Skip to content

Commit

Permalink
Binance: Fix websocket reponse unmarshal bug (thrasher-corp#651)
Browse files Browse the repository at this point in the history
* binance: Fix websocket reponse unmarshal, fix field type when not null and add test replicating what I received from endpoint.

* Binancce: RMLINE AND COMMENT

* return error on any uncaptured data
  • Loading branch information
shazbert authored Mar 25, 2021
1 parent 881bab2 commit fe3d0e9
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 177 deletions.
95 changes: 28 additions & 67 deletions exchanges/binance/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2012,68 +2012,6 @@ func TestWSUnsubscriptionHandling(t *testing.T) {
}
}

func TestWsOrderUpdateHandling(t *testing.T) {
t.Parallel()
pressXToJSON := []byte(`{
"e": "executionReport",
"E": 1499405658658,
"s": "BTCUSDT",
"c": "mUvoqJxFIILMdfAW5iGSOW",
"S": "BUY",
"o": "LIMIT",
"f": "GTC",
"q": "1.00000000",
"p": "0.10264410",
"P": "0.00000000",
"F": "0.00000000",
"g": -1,
"C": null,
"x": "NEW",
"X": "NEW",
"r": "NONE",
"i": 4293153,
"l": "0.00000000",
"z": "0.00000000",
"L": "0.00000000",
"n": "0",
"N": null,
"T": 1499405658657,
"t": -1,
"I": 8641984,
"w": true,
"m": false,
"M": false,
"O": 1499405658657,
"Z": "0.00000000",
"Y": "0.00000000",
"Q": "0.00000000"
}`)
err := b.wsHandleData(pressXToJSON)
if err != nil {
t.Error(err)
}
}

func TestWsOutboundAccountPosition(t *testing.T) {
t.Parallel()
pressXToJSON := []byte(`{
"e": "outboundAccountPosition",
"E": 1564034571105,
"u": 1564034571073,
"B": [
{
"a": "ETH",
"f": "10000.000000",
"l": "0.000000"
}
]
}`)
err := b.wsHandleData(pressXToJSON)
if err != nil {
t.Error(err)
}
}

func TestWsTickerUpdate(t *testing.T) {
t.Parallel()
pressXToJSON := []byte(`{"stream":"btcusdt@ticker","data":{"e":"24hrTicker","E":1580254809477,"s":"BTCUSDT","p":"420.97000000","P":"4.720","w":"9058.27981278","x":"8917.98000000","c":"9338.96000000","Q":"0.17246300","b":"9338.03000000","B":"0.18234600","a":"9339.70000000","A":"0.14097600","o":"8917.99000000","h":"9373.19000000","l":"8862.40000000","v":"72229.53692000","q":"654275356.16896672","O":1580168409456,"C":1580254809456,"F":235294268,"L":235894703,"n":600436}}`)
Expand Down Expand Up @@ -2237,13 +2175,13 @@ func TestWsDepthUpdate(t *testing.T) {

func TestWsBalanceUpdate(t *testing.T) {
t.Parallel()
pressXToJSON := []byte(`{
pressXToJSON := []byte(`{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{
"e": "balanceUpdate",
"E": 1573200697110,
"a": "BTC",
"d": "100.00000000",
"T": 1573200697068
}`)
}}`)
err := b.wsHandleData(pressXToJSON)
if err != nil {
t.Error(err)
Expand All @@ -2252,7 +2190,7 @@ func TestWsBalanceUpdate(t *testing.T) {

func TestWsOCO(t *testing.T) {
t.Parallel()
pressXToJSON := []byte(`{
pressXToJSON := []byte(`{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{
"e": "listStatus",
"E": 1564035303637,
"s": "ETHBTC",
Expand All @@ -2275,7 +2213,7 @@ func TestWsOCO(t *testing.T) {
"c": "bfYPSQdLoqAJeNrOr9adzq"
}
]
}`)
}}`)
err := b.wsHandleData(pressXToJSON)
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -2490,7 +2428,6 @@ func TestSetExchangeOrderExecutionLimits(t *testing.T) {
if err != nil {
t.Fatal(err)
}

err = b.UpdateOrderExecutionLimits(asset.CoinMarginedFutures)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -2530,3 +2467,27 @@ func TestSetExchangeOrderExecutionLimits(t *testing.T) {
t.Fatalf("expected %v, but receieved %v", order.ErrPriceBelowMin, err)
}
}

func TestWsOrderExecutionReport(t *testing.T) {
t.Parallel()
payload := []byte(`{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e":"executionReport","E":1616627567900,"s":"BTCUSDT","c":"c4wyKsIhoAaittTYlIVLqk","S":"BUY","o":"LIMIT","f":"GTC","q":"0.00028400","p":"52789.10000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"NEW","X":"NEW","r":"NONE","i":5340845958,"l":"0.00000000","z":"0.00000000","L":"0.00000000","n":"0","N":null,"T":1616627567900,"t":-1,"I":11388173160,"w":true,"m":false,"M":false,"O":1616627567900,"Z":"0.00000000","Y":"0.00000000","Q":"0.00000000"}}`)
err := b.wsHandleData(payload)
if err != nil {
t.Fatal(err)
}

payload = []byte(`{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e":"executionReport","E":1616633041556,"s":"BTCUSDT","c":"YeULctvPAnHj5HXCQo9Mob","S":"BUY","o":"LIMIT","f":"GTC","q":"0.00028600","p":"52436.85000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"TRADE","X":"FILLED","r":"NONE","i":5341783271,"l":"0.00028600","z":"0.00028600","L":"52436.85000000","n":"0.00000029","N":"BTC","T":1616633041555,"t":726946523,"I":11390206312,"w":false,"m":false,"M":true,"O":1616633041555,"Z":"14.99693910","Y":"14.99693910","Q":"0.00000000"}}`)
err = b.wsHandleData(payload)
if err != nil {
t.Fatal(err)
}
}

func TestWsOutboundAccountPosition(t *testing.T) {
t.Parallel()
payload := []byte(`{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e":"outboundAccountPosition","E":1616628815745,"u":1616628815745,"B":[{"a":"BTC","f":"0.00225109","l":"0.00123000"},{"a":"BNB","f":"0.00000000","l":"0.00000000"},{"a":"USDT","f":"54.43390661","l":"0.00000000"}]}}`)
err := b.wsHandleData(payload)
if err != nil {
t.Fatal(err)
}
}
Loading

0 comments on commit fe3d0e9

Please sign in to comment.