Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huobi: V2 subscription support #1703

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
344 changes: 173 additions & 171 deletions exchanges/huobi/cfutures_types.go

Large diffs are not rendered by default.

222 changes: 112 additions & 110 deletions exchanges/huobi/futures_types.go

Large diffs are not rendered by default.

2,411 changes: 733 additions & 1,678 deletions exchanges/huobi/huobi_test.go

Large diffs are not rendered by default.

628 changes: 260 additions & 368 deletions exchanges/huobi/huobi_types.go

Large diffs are not rendered by default.

1,085 changes: 489 additions & 596 deletions exchanges/huobi/huobi_websocket.go

Large diffs are not rendered by default.

259 changes: 91 additions & 168 deletions exchanges/huobi/huobi_wrapper.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions exchanges/huobi/testdata/wsAllTrades.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ch":"market.btcusdt.trade.detail","ts":1630994963175,"tick":{"id":137005445109,"ts":1630994963173,"data":[{"id":137005445109359290000000000,"ts":1630994963173,"tradeId":102523573486,"amount":0.006754,"price":52648.62,"direction":"buy"}]}}
1 change: 1 addition & 0 deletions exchanges/huobi/testdata/wsCandles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ch":"market.btcusdt.kline.1min","ts":1489474082831,"tick":{"id":1489464480,"amount":1821.49,"count":4,"open":7962.62,"close":8014.56,"low":5110.14,"high":14962.77,"vol":4.4}}
3 changes: 3 additions & 0 deletions exchanges/huobi/testdata/wsMyAccount.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"action":"push","ch":"accounts.update#2","data":{"currency":"btc","accountId":123456,"balance":"23.111","changeType":"transfer","accountType":"trade","seqNum":1,"changeTime":1568601800000}}
{"action":"push","ch":"accounts.update#2","data":{"currency":"btc","accountId":33385,"available":"2028.69","changeType":"order.match","accountType":"trade","seqNum":2,"changeTime":1574393385167}}
{"action":"push","ch":"accounts.update#2","data":{"currency":"usdt","accountId":14884859,"balance":"20.29388158","available":"20.29388158","changeType":null,"accountType":"trade","changeTime":null,"seqNum":3}}
4 changes: 4 additions & 0 deletions exchanges/huobi/testdata/wsMyOrders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"action":"push","ch":"orders#*","data":{"orderSide":"buy","lastActTime":1583853365586,"clientOrderId":"test1","orderStatus":"rejected","symbol":"btcusdt","eventType":"trigger","errCode":2002,"errMessage":"invalid.client.order.id (NT)"}}
{"action":"push","ch":"orders#*","data":{"orderSide":"buy","lastActTime":1583853365586,"clientOrderId":"test2","orderStatus":"canceled","symbol":"btcusdt","eventType":"deletion"}}
{"action":"push","ch":"orders#*","data":{"orderSize":"2.000000000000000000","orderCreateTime":1583853365586,"accountld":992701,"orderPrice":"77.000000000000000000","type":"sell-limit","orderId":27163533,"clientOrderId":"test3","orderSource":"spot-api","orderStatus":"submitted","symbol":"btcusdt","eventType":"creation"}}
{"action":"push","ch":"orders#*","data":{"orderSource":"spot-web","accountId":16820007,"orderPrice":"70000","orderSize":"0.000157","orderCreateTime":1731039387696,"symbol":"btcusdt","eventType":"creation","type":"buy-limit","orderId":1199329381585359,"clientOrderId":"","orderStatus":"submitted"}}
1 change: 1 addition & 0 deletions exchanges/huobi/testdata/wsMyTrades.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ch":"trade.clearing#btcusdt#1","data":{"eventType":"trade","symbol":"btcusdt","orderId":99998888,"tradePrice":"9999.99","tradeVolume":"0.96","orderSide":"buy","aggressor":true,"tradeId":919219323232,"tradeTime":1583853365996,"transactFee":"19.88","feeDeduct ":"0","feeDeductType":"","feeCurrency":"btc","accountId":9912791,"source":"spot-api","orderPrice":"10000","orderSize":"1","clientOrderId":"a001","orderCreateTime":1583853365586,"orderStatus":"partial-filled"}}
1 change: 1 addition & 0 deletions exchanges/huobi/testdata/wsOrderbook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ch":"market.btcusdt.depth.step0","ts":1630983549503,"tick":{"bids":[[52690.69,0.36281],[52690.68,0.2]],"asks":[[52690.7,0.372591],[52691.26,0.13]],"version":136998124622,"ts":1630983549500}}
1 change: 1 addition & 0 deletions exchanges/huobi/testdata/wsTicker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ch":"market.btcusdt.detail","ts":1630998026649,"tick":{"id":273956868110,"low":51000,"high":52924.14,"open":51823.62,"close":52379.99,"vol":727676440.200527,"amount":13991.028076056185,"version":273956868110,"count":471348}}
3 changes: 1 addition & 2 deletions exchanges/order/order_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ type ModifyResponse struct {
}

