Bittrex: Update API v1.1 to v3 and add websocket support (#646)

* Update Bittrex API from v1.1 to v3

V1.1 has been retired as of 9/30/2020

- Update REST to V3
- Add initial websocket support

* Bittrex update - enable websockets in testdata config file

* Update Bittrex - add Websocket capability to docs

* Update Bittrex connector

- AppVeyor warnings
- Update tests
- Generate documentation
- Fix nits

* Update Bittrex - add websocket order processing

* Update Bittrex connector

* Bittrex connector - fix ineffectual err assignment

* Fix nits

* Orderbook synchronization

* Remove redundant nil

* Log WS fetch orderbook message as debug message instead of as warning

* Update after rebase

* Add tests

* Add allowed candle interval values

* Replace literals with declared constants

* Replace variable name 'request' with 'req'

* Add check and update for deprecated REST URL

* Nits and some cleaning up

* Change ParseInt bit size to 64

* [FIX] Remove several shadow declarations

* Do not export constructTicker

* Remove parseTime()

* Update GetHistoricCandles()

* [FIX] Address gocritic nits

* [FIX] Address gocritic nits

* Use SendMessageReturnResponse() instead of local map

* Rate limit subscribing and unsubscribing

* [FIX] use go routine for subscribing and unsubscribing

* [FIX] Set correct index for map

* [FIX] Address unused vars, literals, time format

* Adjusted timing when subscribing to many order books

* Cache partial updates to tickers instead of calling REST function

* [FIX] Update sequence nr when multiple updates are queued

* Address golint issues

* Fix nits
This commit is contained in:
TaltaM
2021-05-18 03:33:53 +02:00
committed by GitHub
parent 9b5619e40c
commit 7e9266e438
14 changed files with 2413 additions and 959 deletions

View File

@@ -21,7 +21,7 @@ const (
apiKey = ""
apiSecret = ""
canManipulateRealOrders = false
currPair = "USDT-BTC"
currPair = "BTC-USDT"
curr = "BTC"
)
@@ -98,7 +98,7 @@ func TestGetMarketSummary(t *testing.T) {
func TestGetOrderbook(t *testing.T) {
t.Parallel()
_, err := b.GetOrderbook(currPair)
_, _, err := b.GetOrderbook(currPair, 500)
if err != nil {
t.Error(err)
}
@@ -113,20 +113,35 @@ func TestGetMarketHistory(t *testing.T) {
}
}
func TestPlaceBuyLimit(t *testing.T) {
func TestGetRecentCandles(t *testing.T) {
t.Parallel()
_, err := b.PlaceBuyLimit(currPair, 1, 1)
if err == nil {
t.Error("Expected error")
_, err := b.GetRecentCandles(currPair, "HOUR_1", "MIDPOINT")
if err != nil {
t.Error(err)
}
}
func TestPlaceSellLimit(t *testing.T) {
func TestGetHistoricalCandles(t *testing.T) {
t.Parallel()
_, err := b.PlaceSellLimit(currPair, 1, 1)
_, err := b.GetHistoricalCandles(currPair, "MINUTE_5", "MIDPOINT", 2020, 12, 31)
if err != nil {
t.Error(err)
}
_, err = b.GetHistoricalCandles(currPair, "MINUTE_5", "MIDPOINT", 2020, 12, 32)
if err == nil {
t.Error("invalid date should give an error")
}
}
func TestOrder(t *testing.T) {
t.Parallel()
_, err := b.Order(currPair, order.Buy.String(), order.Limit.String(), "", 1, 1, 0.0)
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
}
@@ -134,13 +149,13 @@ func TestPlaceSellLimit(t *testing.T) {
func TestGetOpenOrders(t *testing.T) {
t.Parallel()
_, err := b.GetOpenOrders("")
_, _, err := b.GetOpenOrders("")
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
_, err = b.GetOpenOrders(currPair)
_, _, err = b.GetOpenOrders(currPair)
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
@@ -160,7 +175,7 @@ func TestCancelExistingOrder(t *testing.T) {
func TestGetAccountBalances(t *testing.T) {
t.Parallel()
_, err := b.GetAccountBalances()
_, err := b.GetBalances()
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
@@ -213,16 +228,10 @@ func TestGetOrderHistoryForCurrency(t *testing.T) {
}
}
func TestGetwithdrawalHistory(t *testing.T) {
func TestGetClosedWithdrawals(t *testing.T) {
t.Parallel()
_, err := b.GetWithdrawalHistory("")
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
_, err = b.GetWithdrawalHistory(curr)
_, err := b.GetClosedWithdrawals()
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
@@ -230,20 +239,94 @@ func TestGetwithdrawalHistory(t *testing.T) {
}
}
func TestGetDepositHistory(t *testing.T) {
func TestGetClosedWithdrawalsForCurrency(t *testing.T) {
t.Parallel()
_, err := b.GetDepositHistory("")
_, err := b.GetClosedWithdrawalsForCurrency(curr)
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
_, err = b.GetDepositHistory(currPair)
if err == nil {
}
func TestGetOpenWithdrawals(t *testing.T) {
t.Parallel()
_, err := b.GetOpenWithdrawals()
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
}
func TestGetClosedDeposits(t *testing.T) {
t.Parallel()
_, err := b.GetClosedDeposits()
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
}
func TestGetClosedDepositsForCurrency(t *testing.T) {
t.Parallel()
_, err := b.GetClosedDepositsForCurrency(curr)
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
}
func TestGetClosedDepositsPaginated(t *testing.T) {
t.Parallel()
_, err := b.GetClosedDepositsPaginated(100)
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
}
func TestGetOpenDeposits(t *testing.T) {
t.Parallel()
_, err := b.GetOpenDeposits()
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
}
func TestGetOpenDepositsForCurrency(t *testing.T) {
t.Parallel()
_, err := b.GetOpenDepositsForCurrency(curr)
if areTestAPIKeysSet() && err != nil {
t.Error(err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expected error")
}
}
func TestWithdraw(t *testing.T) {
t.Parallel()
if !areTestAPIKeysSet() || !canManipulateRealOrders {
t.Skip("skipping test, either api keys or canManipulateRealOrders isnt set correctly")
}
_, err := b.Withdraw(curr, "", core.BitcoinDonationAddress, 0.0009)
if err != nil {
t.Error(err)
}
}
func setFeeBuilder() *exchange.FeeBuilder {
return &exchange.FeeBuilder{
Amount: 1,
@@ -356,7 +439,7 @@ func TestGetActiveOrders(t *testing.T) {
AssetType: asset.Spot,
}
getOrdersRequest.Pairs[0].Delimiter = "-"
getOrdersRequest.Pairs[0].Delimiter = currency.DashDelimiter
_, err = b.GetActiveOrders(&getOrdersRequest)
if areTestAPIKeysSet() && err != nil {
@@ -373,6 +456,15 @@ func TestGetOrderHistory(t *testing.T) {
}
_, err := b.GetOrderHistory(&getOrdersRequest)
if err == nil {
t.Error("Expected: 'At least one currency is required to fetch order history'. received nil")
}
getOrdersRequest.Pairs = []currency.Pair{
currency.NewPair(currency.BTC, currency.USDT),
}
_, err = b.GetOrderHistory(&getOrdersRequest)
if areTestAPIKeysSet() && err != nil {
t.Errorf("Could not get order history: %s", err)
} else if !areTestAPIKeysSet() && err == nil {
@@ -393,7 +485,7 @@ func TestSubmitOrder(t *testing.T) {
var orderSubmission = &order.Submit{
Pair: currency.Pair{
Delimiter: "-",
Delimiter: currency.DashDelimiter,
Base: currency.BTC,
Quote: currency.LTC,
},
@@ -473,7 +565,7 @@ func TestModifyOrder(t *testing.T) {
}
}
func TestWithdraw(t *testing.T) {
func WithdrawCryptocurrencyFunds(t *testing.T) {
withdrawCryptoRequest := withdraw.Request{
Amount: -1,
Currency: currency.BTC,
@@ -536,24 +628,6 @@ func TestGetDepositAddress(t *testing.T) {
}
}
func TestParseTime(t *testing.T) {
t.Parallel()
tm, err := parseTime("2019-11-21T02:08:34.87")
if err != nil {
t.Fatal(err)
}
if tm.Year() != 2019 ||
tm.Month() != 11 ||
tm.Day() != 21 ||
tm.Hour() != 2 ||
tm.Minute() != 8 ||
tm.Second() != 34 {
t.Error("invalid time values")
}
}
func TestGetRecentTrades(t *testing.T) {
t.Parallel()
currencyPair, err := currency.NewPairFromString(currPair)