From cf969f6b55b7648bf43d6cb146c51b48ef3f9714 Mon Sep 17 00:00:00 2001 From: Chathumi Kumarapeli Date: Wed, 8 Jan 2025 11:54:40 +0530 Subject: [PATCH] Added test for perp pricing --- marketdata/rest_test.go | 16 +++++ marketdata/stream/client_test.go | 94 ++++++++++++++++++-------- marketdata/stream/entities_easyjson.go | 60 ++++++++-------- marketdata/stream/message_test.go | 12 ++++ 4 files changed, 124 insertions(+), 58 deletions(-) diff --git a/marketdata/rest_test.go b/marketdata/rest_test.go index 7b617d1..da1da72 100644 --- a/marketdata/rest_test.go +++ b/marketdata/rest_test.go @@ -1468,3 +1468,19 @@ func TestLatestCryptoPerpQuotes(t *testing.T) { }, got["ETH-PERP"]) assert.Equal(t, 1.9428, got["BTC-PERP"].BidSize) } + +func TestGetLatestCryptoPerpPricing(t *testing.T) { + c := DefaultClient + c.do = mockResp(`{"futuresPricing": {"BTC-PERP": {"t": "2024-12-19T09:33:36.311Z", "ft": "2024-12-19T10:33:36.311Z", "oi": 90.7367, "ip": 50702.8, "mp": 50652.3553, "fr": 0.000565699}}}`) + got, err := c.GetLatestCryptoPerpPricing("BTC-PERP", GetLatestCryptoPerpPricingRequest{}) + require.NoError(t, err) + require.NotNil(t, got) + assert.Equal(t, CryptoPerpPricing{ + IndexPrice: 50702.8, + MarkPrice: 50652.3553, + OpenInterest: 90.7367, + FundingRate: 0.000565699, + Timestamp: time.Date(2024, 12, 19, 9, 33, 36, 311000000, time.UTC), + NextFundingTime: time.Date(2024, 12, 19, 10, 33, 36, 311000000, time.UTC), + }, *got) +} diff --git a/marketdata/stream/client_test.go b/marketdata/stream/client_test.go index 1ec704d..91d9249 100644 --- a/marketdata/stream/client_test.go +++ b/marketdata/stream/client_test.go @@ -55,7 +55,7 @@ func TestConnectFails(t *testing.T) { WithReconnectSettings(1, 0), withConnCreator(connCreator)) case cryptoPerpTests: - c = NewCryptoPerpClient( + c = NewCryptoClient( marketdata.GLOBAL, WithReconnectSettings(1, 0), withConnCreator(connCreator)) @@ -94,7 +94,7 @@ func TestConnectWithInvalidURL(t *testing.T) { WithBaseURL("http://192.168.0.%31/"), WithReconnectSettings(1, 0)) case cryptoPerpTests: - c = NewCryptoPerpClient( + c = NewCryptoClient( marketdata.GLOBAL, WithBaseURL("http://192.168.0.%31/"), WithReconnectSettings(1, 0)) @@ -141,7 +141,7 @@ func TestConnectImmediatelyFailsAfterIrrecoverableErrors(t *testing.T) { case cryptoTests: c = NewCryptoClient(marketdata.US, reconnectSettings, withConnCreator(connCreator)) case cryptoPerpTests: - c = NewCryptoPerpClient(marketdata.GLOBAL, reconnectSettings, withConnCreator(connCreator)) + c = NewCryptoClient(marketdata.GLOBAL, reconnectSettings, withConnCreator(connCreator)) } // server welcomes the client @@ -192,7 +192,7 @@ func TestContextCancelledBeforeConnect(t *testing.T) { WithBaseURL("http://test.paca/v2"), withConnCreator(connCreator)) case cryptoPerpTests: - c = NewCryptoPerpClient( + c = NewCryptoClient( marketdata.GLOBAL, WithBaseURL("http://test.paca/v2"), withConnCreator(connCreator)) @@ -225,7 +225,7 @@ func TestConnectSucceeds(t *testing.T) { case cryptoTests: c = NewCryptoClient(marketdata.US, withConnCreator(connCreator)) case cryptoPerpTests: - c = NewCryptoPerpClient(marketdata.GLOBAL, withConnCreator(connCreator)) + c = NewCryptoClient(marketdata.GLOBAL, withConnCreator(connCreator)) } ctx, cancel := context.WithCancel(context.Background()) @@ -279,7 +279,7 @@ func TestCallbacksCalledOnConnectAndDisconnect(t *testing.T) { WithConnectCallback(connectCallback), WithDisconnectCallback(disconnectCallback)) case cryptoPerpTests: - c = NewCryptoPerpClient(marketdata.GLOBAL, + c = NewCryptoClient(marketdata.GLOBAL, withConnCreator(connCreator), WithConnectCallback(connectCallback), WithDisconnectCallback(disconnectCallback)) @@ -359,6 +359,8 @@ func TestSubscribeBeforeConnectCrypto(t *testing.T) { assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) err = c.SubscribeToOrderbooks(func(_ CryptoOrderbook) {}) assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) + err = c.SubscribeToPerpPricing(func(_ CryptoPerpPricing) {}) + assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) err = c.UnsubscribeFromTrades() assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) err = c.UnsubscribeFromQuotes() @@ -371,6 +373,8 @@ func TestSubscribeBeforeConnectCrypto(t *testing.T) { assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) err = c.UnsubscribeFromOrderbooks() assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) + err = c.UnsubscribeFromPerpPricing() + assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) } func TestSubscribeMultipleCallsStocks(t *testing.T) { @@ -970,7 +974,7 @@ func TestPingFails(t *testing.T) { c = NewCryptoClient(marketdata.US, WithReconnectSettings(1, 0), withConnCreator(connCreator)) case cryptoPerpTests: - c = NewCryptoPerpClient(marketdata.GLOBAL, + c = NewCryptoClient(marketdata.GLOBAL, WithReconnectSettings(1, 0), withConnCreator(connCreator)) } @@ -993,7 +997,7 @@ func TestPingFails(t *testing.T) { return nil, connErr } case cryptoPerpTests: - c.(*CryptoPerpClient).connCreator = func(_ context.Context, _ url.URL) (conn, error) { + c.(*CryptoClient).connCreator = func(_ context.Context, _ url.URL) (conn, error) { return nil, connErr } } @@ -1614,7 +1618,7 @@ func TestCryptoClientConstructURL(t *testing.T) { } func TestSubscribeBeforeConnectCryptoPerp(t *testing.T) { - c := NewCryptoPerpClient(marketdata.GLOBAL, WithBaseURL(perpBaseURL)) + c := NewCryptoClient(marketdata.GLOBAL, WithBaseURL(perpBaseURL)) err := c.SubscribeToTrades(func(_ CryptoTrade) {}) assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) @@ -1628,6 +1632,8 @@ func TestSubscribeBeforeConnectCryptoPerp(t *testing.T) { assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) err = c.SubscribeToOrderbooks(func(_ CryptoOrderbook) {}) assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) + err = c.SubscribeToPerpPricing(func(_ CryptoPerpPricing) {}) + assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) err = c.UnsubscribeFromTrades() assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) err = c.UnsubscribeFromQuotes() @@ -1640,6 +1646,8 @@ func TestSubscribeBeforeConnectCryptoPerp(t *testing.T) { assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) err = c.UnsubscribeFromOrderbooks() assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) + err = c.UnsubscribeFromPerpPricing() + assert.Equal(t, ErrSubscriptionChangeBeforeConnect, err) } func TestSubscribeCalledButClientTerminatesCryptoPerp(t *testing.T) { @@ -1647,7 +1655,7 @@ func TestSubscribeCalledButClientTerminatesCryptoPerp(t *testing.T) { defer connection.close() writeInitialFlowMessagesToConn(t, connection, subscriptions{}) - c := NewCryptoPerpClient(marketdata.GLOBAL, + c := NewCryptoClient(marketdata.GLOBAL, WithBaseURL(perpBaseURL), WithCredentials("my_key", "my_secret"), withConnCreator(func(_ context.Context, _ url.URL) (conn, error) { return connection, nil })) @@ -1687,7 +1695,7 @@ func TestSubscribeFailsDueToErrorCryptoPerp(t *testing.T) { defer connection.close() writeInitialFlowMessagesToConn(t, connection, subscriptions{}) - c := NewCryptoPerpClient(marketdata.GLOBAL, + c := NewCryptoClient(marketdata.GLOBAL, WithBaseURL(perpBaseURL), WithCredentials("my_key", "my_secret"), withConnCreator(func(_ context.Context, _ url.URL) (conn, error) { @@ -1774,12 +1782,13 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { connection := newMockConn() defer connection.close() writeInitialFlowMessagesToConn(t, connection, subscriptions{ - trades: []string{"BTC-PERP"}, - quotes: []string{"BTC-PERP"}, - bars: []string{"BTC-PERP"}, - updatedBars: []string{"BTC-PERP"}, - dailyBars: []string{"BTC-PERP"}, - orderbooks: []string{"BTC-PERP"}, + trades: []string{"BTC-PERP"}, + quotes: []string{"BTC-PERP"}, + bars: []string{"BTC-PERP"}, + updatedBars: []string{"BTC-PERP"}, + dailyBars: []string{"BTC-PERP"}, + orderbooks: []string{"BTC-PERP"}, + futuresPricing: []string{"BTC-PERP"}, }) trades := make(chan CryptoTrade, 10) @@ -1788,7 +1797,8 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { updatedBars := make(chan CryptoBar, 10) dailyBars := make(chan CryptoBar, 10) orderbooks := make(chan CryptoOrderbook, 10) - c := NewCryptoPerpClient(marketdata.GLOBAL, + pricing := make(chan CryptoPerpPricing, 10) + c := NewCryptoClient(marketdata.GLOBAL, WithBaseURL(perpBaseURL), WithCryptoTrades(func(t CryptoTrade) { trades <- t }, "BTC-PERP"), WithCryptoQuotes(func(q CryptoQuote) { quotes <- q }, "BTC-PERP"), @@ -1796,6 +1806,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { WithCryptoUpdatedBars(func(b CryptoBar) { updatedBars <- b }, "BTC-PERP"), WithCryptoDailyBars(func(b CryptoBar) { dailyBars <- b }, "BTC-PERP"), WithCryptoOrderbooks(func(ob CryptoOrderbook) { orderbooks <- ob }, "BTC-PERP"), + WithCryptoPerpPricing(func(p CryptoPerpPricing) { pricing <- p }, "BTC-PERP"), withConnCreator(func(_ context.Context, _ url.URL) (conn, error) { return connection, nil })) @@ -1811,7 +1822,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { cryptoBarWithT{ Type: "b", Symbol: "BTC-PERP", - Exchange: "TEST", + Exchange: "PERP", Volume: 10, TradeCount: 3, VWAP: 123.45, @@ -1819,7 +1830,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { cryptoBarWithT{ Type: "d", Symbol: "BTC-PERP", - Exchange: "TES7", + Exchange: "PERP", Open: 196.05, High: 196.3, TradeCount: 32, @@ -1828,7 +1839,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { cryptoBarWithT{ Type: "u", Symbol: "BTC-PERP", - Exchange: "TES7", + Exchange: "PERP", TradeCount: 33, }, cryptoQuoteWithT{ @@ -1838,7 +1849,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { AskSize: 3.12, BidPrice: 2712.82, BidSize: 3.982, - Exchange: "TEST", + Exchange: "PERP", }, }) // sending a trade @@ -1848,7 +1859,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { Type: "t", Symbol: "BTC-PERP", Timestamp: ts, - Exchange: "TST", + Exchange: "PERP", Price: 4123.123, Size: 34.876, ID: 25, @@ -1860,7 +1871,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { cryptoOrderbookWithT{ Type: "o", Symbol: "BTC-PERP", - Exchange: "TST", + Exchange: "PERP", Bids: []cryptoOrderbookEntry{ {Price: 111.1, Size: 222.2}, {Price: 333.3, Size: 444.4}, @@ -1871,6 +1882,21 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { }, }, }) + // sending perp pricing + nft := time.Date(2021, 6, 2, 20, 12, 4, 3534, time.UTC) + connection.readCh <- serializeToMsgpack(t, []interface{}{ + cryptoPerpPricingWithT{ + Type: "p", + Symbol: "BTC-PERP", + Exchange: "PERP", + Timestamp: ts, + IndexPrice: 0.72817, + MarkPrice: 0.727576296, + FundingRate: -0.000439065, + OpenInterest: 46795, + NextFundingTime: nft, + }, + }) // checking contents select { @@ -1878,7 +1904,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { assert.EqualValues(t, 10, bar.Volume) assert.EqualValues(t, 3, bar.TradeCount) assert.EqualValues(t, 123.45, bar.VWAP) - assert.Equal(t, "TEST", bar.Exchange) + assert.Equal(t, "PERP", bar.Exchange) case <-time.After(time.Second): require.Fail(t, "no bar received in time") } @@ -1896,7 +1922,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { assert.EqualValues(t, 196.3, dailyBar.High) assert.EqualValues(t, 32, dailyBar.TradeCount) assert.EqualValues(t, 196.21, dailyBar.VWAP) - assert.Equal(t, "TES7", dailyBar.Exchange) + assert.Equal(t, "PERP", dailyBar.Exchange) case <-time.After(time.Second): require.Fail(t, "no daily bar received in time") } @@ -1907,7 +1933,7 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { assert.EqualValues(t, 2848.53, quote.AskPrice) assert.EqualValues(t, 3.12, quote.AskSize) assert.EqualValues(t, 3.982, quote.BidSize) - assert.EqualValues(t, "TEST", quote.Exchange) + assert.EqualValues(t, "PERP", quote.Exchange) case <-time.After(time.Second): require.Fail(t, "no quote received in time") } @@ -1928,6 +1954,18 @@ func TestCoreFunctionalityCryptoPerp(t *testing.T) { case <-time.After(time.Second): require.Fail(t, "no orderbook received in time") } + + select { + case p := <-pricing: + assert.Equal(t, "BTC-PERP", p.Symbol) + assert.EqualValues(t, 0.72817, p.IndexPrice) + assert.EqualValues(t, 0.727576296, p.MarkPrice) + assert.EqualValues(t, -0.000439065, p.FundingRate) + assert.EqualValues(t, 46795, p.OpenInterest) + assert.EqualValues(t, "PERP", p.Exchange) + case <-time.After(time.Second): + require.Fail(t, "no perp pricing received in time") + } } func TestCryptoPerpClientConstructURL(t *testing.T) { @@ -1959,7 +1997,7 @@ func TestCryptoPerpClientConstructURL(t *testing.T) { }, } { t.Run(test.name, func(t *testing.T) { - c := NewCryptoPerpClient( + c := NewCryptoClient( marketdata.GLOBAL, WithBaseURL(test.baseURL), ) diff --git a/marketdata/stream/entities_easyjson.go b/marketdata/stream/entities_easyjson.go index de078e9..4436d40 100644 --- a/marketdata/stream/entities_easyjson.go +++ b/marketdata/stream/entities_easyjson.go @@ -1668,7 +1668,7 @@ func (v *CryptoQuote) UnmarshalJSON(data []byte) error { func (v *CryptoQuote) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream12(in *jlexer.Lexer, out *CryptoPerpPricing) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(in *jlexer.Lexer, out *CryptoPerpPricing) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1717,7 +1717,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream12 in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream12(out *jwriter.Writer, in CryptoPerpPricing) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(out *jwriter.Writer, in CryptoPerpPricing) { out.RawByte('{') first := true _ = first @@ -1767,27 +1767,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream12 // MarshalJSON supports json.Marshaler interface func (v CryptoPerpPricing) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream12(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CryptoPerpPricing) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream12(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CryptoPerpPricing) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream12(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CryptoPerpPricing) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream12(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13(in *jlexer.Lexer, out *CryptoOrderbookEntry) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(in *jlexer.Lexer, out *CryptoOrderbookEntry) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1820,7 +1820,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13 in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13(out *jwriter.Writer, in CryptoOrderbookEntry) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(out *jwriter.Writer, in CryptoOrderbookEntry) { out.RawByte('{') first := true _ = first @@ -1840,27 +1840,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13 // MarshalJSON supports json.Marshaler interface func (v CryptoOrderbookEntry) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CryptoOrderbookEntry) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CryptoOrderbookEntry) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CryptoOrderbookEntry) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream13(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(in *jlexer.Lexer, out *CryptoOrderbook) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(in *jlexer.Lexer, out *CryptoOrderbook) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1945,7 +1945,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14 in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(out *jwriter.Writer, in CryptoOrderbook) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(out *jwriter.Writer, in CryptoOrderbook) { out.RawByte('{') first := true _ = first @@ -2007,27 +2007,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14 // MarshalJSON supports json.Marshaler interface func (v CryptoOrderbook) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CryptoOrderbook) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CryptoOrderbook) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CryptoOrderbook) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream14(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(in *jlexer.Lexer, out *CryptoBar) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream17(in *jlexer.Lexer, out *CryptoBar) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2078,7 +2078,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15 in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(out *jwriter.Writer, in CryptoBar) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream17(out *jwriter.Writer, in CryptoBar) { out.RawByte('{') first := true _ = first @@ -2138,27 +2138,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15 // MarshalJSON supports json.Marshaler interface func (v CryptoBar) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream17(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CryptoBar) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream17(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CryptoBar) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream17(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CryptoBar) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream15(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream17(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(in *jlexer.Lexer, out *Bar) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream18(in *jlexer.Lexer, out *Bar) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2207,7 +2207,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16 in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(out *jwriter.Writer, in Bar) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream18(out *jwriter.Writer, in Bar) { out.RawByte('{') first := true _ = first @@ -2262,23 +2262,23 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16 // MarshalJSON supports json.Marshaler interface func (v Bar) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream18(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Bar) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream18(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Bar) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream18(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Bar) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream16(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream18(l, v) } diff --git a/marketdata/stream/message_test.go b/marketdata/stream/message_test.go index ae4e381..ff345c3 100644 --- a/marketdata/stream/message_test.go +++ b/marketdata/stream/message_test.go @@ -435,6 +435,18 @@ var testCryptoOrderbook = cryptoOrderbookWithT{ }, } +type cryptoPerpPricingWithT struct { + Type string `msgpack:"T"` + Symbol string `msgpack:"S"` + Timestamp time.Time `msgpack:"t"` + Exchange string `msgpack:"x"` + IndexPrice float64 `msgpack:"ip"` + MarkPrice float64 `msgpack:"mp"` + FundingRate float64 `msgpack:"fr"` + OpenInterest float64 `msgpack:"oi"` + NextFundingTime time.Time `msgpack:"ft"` +} + var testOther = other{ Type: "other", Whatever: "whatever",