diff --git a/exchanges/binance/binance_websocket.go b/exchanges/binance/binance_websocket.go index 4a31aacf..c73b7782 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/bitmex/bitmex_websocket.go b/exchanges/bitmex/bitmex_websocket.go index 7e4938f5..5a6498ef 100644 --- a/exchanges/bitmex/bitmex_websocket.go +++ b/exchanges/bitmex/bitmex_websocket.go @@ -379,7 +379,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), diff --git a/exchanges/huobi/huobi.go b/exchanges/huobi/huobi.go index bbac3f90..0a17cdb5 100644 --- a/exchanges/huobi/huobi.go +++ b/exchanges/huobi/huobi.go @@ -39,6 +39,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" @@ -310,6 +311,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 79f28728..d83134d7 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -211,6 +211,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"` diff --git a/exchanges/huobihadax/huobihadax.go b/exchanges/huobihadax/huobihadax.go index 835b0070..2155dea4 100644 --- a/exchanges/huobihadax/huobihadax.go +++ b/exchanges/huobihadax/huobihadax.go @@ -35,6 +35,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" @@ -303,6 +304,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 ae3294d4..d273aa4e 100644 --- a/exchanges/huobihadax/huobihadax_test.go +++ b/exchanges/huobihadax/huobihadax_test.go @@ -256,6 +256,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"` diff --git a/exchanges/okgroup/okgroup_websocket.go b/exchanges/okgroup/okgroup_websocket.go index 79efb391..a3424d74 100644 --- a/exchanges/okgroup/okgroup_websocket.go +++ b/exchanges/okgroup/okgroup_websocket.go @@ -456,7 +456,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(),