From 4222b327c659167e23fb0212c5a59c7f3abe4334 Mon Sep 17 00:00:00 2001 From: DirectX Date: Mon, 15 Jul 2019 06:36:18 +0300 Subject: [PATCH 1/4] Fixes to OKEX and Binance WS trades data mapping (#326) * Fixes to OKEX and Binance WS trades data mapping * Small improvement using semantic time.Milliscond unit * gofmt -s file --- exchanges/binance/binance_websocket.go | 2 +- exchanges/okgroup/okgroup_websocket.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exchanges/binance/binance_websocket.go b/exchanges/binance/binance_websocket.go index b96fd35f..fff453e4 100644 --- a/exchanges/binance/binance_websocket.go +++ b/exchanges/binance/binance_websocket.go @@ -250,7 +250,7 @@ func (b *Binance) WsHandleData() { b.Websocket.DataHandler <- exchange.TradeData{ CurrencyPair: currency.NewPairFromString(trade.Symbol), - Timestamp: time.Unix(0, trade.TimeStamp), + Timestamp: time.Unix(0, trade.TimeStamp*int64(time.Millisecond)), Price: price, Amount: amount, Exchange: b.GetName(), diff --git a/exchanges/okgroup/okgroup_websocket.go b/exchanges/okgroup/okgroup_websocket.go index 66f7fd12..87c19489 100644 --- a/exchanges/okgroup/okgroup_websocket.go +++ b/exchanges/okgroup/okgroup_websocket.go @@ -452,7 +452,7 @@ func (o *OKGroup) wsProcessTrades(response *WebsocketDataResponse) { for i := range response.Data { instrument := currency.NewPairDelimiter(response.Data[i].InstrumentID, "-") o.Websocket.DataHandler <- exchange.TradeData{ - Amount: response.Data[i].Qty, + Amount: response.Data[i].Size, AssetType: o.GetAssetTypeFromTableName(response.Table), CurrencyPair: instrument, EventTime: time.Now().Unix(), From e0aea96a5ce6e503c9b4a3bab62e17ae3f040c28 Mon Sep 17 00:00:00 2001 From: Yunseok Date: Thu, 18 Jul 2019 12:10:30 +0900 Subject: [PATCH 2/4] Add Huobi GetAggregatedBalance api (#329) Add Huobi GetAggregatedBalance api that returns the balances of all the sub-account aggregated. See also - https://huobiapi.github.io/docs/spot/v1/en/#get-the-aggregated-balance-of-all-sub-accounts-of-the-current-user --- exchanges/huobi/huobi.go | 24 ++++++++++++++++++++++++ exchanges/huobi/huobi_test.go | 13 +++++++++++++ exchanges/huobi/huobi_types.go | 6 ++++++ 3 files changed, 43 insertions(+) diff --git a/exchanges/huobi/huobi.go b/exchanges/huobi/huobi.go index 27a893a3..483f284f 100644 --- a/exchanges/huobi/huobi.go +++ b/exchanges/huobi/huobi.go @@ -42,6 +42,7 @@ const ( huobiTimestamp = "common/timestamp" huobiAccounts = "account/accounts" huobiAccountBalance = "account/accounts/%s/balance" + huobiAggregatedBalance = "subuser/aggregate-balance" huobiOrderPlace = "order/orders/place" huobiOrderCancel = "order/orders/%s/submitcancel" huobiOrderCancelBatch = "order/orders/batchcancel" @@ -399,6 +400,29 @@ func (h *HUOBI) GetAccountBalance(accountID string) ([]AccountBalanceDetail, err return result.AccountBalanceData.AccountBalanceDetails, err } +// GetAggregatedBalance returns the balances of all the sub-account aggregated. +func (h *HUOBI) GetAggregatedBalance() ([]AggregatedBalance, error) { + type response struct { + Response + AggregatedBalances []AggregatedBalance `json:"data"` + } + + var result response + + err := h.SendAuthenticatedHTTPRequest( + http.MethodGet, + huobiAggregatedBalance, + nil, + nil, + &result, + ) + + if result.ErrorMessage != "" { + return nil, errors.New(result.ErrorMessage) + } + return result.AggregatedBalances, err +} + // SpotNewOrder submits an order to Huobi func (h *HUOBI) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error) { data := struct { diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index 422fad7e..fea3413f 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -210,6 +210,19 @@ func TestGetAccountBalance(t *testing.T) { } } +func TestGetAggregatedBalance(t *testing.T) { + t.Parallel() + + if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" { + t.Skip() + } + + _, err := h.GetAggregatedBalance() + if err != nil { + t.Errorf("Test failed - Huobi GetAggregatedBalance: %s", err) + } +} + func TestSpotNewOrder(t *testing.T) { t.Parallel() diff --git a/exchanges/huobi/huobi_types.go b/exchanges/huobi/huobi_types.go index 958a09ad..feb83195 100644 --- a/exchanges/huobi/huobi_types.go +++ b/exchanges/huobi/huobi_types.go @@ -131,6 +131,12 @@ type AccountBalanceDetail struct { Balance float64 `json:"balance,string"` } +// AggregatedBalance stores balances of all the sub-account +type AggregatedBalance struct { + Currency string `json:"currency"` + Balance float64 `json:"balance,string"` +} + // CancelOrderBatch stores the cancel order batch data type CancelOrderBatch struct { Success []string `json:"success"` From eb07c7e4952cbe35a5bc9880d4e3e79d2ef198e5 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 19 Jul 2019 17:00:54 +1000 Subject: [PATCH 3/4] Implements endpoint GetAggregatedBalance for Hadax too. (#330) --- exchanges/huobihadax/huobihadax.go | 23 +++++++++++++++++++++++ exchanges/huobihadax/huobihadax_test.go | 12 ++++++++++++ exchanges/huobihadax/huobihadax_types.go | 6 ++++++ 3 files changed, 41 insertions(+) diff --git a/exchanges/huobihadax/huobihadax.go b/exchanges/huobihadax/huobihadax.go index 1160edde..35d8d0a8 100644 --- a/exchanges/huobihadax/huobihadax.go +++ b/exchanges/huobihadax/huobihadax.go @@ -36,6 +36,7 @@ const ( huobihadaxCurrencies = "common/currencys" huobihadaxTimestamp = "common/timestamp" huobihadaxAccounts = "account/accounts" + huobihadaxAggregatedBalance = "subuser/aggregate-balance" huobihadaxAccountBalance = "account/accounts/%s/balance" huobihadaxOrderPlace = "order/orders/place" huobihadaxOrderCancel = "order/orders/%s/submitcancel" @@ -389,6 +390,28 @@ func (h *HUOBIHADAX) GetAccountBalance(accountID string) ([]AccountBalanceDetail return result.AccountBalanceData.AccountBalanceDetails, err } +// GetAggregatedBalance returns the balances of all the sub-account aggregated. +func (h *HUOBIHADAX) GetAggregatedBalance() ([]AggregatedBalance, error) { + type response struct { + Response + AggregatedBalances []AggregatedBalance `json:"data"` + } + + var result response + + err := h.SendAuthenticatedHTTPRequest( + http.MethodGet, + huobihadaxAggregatedBalance, + url.Values{}, + &result, + ) + + if result.ErrorMessage != "" { + return nil, errors.New(result.ErrorMessage) + } + return result.AggregatedBalances, err +} + // SpotNewOrder submits an order to Huobi func (h *HUOBIHADAX) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error) { vals := make(map[string]string) diff --git a/exchanges/huobihadax/huobihadax_test.go b/exchanges/huobihadax/huobihadax_test.go index 0647d55c..c6d16bb8 100644 --- a/exchanges/huobihadax/huobihadax_test.go +++ b/exchanges/huobihadax/huobihadax_test.go @@ -202,6 +202,18 @@ func TestGetAccountBalance(t *testing.T) { } } +func TestGetAggregatedBalance(t *testing.T) { + t.Parallel() + if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" { + t.Skip() + } + + _, err := h.GetAggregatedBalance() + if err != nil { + t.Errorf("Test failed - Huobi GetAggregatedBalance: %s", err) + } +} + func TestSpotNewOrder(t *testing.T) { t.Parallel() diff --git a/exchanges/huobihadax/huobihadax_types.go b/exchanges/huobihadax/huobihadax_types.go index 20ee992b..787c9b14 100644 --- a/exchanges/huobihadax/huobihadax_types.go +++ b/exchanges/huobihadax/huobihadax_types.go @@ -113,6 +113,12 @@ type AccountBalanceDetail struct { Balance float64 `json:"balance,string"` } +// AggregatedBalance stores balances of all the sub-account +type AggregatedBalance struct { + Currency string `json:"currency"` + Balance float64 `json:"balance,string"` +} + // CancelOrderBatch stores the cancel order batch data type CancelOrderBatch struct { Success []string `json:"success"` From 3f7105088119829043a09532af17d35bcfc87a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rensen?= <1040765+mortensorensen@users.noreply.github.com> Date: Wed, 31 Jul 2019 13:58:20 +0800 Subject: [PATCH 4/4] Bitmex compare initial orderbook snapsnot insensitive (#331) --- exchanges/bitmex/bitmex_websocket.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exchanges/bitmex/bitmex_websocket.go b/exchanges/bitmex/bitmex_websocket.go index 56f9a494..1e9040e2 100644 --- a/exchanges/bitmex/bitmex_websocket.go +++ b/exchanges/bitmex/bitmex_websocket.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" "strconv" + "strings" "time" "github.com/gorilla/websocket" @@ -376,7 +377,7 @@ func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPai var bids, asks []orderbook.Item for _, orderbookItem := range data { - if orderbookItem.Side == exchange.SellOrderSide.ToString() { + if strings.EqualFold(orderbookItem.Side, exchange.SellOrderSide.ToString()) { asks = append(asks, orderbook.Item{ Price: orderbookItem.Price, Amount: float64(orderbookItem.Size),