From fe4221def0e1cbed7b26bcdfc884e93736d93e4c Mon Sep 17 00:00:00 2001 From: Yordan Miladinov Date: Wed, 6 Oct 2021 20:38:40 -0700 Subject: [PATCH] exchanges/ftx: test ws -> ticker.Price conversion (#797) * exchanges/ftx: add TestFTX_wsHandleData_Price * exchange/ftx/test: proper types in casting errors --- exchanges/ftx/ftx_websocket_test.go | 37 ++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/exchanges/ftx/ftx_websocket_test.go b/exchanges/ftx/ftx_websocket_test.go index c97b6cd4..2e66f970 100644 --- a/exchanges/ftx/ftx_websocket_test.go +++ b/exchanges/ftx/ftx_websocket_test.go @@ -9,6 +9,7 @@ import ( "github.com/thrasher-corp/gocryptotrader/exchanges/asset" "github.com/thrasher-corp/gocryptotrader/exchanges/order" "github.com/thrasher-corp/gocryptotrader/exchanges/stream" + "github.com/thrasher-corp/gocryptotrader/exchanges/ticker" ) func parseRaw(t *testing.T, input string) interface{} { @@ -72,7 +73,7 @@ func TestFTX_wsHandleData_Details(t *testing.T) { p := parseRaw(t, inputPartiallyCancelled) x, ok := p.(*order.Detail) if !ok { - t.Fatalf("have %T, want order.Detail", p) + t.Fatalf("have %T, want *order.Detail", p) } // "reduceOnly" and "liquidation" do not have corresponding fields in // order.Detail. @@ -194,6 +195,40 @@ func TestFTX_wsHandleData_wsFills(t *testing.T) { } } +func TestFTX_wsHandleData_Price(t *testing.T) { + const input = `{ + "channel": "ticker", + "market": "BTC/USDT", + "type": "update", + "data": { + "bid": 16.0, + "ask": 32.0, + "bidSize": 64.0, + "askSize": 128.0, + "last": 256.0, + "time": 1073741824.0 + } + }` + + p := parseRaw(t, input) + x, ok := p.(*ticker.Price) + + if !ok { + t.Fatalf("have %T, want *ticker.Price", p) + } + + if x.AssetType != asset.Spot || + !x.Pair.Equal(currency.NewPair(currency.BTC, currency.USDT)) || + x.Bid != 16 || + x.BidSize != 64 || + x.Ask != 32 || + x.AskSize != 128 || + x.Last != 256 || + !x.LastUpdated.Equal(time.Unix(1073741824, 0)) { + t.Error("parsed values do not match") + } +} + func TestParsingOrders(t *testing.T) { t.Parallel() data := []byte(`{