From dffa8eca99df31df2e5385b197e34000ec14886e Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Thu, 27 Dec 2018 15:32:59 +1100 Subject: [PATCH] Periodic pairsLastUpdated timestamp update Fix other GoReportCard warnings --- config/config.go | 7 + config_example.json | 8 +- exchanges/anx/anx_types.go | 2 +- exchanges/btcmarkets/btcmarkets_wrapper.go | 4 +- exchanges/exchange.go | 2 +- exchanges/exchange_websocket_test.go | 164 ++++++++++----------- exchanges/huobi/huobi_test.go | 3 + exchanges/huobi/huobi_wrapper.go | 4 + exchanges/huobihadax/huobihadax_test.go | 4 + exchanges/huobihadax/huobihadax_wrapper.go | 4 + exchanges/okex/okex.go | 2 +- testdata/configtest.json | 8 +- 12 files changed, 118 insertions(+), 94 deletions(-) diff --git a/config/config.go b/config/config.go index e8b4e4b8..37b167bd 100644 --- a/config/config.go +++ b/config/config.go @@ -1015,10 +1015,15 @@ func GetFilePath(file string) (string, error) { } data, err := common.ReadFile(newDirs[x]) + if err != nil { + return "", err + } + if ConfirmECS(data) { if path.Ext(newDirs[x]) == ".dat" { return newDirs[x], nil } + err = os.Rename(newDirs[x], newDirs[1]) if err != nil { return "", err @@ -1029,10 +1034,12 @@ func GetFilePath(file string) (string, error) { if path.Ext(newDirs[x]) == ".json" { return newDirs[x], nil } + err = os.Rename(newDirs[x], newDirs[0]) if err != nil { return "", err } + return newDirs[0], nil } diff --git a/config_example.json b/config_example.json index 104317cf..c058dff2 100644 --- a/config_example.json +++ b/config_example.json @@ -265,7 +265,7 @@ "baseCurrencies": "JPY", "assetTypes": "SPOT", "supportsAutoPairUpdates": false, - "pairsLastUpdated": 1543208659, + "pairsLastUpdated": 1545884823, "configCurrencyPairFormat": { "uppercase": true, "delimiter": "_" @@ -873,7 +873,7 @@ "baseCurrencies": "USD,SGD", "assetTypes": "SPOT", "supportsAutoPairUpdates": false, - "pairsLastUpdated": 1543208659, + "pairsLastUpdated": 1545884823, "configCurrencyPairFormat": { "uppercase": true }, @@ -1074,7 +1074,7 @@ "baseCurrencies": "CNY", "assetTypes": "SPOT", "supportsAutoPairUpdates": false, - "pairsLastUpdated": 1543207521, + "pairsLastUpdated": 1545884823, "configCurrencyPairFormat": { "uppercase": true }, @@ -1280,7 +1280,7 @@ "baseCurrencies": "USD,RUR", "assetTypes": "SPOT", "supportsAutoPairUpdates": false, - "pairsLastUpdated": 1543208659, + "pairsLastUpdated": 1545884823, "configCurrencyPairFormat": { "uppercase": true, "delimiter": "_" diff --git a/exchanges/anx/anx_types.go b/exchanges/anx/anx_types.go index 76d087e3..49b1d498 100644 --- a/exchanges/anx/anx_types.go +++ b/exchanges/anx/anx_types.go @@ -143,7 +143,7 @@ type OrderCancelResponse struct { ErrorCode int64 `json:"errorCode"` } -// OrderCancellationResponse contians the orderID and error when cancelling multiple orders +// OrderCancellationResponse contains the orderID and error when cancelling multiple orders type OrderCancellationResponse struct { UUID string `json:"uuid"` Error string `json:"errorCode"` diff --git a/exchanges/btcmarkets/btcmarkets_wrapper.go b/exchanges/btcmarkets/btcmarkets_wrapper.go index b4db650e..c7fc7bab 100644 --- a/exchanges/btcmarkets/btcmarkets_wrapper.go +++ b/exchanges/btcmarkets/btcmarkets_wrapper.go @@ -179,9 +179,11 @@ func (b *BTCMarkets) ModifyOrder(action exchange.ModifyOrder) (string, error) { // CancelOrder cancels an order by its corresponding ID number func (b *BTCMarkets) CancelOrder(order exchange.OrderCancellation) error { orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64) + if err != nil { + return err + } _, err = b.CancelExistingOrder([]int64{orderIDInt}) - return err } diff --git a/exchanges/exchange.go b/exchanges/exchange.go index aa028e53..069aa737 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -407,7 +407,7 @@ func (e *Base) SetAssetTypes() error { return err } - var update = false + var update bool if exch.AssetTypes == "" { exch.AssetTypes = common.JoinStrings(e.AssetTypes, ",") update = true diff --git a/exchanges/exchange_websocket_test.go b/exchanges/exchange_websocket_test.go index 26e21d90..d6705ea4 100644 --- a/exchanges/exchange_websocket_test.go +++ b/exchanges/exchange_websocket_test.go @@ -127,31 +127,31 @@ func TestWebsocket(t *testing.T) { func TestInsertingSnapShots(t *testing.T) { var snapShot1 orderbook.Base asks := []orderbook.Item{ - orderbook.Item{Price: 6000, Amount: 1, ID: 1}, - orderbook.Item{Price: 6001, Amount: 0.5, ID: 2}, - orderbook.Item{Price: 6002, Amount: 2, ID: 3}, - orderbook.Item{Price: 6003, Amount: 3, ID: 4}, - orderbook.Item{Price: 6004, Amount: 5, ID: 5}, - orderbook.Item{Price: 6005, Amount: 2, ID: 6}, - orderbook.Item{Price: 6006, Amount: 1.5, ID: 7}, - orderbook.Item{Price: 6007, Amount: 0.5, ID: 8}, - orderbook.Item{Price: 6008, Amount: 23, ID: 9}, - orderbook.Item{Price: 6009, Amount: 9, ID: 10}, - orderbook.Item{Price: 6010, Amount: 7, ID: 11}, + {Price: 6000, Amount: 1, ID: 1}, + {Price: 6001, Amount: 0.5, ID: 2}, + {Price: 6002, Amount: 2, ID: 3}, + {Price: 6003, Amount: 3, ID: 4}, + {Price: 6004, Amount: 5, ID: 5}, + {Price: 6005, Amount: 2, ID: 6}, + {Price: 6006, Amount: 1.5, ID: 7}, + {Price: 6007, Amount: 0.5, ID: 8}, + {Price: 6008, Amount: 23, ID: 9}, + {Price: 6009, Amount: 9, ID: 10}, + {Price: 6010, Amount: 7, ID: 11}, } bids := []orderbook.Item{ - orderbook.Item{Price: 5999, Amount: 1, ID: 12}, - orderbook.Item{Price: 5998, Amount: 0.5, ID: 13}, - orderbook.Item{Price: 5997, Amount: 2, ID: 14}, - orderbook.Item{Price: 5996, Amount: 3, ID: 15}, - orderbook.Item{Price: 5995, Amount: 5, ID: 16}, - orderbook.Item{Price: 5994, Amount: 2, ID: 17}, - orderbook.Item{Price: 5993, Amount: 1.5, ID: 18}, - orderbook.Item{Price: 5992, Amount: 0.5, ID: 19}, - orderbook.Item{Price: 5991, Amount: 23, ID: 20}, - orderbook.Item{Price: 5990, Amount: 9, ID: 21}, - orderbook.Item{Price: 5989, Amount: 7, ID: 22}, + {Price: 5999, Amount: 1, ID: 12}, + {Price: 5998, Amount: 0.5, ID: 13}, + {Price: 5997, Amount: 2, ID: 14}, + {Price: 5996, Amount: 3, ID: 15}, + {Price: 5995, Amount: 5, ID: 16}, + {Price: 5994, Amount: 2, ID: 17}, + {Price: 5993, Amount: 1.5, ID: 18}, + {Price: 5992, Amount: 0.5, ID: 19}, + {Price: 5991, Amount: 23, ID: 20}, + {Price: 5990, Amount: 9, ID: 21}, + {Price: 5989, Amount: 7, ID: 22}, } snapShot1.Asks = asks @@ -165,31 +165,31 @@ func TestInsertingSnapShots(t *testing.T) { var snapShot2 orderbook.Base asks = []orderbook.Item{ - orderbook.Item{Price: 51, Amount: 1, ID: 1}, - orderbook.Item{Price: 52, Amount: 0.5, ID: 2}, - orderbook.Item{Price: 53, Amount: 2, ID: 3}, - orderbook.Item{Price: 54, Amount: 3, ID: 4}, - orderbook.Item{Price: 55, Amount: 5, ID: 5}, - orderbook.Item{Price: 56, Amount: 2, ID: 6}, - orderbook.Item{Price: 57, Amount: 1.5, ID: 7}, - orderbook.Item{Price: 58, Amount: 0.5, ID: 8}, - orderbook.Item{Price: 59, Amount: 23, ID: 9}, - orderbook.Item{Price: 50, Amount: 9, ID: 10}, - orderbook.Item{Price: 60, Amount: 7, ID: 11}, + {Price: 51, Amount: 1, ID: 1}, + {Price: 52, Amount: 0.5, ID: 2}, + {Price: 53, Amount: 2, ID: 3}, + {Price: 54, Amount: 3, ID: 4}, + {Price: 55, Amount: 5, ID: 5}, + {Price: 56, Amount: 2, ID: 6}, + {Price: 57, Amount: 1.5, ID: 7}, + {Price: 58, Amount: 0.5, ID: 8}, + {Price: 59, Amount: 23, ID: 9}, + {Price: 50, Amount: 9, ID: 10}, + {Price: 60, Amount: 7, ID: 11}, } bids = []orderbook.Item{ - orderbook.Item{Price: 49, Amount: 1, ID: 12}, - orderbook.Item{Price: 48, Amount: 0.5, ID: 13}, - orderbook.Item{Price: 47, Amount: 2, ID: 14}, - orderbook.Item{Price: 46, Amount: 3, ID: 15}, - orderbook.Item{Price: 45, Amount: 5, ID: 16}, - orderbook.Item{Price: 44, Amount: 2, ID: 17}, - orderbook.Item{Price: 43, Amount: 1.5, ID: 18}, - orderbook.Item{Price: 42, Amount: 0.5, ID: 19}, - orderbook.Item{Price: 41, Amount: 23, ID: 20}, - orderbook.Item{Price: 40, Amount: 9, ID: 21}, - orderbook.Item{Price: 39, Amount: 7, ID: 22}, + {Price: 49, Amount: 1, ID: 12}, + {Price: 48, Amount: 0.5, ID: 13}, + {Price: 47, Amount: 2, ID: 14}, + {Price: 46, Amount: 3, ID: 15}, + {Price: 45, Amount: 5, ID: 16}, + {Price: 44, Amount: 2, ID: 17}, + {Price: 43, Amount: 1.5, ID: 18}, + {Price: 42, Amount: 0.5, ID: 19}, + {Price: 41, Amount: 23, ID: 20}, + {Price: 40, Amount: 9, ID: 21}, + {Price: 39, Amount: 7, ID: 22}, } snapShot2.Asks = asks @@ -203,31 +203,31 @@ func TestInsertingSnapShots(t *testing.T) { var snapShot3 orderbook.Base asks = []orderbook.Item{ - orderbook.Item{Price: 51, Amount: 1, ID: 1}, - orderbook.Item{Price: 52, Amount: 0.5, ID: 2}, - orderbook.Item{Price: 53, Amount: 2, ID: 3}, - orderbook.Item{Price: 54, Amount: 3, ID: 4}, - orderbook.Item{Price: 55, Amount: 5, ID: 5}, - orderbook.Item{Price: 56, Amount: 2, ID: 6}, - orderbook.Item{Price: 57, Amount: 1.5, ID: 7}, - orderbook.Item{Price: 58, Amount: 0.5, ID: 8}, - orderbook.Item{Price: 59, Amount: 23, ID: 9}, - orderbook.Item{Price: 50, Amount: 9, ID: 10}, - orderbook.Item{Price: 60, Amount: 7, ID: 11}, + {Price: 51, Amount: 1, ID: 1}, + {Price: 52, Amount: 0.5, ID: 2}, + {Price: 53, Amount: 2, ID: 3}, + {Price: 54, Amount: 3, ID: 4}, + {Price: 55, Amount: 5, ID: 5}, + {Price: 56, Amount: 2, ID: 6}, + {Price: 57, Amount: 1.5, ID: 7}, + {Price: 58, Amount: 0.5, ID: 8}, + {Price: 59, Amount: 23, ID: 9}, + {Price: 50, Amount: 9, ID: 10}, + {Price: 60, Amount: 7, ID: 11}, } bids = []orderbook.Item{ - orderbook.Item{Price: 49, Amount: 1, ID: 12}, - orderbook.Item{Price: 48, Amount: 0.5, ID: 13}, - orderbook.Item{Price: 47, Amount: 2, ID: 14}, - orderbook.Item{Price: 46, Amount: 3, ID: 15}, - orderbook.Item{Price: 45, Amount: 5, ID: 16}, - orderbook.Item{Price: 44, Amount: 2, ID: 17}, - orderbook.Item{Price: 43, Amount: 1.5, ID: 18}, - orderbook.Item{Price: 42, Amount: 0.5, ID: 19}, - orderbook.Item{Price: 41, Amount: 23, ID: 20}, - orderbook.Item{Price: 40, Amount: 9, ID: 21}, - orderbook.Item{Price: 39, Amount: 7, ID: 22}, + {Price: 49, Amount: 1, ID: 12}, + {Price: 48, Amount: 0.5, ID: 13}, + {Price: 47, Amount: 2, ID: 14}, + {Price: 46, Amount: 3, ID: 15}, + {Price: 45, Amount: 5, ID: 16}, + {Price: 44, Amount: 2, ID: 17}, + {Price: 43, Amount: 1.5, ID: 18}, + {Price: 42, Amount: 0.5, ID: 19}, + {Price: 41, Amount: 23, ID: 20}, + {Price: 40, Amount: 9, ID: 21}, + {Price: 39, Amount: 7, ID: 22}, } snapShot3.Asks = asks @@ -249,17 +249,17 @@ func TestUpdate(t *testing.T) { BTCUSDPAIR := pair.NewCurrencyPairFromString("BTCUSD") bidTargets := []orderbook.Item{ - orderbook.Item{Price: 49, Amount: 24}, // Amend - orderbook.Item{Price: 48, Amount: 0}, // Delete - orderbook.Item{Price: 1337, Amount: 100}, // Append - orderbook.Item{Price: 1336, Amount: 0}, // Ghost delete + {Price: 49, Amount: 24}, // Amend + {Price: 48, Amount: 0}, // Delete + {Price: 1337, Amount: 100}, // Append + {Price: 1336, Amount: 0}, // Ghost delete } askTargets := []orderbook.Item{ - orderbook.Item{Price: 51, Amount: 24}, // Amend - orderbook.Item{Price: 52, Amount: 0}, // Delete - orderbook.Item{Price: 1337, Amount: 100}, // Append - orderbook.Item{Price: 1336, Amount: 0}, // Ghost delete + {Price: 51, Amount: 24}, // Amend + {Price: 52, Amount: 0}, // Delete + {Price: 1337, Amount: 100}, // Append + {Price: 1336, Amount: 0}, // Ghost delete } err := wsTest.Websocket.Orderbook.Update(bidTargets, @@ -285,17 +285,17 @@ func TestUpdate(t *testing.T) { } bidTargets = []orderbook.Item{ - orderbook.Item{Price: 5999, Amount: 24}, // Amend - orderbook.Item{Price: 5998, Amount: 0}, // Delete - orderbook.Item{Price: 1337, Amount: 100}, // Append - orderbook.Item{Price: 1336, Amount: 0}, // Ghost delete + {Price: 5999, Amount: 24}, // Amend + {Price: 5998, Amount: 0}, // Delete + {Price: 1337, Amount: 100}, // Append + {Price: 1336, Amount: 0}, // Ghost delete } askTargets = []orderbook.Item{ - orderbook.Item{Price: 6000, Amount: 24}, // Amend - orderbook.Item{Price: 6001, Amount: 0}, // Delete - orderbook.Item{Price: 1337, Amount: 100}, // Append - orderbook.Item{Price: 1336, Amount: 0}, // Ghost delete + {Price: 6000, Amount: 24}, // Amend + {Price: 6001, Amount: 0}, // Delete + {Price: 1337, Amount: 100}, // Append + {Price: 1336, Amount: 0}, // Ghost delete } err = wsTest.Websocket.Orderbook.Update(bidTargets, diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index 684a3633..179cb62a 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -421,6 +421,9 @@ func TestSubmitOrder(t *testing.T) { SecondCurrency: symbol.USDT, } accounts, err := h.GetAccounts() + if err != nil { + t.Errorf("Failed to get accounts. Err: %s", err) + } response, err := h.SubmitOrder(p, exchange.Buy, exchange.Limit, 1, 10, strconv.FormatInt(accounts[0].ID, 10)) if err != nil || !response.IsOrderPlaced { diff --git a/exchanges/huobi/huobi_wrapper.go b/exchanges/huobi/huobi_wrapper.go index a989f59d..8f8ed65d 100644 --- a/exchanges/huobi/huobi_wrapper.go +++ b/exchanges/huobi/huobi_wrapper.go @@ -240,6 +240,10 @@ func (h *HUOBI) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exc func (h *HUOBI) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) { var submitOrderResponse exchange.SubmitOrderResponse accountID, err := strconv.ParseInt(clientID, 10, 64) + if err != nil { + return submitOrderResponse, err + } + var formattedType SpotNewOrderRequestParamsType var params = SpotNewOrderRequestParams{ Amount: amount, diff --git a/exchanges/huobihadax/huobihadax_test.go b/exchanges/huobihadax/huobihadax_test.go index 1d4ddd6f..91ee5a82 100644 --- a/exchanges/huobihadax/huobihadax_test.go +++ b/exchanges/huobihadax/huobihadax_test.go @@ -399,7 +399,11 @@ func TestSubmitOrder(t *testing.T) { FirstCurrency: symbol.BTC, SecondCurrency: symbol.USDT, } + accounts, err := h.GetAccounts() + if err != nil { + t.Errorf("Failed to get accounts. Err: %s", err) + } response, err := h.SubmitOrder(p, exchange.Buy, exchange.Limit, 1, 10, strconv.FormatInt(accounts[0].ID, 10)) if err != nil || !response.IsOrderPlaced { diff --git a/exchanges/huobihadax/huobihadax_wrapper.go b/exchanges/huobihadax/huobihadax_wrapper.go index 9a16faef..94ecfc58 100644 --- a/exchanges/huobihadax/huobihadax_wrapper.go +++ b/exchanges/huobihadax/huobihadax_wrapper.go @@ -205,6 +205,10 @@ func (h *HUOBIHADAX) GetExchangeHistory(p pair.CurrencyPair, assetType string) ( func (h *HUOBIHADAX) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) { var submitOrderResponse exchange.SubmitOrderResponse accountID, err := strconv.ParseInt(clientID, 0, 64) + if err != nil { + return submitOrderResponse, err + } + var formattedType SpotNewOrderRequestParamsType var params = SpotNewOrderRequestParams{ Amount: amount, diff --git a/exchanges/okex/okex.go b/exchanges/okex/okex.go index ce7c3760..96cc904e 100644 --- a/exchanges/okex/okex.go +++ b/exchanges/okex/okex.go @@ -1190,7 +1190,7 @@ func getWithdrawalFee(currency string) float64 { return WithdrawalFees[currency] } -// GetBalance returns the full balance accross all wallets +// GetBalance returns the full balance across all wallets func (o *OKEX) GetBalance() ([]FullBalance, error) { var resp Balance var balances []FullBalance diff --git a/testdata/configtest.json b/testdata/configtest.json index bf321527..72965ec1 100644 --- a/testdata/configtest.json +++ b/testdata/configtest.json @@ -274,7 +274,7 @@ "baseCurrencies": "JPY", "assetTypes": "SPOT", "supportsAutoPairUpdates": false, - "pairsLastUpdated": 1543208659, + "pairsLastUpdated": 1545884823, "configCurrencyPairFormat": { "uppercase": true, "delimiter": "_" @@ -885,7 +885,7 @@ "baseCurrencies": "USD,SGD", "assetTypes": "SPOT", "supportsAutoPairUpdates": false, - "pairsLastUpdated": 1543208659, + "pairsLastUpdated": 1545884823, "configCurrencyPairFormat": { "uppercase": true }, @@ -1086,7 +1086,7 @@ "baseCurrencies": "CNY", "assetTypes": "SPOT", "supportsAutoPairUpdates": false, - "pairsLastUpdated": 1543207521, + "pairsLastUpdated": 1545884823, "configCurrencyPairFormat": { "uppercase": true }, @@ -1250,7 +1250,7 @@ "baseCurrencies": "USD", "assetTypes": "SPOT", "supportsAutoPairUpdates": false, - "pairsLastUpdated": 1543207521, + "pairsLastUpdated": 1545884823, "configCurrencyPairFormat": { "uppercase": true, "delimiter": "_"