// Detail contains all properties of an order
// Each exchange has their own requirements, so not all fields
// are required to be populated
// Each exchange has their own requirements, so not all fields are required to be populated
type Detail struct {
ImmediateOrCancel bool
HiddenOrder bool
Expand Down
6 changes: 3 additions & 3 deletions exchanges/order/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,15 +1167,15 @@ func StringToOrderStatus(status string) (Status, error) {
switch status {
case AnyStatus.String():
return AnyStatus, nil
case New.String(), "PLACED", "ACCEPTED":
case New.String(), "PLACED", "ACCEPTED", "SUBMITTED":
return New, nil
case Active.String(), "STATUS_ACTIVE", "LIVE":
return Active, nil
case PartiallyFilled.String(), "PARTIALLY MATCHED", "PARTIALLY FILLED":
case PartiallyFilled.String(), "PARTIAL-FILLED", "PARTIALLY MATCHED", "PARTIALLY FILLED":
return PartiallyFilled, nil
case Filled.String(), "FULLY MATCHED", "FULLY FILLED", "ORDER_FULLY_TRANSACTED", "EFFECTIVE":
return Filled, nil
case PartiallyCancelled.String(), "PARTIALLY CANCELLED", "ORDER_PARTIALLY_TRANSACTED":
case PartiallyCancelled.String(), "PARTIAL-CANCELED", "PARTIALLY CANCELLED", "ORDER_PARTIALLY_TRANSACTED":
return PartiallyCancelled, nil
case PartiallyFilledCancelled.String(), "PARTIALLYFILLEDCANCELED":
return PartiallyFilledCancelled, nil
Expand Down
31 changes: 27 additions & 4 deletions internal/testing/exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,45 @@ func MockWsInstance[T any, PT interface {
return e
}

// FixtureToDataHandler squirts the contents of a file to a reader function (probably e.wsHandleData)
// FixtureError contains an error and the message that caused it
type FixtureError struct {
Err error
Msg []byte
}

// FixtureToDataHandler squirts the contents of a file to a reader function (probably e.wsHandleData) and asserts no errors are returned
func FixtureToDataHandler(tb testing.TB, fixturePath string, reader func([]byte) error) {
tb.Helper()

for _, e := range FixtureToDataHandlerWithErrors(tb, fixturePath, reader) {
assert.NoErrorf(tb, e.Err, "Should not error handling message:\n%s", e.Msg)
}
}

// FixtureToDataHandlerWithErrors squirts the contents of a file to a reader function (probably e.wsHandleData) and returns handler errors
// Any errors setting up the fixture will fail tests
func FixtureToDataHandlerWithErrors(tb testing.TB, fixturePath string, reader func([]byte) error) []FixtureError {
tb.Helper()

fixture, err := os.Open(fixturePath)
assert.NoError(tb, err, "Opening fixture '%s' should not error", fixturePath)
require.NoError(tb, err, "Opening fixture '%s' should not error", fixturePath)
defer func() {
assert.NoError(tb, fixture.Close(), "Closing the fixture file should not error")
}()

errs := []FixtureError{}
s := bufio.NewScanner(fixture)
for s.Scan() {
msg := s.Bytes()
err := reader(msg)
assert.NoErrorf(tb, err, "Fixture message should not error:\n%s", msg)
if err := reader(msg); err != nil {
errs = append(errs, FixtureError{
Err: err,
Msg: msg,
})
}
}
assert.NoError(tb, s.Err(), "Fixture Scanner should not error")
return errs
}

var setupWsMutex sync.Mutex
Expand Down Expand Up @@ -178,6 +200,7 @@ var updatePairsOnce = make(map[string]*currency.PairsManager)

// UpdatePairsOnce ensures pairs are only updated once in parallel tests
// A clone of the cache of the updated pairs is used to populate duplicate requests
// Any pairs enabled after this is called will be lost on the next call
func UpdatePairsOnce(tb testing.TB, e exchange.IBotExchange) {
tb.Helper()

Expand Down
2 changes: 1 addition & 1 deletion testdata/configtest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@
},
"spot": {
"assetEnabled": true,
"enabled": "BTC-USDT",
"enabled": "BTC-USDT,ETH-BTC",
"available": "PROPY-ETH,IOTA-BTC,UGAS-ETH,PAI-USDT,BSV-HUSD,MTX-ETH,BCH-BTC,LTC-HT,SOC-USDT,WXT-BTC,SALT-BTC,RCN-ETH,PNT-ETH,TT-USDT,AIDOC-ETH,BIX-BTC,OCN-USDT,QTUM-ETH,KCASH-ETH,SNT-USDT,LUN-BTC,QASH-BTC,ITC-BTC,NAS-BTC,XMR-BTC,TNT-ETH,UC-ETH,FAIR-BTC,PC-ETH,YEE-BTC,PAY-ETH,XMX-BTC,CRE-USDT,BAT-ETH,BHT-USDT,CKB-HT,LAMB-HT,AE-USDT,QUN-ETH,LYM-BTC,BCH-HT,BHT-BTC,RUFF-ETH,CNN-BTC,FOR-USDT,GTC-ETH,TRX-ETH,ELA-USDT,ACT-ETH,SMT-ETH,BUT-ETH,BCH-USDT,ICX-BTC,MEET-BTC,NCC-BTC,APPC-BTC,GVE-ETH,TNB-BTC,STEEM-ETH,18C-ETH,LBA-BTC,EKO-BTC,REQ-BTC,SOC-BTC,BOX-ETH,ELF-BTC,ZRX-ETH,LET-USDT,HT-BTC,TUSD-HUSD,EGCC-BTC,WTC-BTC,ATP-USDT,DOCK-USDT,PAI-BTC,ONT-ETH,IRIS-BTC,BTT-ETH,SC-BTC,XZC-BTC,LBA-USDT,HT-USDT,VET-ETH,KMD-ETH,SHE-ETH,PORTAL-BTC,ONE-BTC,BIX-USDT,RCCC-BTC,SKM-USDT,XTZ-ETH,SWFTC-BTC,RSR-BTC,LINK-ETH,DATX-BTC,HPT-HT,GET-ETH,BLZ-ETH,CTXC-USDT,C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