exchanges/ftx: test ws -> ticker.Price conversion (#797)

* exchanges/ftx: add TestFTX_wsHandleData_Price

* exchange/ftx/test: proper types in casting errors
This commit is contained in:
Yordan Miladinov
2021-10-06 20:38:40 -07:00
committed by GitHub
parent 4caa1125bc
commit fe4221def0

View File

@@ -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(`{