From 3252bdb8ec22d32a8cbd7f3d1f2aed7374f977fe Mon Sep 17 00:00:00 2001 From: Dasun Nimantha Date: Wed, 1 Jan 2025 11:31:33 +0530 Subject: [PATCH] Refactor futures pricing path --- marketdata/stream/entities.go | 2 +- marketdata/stream/entities_easyjson.go | 284 ++++++++++++------------- marketdata/stream/message.go | 60 +++++- marketdata/stream/subscription.go | 38 ++-- 4 files changed, 211 insertions(+), 173 deletions(-) diff --git a/marketdata/stream/entities.go b/marketdata/stream/entities.go index 7dec87c..f194a4f 100644 --- a/marketdata/stream/entities.go +++ b/marketdata/stream/entities.go @@ -201,7 +201,7 @@ func (e errorMessage) Error() string { return e.msg } -type PerpPricingData struct { +type FuturesPricing struct { Symbol string Timestamp time.Time Exchange string diff --git a/marketdata/stream/entities_easyjson.go b/marketdata/stream/entities_easyjson.go index 12aa563..d881281 100644 --- a/marketdata/stream/entities_easyjson.go +++ b/marketdata/stream/entities_easyjson.go @@ -824,126 +824,7 @@ func (v *Quote) UnmarshalJSON(data []byte) error { func (v *Quote) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream5(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(in *jlexer.Lexer, out *PerpPricingData) { - isTopLevel := in.IsStart() - if in.IsNull() { - if isTopLevel { - in.Consumed() - } - in.Skip() - return - } - in.Delim('{') - for !in.IsDelim('}') { - key := in.UnsafeFieldName(false) - in.WantColon() - if in.IsNull() { - in.Skip() - in.WantComma() - continue - } - switch key { - case "symbol": - out.Symbol = string(in.String()) - case "timestamp": - if data := in.Raw(); in.Ok() { - in.AddError((out.Timestamp).UnmarshalJSON(data)) - } - case "exchange": - out.Exchange = string(in.String()) - case "index_price": - out.IndexPrice = float64(in.Float64()) - case "mark_price": - out.MarkPrice = float64(in.Float64()) - case "funding_rate": - out.FundingRate = float64(in.Float64()) - case "open_interest": - out.OpenInterest = float64(in.Float64()) - case "next_funding_time": - if data := in.Raw(); in.Ok() { - in.AddError((out.NextFundingTime).UnmarshalJSON(data)) - } - default: - in.SkipRecursive() - } - in.WantComma() - } - in.Delim('}') - if isTopLevel { - in.Consumed() - } -} -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(out *jwriter.Writer, in PerpPricingData) { - out.RawByte('{') - first := true - _ = first - { - const prefix string = ",\"symbol\":" - out.RawString(prefix[1:]) - out.String(string(in.Symbol)) - } - { - const prefix string = ",\"timestamp\":" - out.RawString(prefix) - out.Raw((in.Timestamp).MarshalJSON()) - } - { - const prefix string = ",\"exchange\":" - out.RawString(prefix) - out.String(string(in.Exchange)) - } - { - const prefix string = ",\"index_price\":" - out.RawString(prefix) - out.Float64(float64(in.IndexPrice)) - } - { - const prefix string = ",\"mark_price\":" - out.RawString(prefix) - out.Float64(float64(in.MarkPrice)) - } - { - const prefix string = ",\"funding_rate\":" - out.RawString(prefix) - out.Float64(float64(in.FundingRate)) - } - { - const prefix string = ",\"open_interest\":" - out.RawString(prefix) - out.Float64(float64(in.OpenInterest)) - } - { - const prefix string = ",\"next_funding_time\":" - out.RawString(prefix) - out.Raw((in.NextFundingTime).MarshalJSON()) - } - out.RawByte('}') -} - -// MarshalJSON supports json.Marshaler interface -func (v PerpPricingData) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - -// MarshalEasyJSON supports easyjson.Marshaler interface -func (v PerpPricingData) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(w, v) -} - -// UnmarshalJSON supports json.Unmarshaler interface -func (v *PerpPricingData) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(&r, v) - return r.Error() -} - -// UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *PerpPricingData) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(l, v) -} -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(in *jlexer.Lexer, out *OptionTrade) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(in *jlexer.Lexer, out *OptionTrade) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -986,7 +867,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7( in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(out *jwriter.Writer, in OptionTrade) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(out *jwriter.Writer, in OptionTrade) { out.RawByte('{') first := true _ = first @@ -1026,27 +907,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7( // MarshalJSON supports json.Marshaler interface func (v OptionTrade) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v OptionTrade) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *OptionTrade) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *OptionTrade) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream6(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(in *jlexer.Lexer, out *OptionQuote) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(in *jlexer.Lexer, out *OptionQuote) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1095,7 +976,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8( in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(out *jwriter.Writer, in OptionQuote) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(out *jwriter.Writer, in OptionQuote) { out.RawByte('{') first := true _ = first @@ -1150,27 +1031,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8( // MarshalJSON supports json.Marshaler interface func (v OptionQuote) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v OptionQuote) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *OptionQuote) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *OptionQuote) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream7(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(in *jlexer.Lexer, out *News) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(in *jlexer.Lexer, out *News) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1242,7 +1123,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9( in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(out *jwriter.Writer, in News) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(out *jwriter.Writer, in News) { out.RawByte('{') first := true _ = first @@ -1308,27 +1189,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9( // MarshalJSON supports json.Marshaler interface func (v News) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v News) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *News) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *News) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream8(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(in *jlexer.Lexer, out *LULD) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(in *jlexer.Lexer, out *LULD) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1371,7 +1252,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10 in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(out *jwriter.Writer, in LULD) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(out *jwriter.Writer, in LULD) { out.RawByte('{') first := true _ = first @@ -1411,24 +1292,143 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10 // MarshalJSON supports json.Marshaler interface func (v LULD) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v LULD) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *LULD) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *LULD) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream9(l, v) +} +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(in *jlexer.Lexer, out *FuturesPricing) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "symbol": + out.Symbol = string(in.String()) + case "timestamp": + if data := in.Raw(); in.Ok() { + in.AddError((out.Timestamp).UnmarshalJSON(data)) + } + case "exchange": + out.Exchange = string(in.String()) + case "index_price": + out.IndexPrice = float64(in.Float64()) + case "mark_price": + out.MarkPrice = float64(in.Float64()) + case "funding_rate": + out.FundingRate = float64(in.Float64()) + case "open_interest": + out.OpenInterest = float64(in.Float64()) + case "next_funding_time": + if data := in.Raw(); in.Ok() { + in.AddError((out.NextFundingTime).UnmarshalJSON(data)) + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(out *jwriter.Writer, in FuturesPricing) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"symbol\":" + out.RawString(prefix[1:]) + out.String(string(in.Symbol)) + } + { + const prefix string = ",\"timestamp\":" + out.RawString(prefix) + out.Raw((in.Timestamp).MarshalJSON()) + } + { + const prefix string = ",\"exchange\":" + out.RawString(prefix) + out.String(string(in.Exchange)) + } + { + const prefix string = ",\"index_price\":" + out.RawString(prefix) + out.Float64(float64(in.IndexPrice)) + } + { + const prefix string = ",\"mark_price\":" + out.RawString(prefix) + out.Float64(float64(in.MarkPrice)) + } + { + const prefix string = ",\"funding_rate\":" + out.RawString(prefix) + out.Float64(float64(in.FundingRate)) + } + { + const prefix string = ",\"open_interest\":" + out.RawString(prefix) + out.Float64(float64(in.OpenInterest)) + } + { + const prefix string = ",\"next_funding_time\":" + out.RawString(prefix) + out.Raw((in.NextFundingTime).MarshalJSON()) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v FuturesPricing) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v FuturesPricing) MarshalEasyJSON(w *jwriter.Writer) { + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *FuturesPricing) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *FuturesPricing) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream10(l, v) } func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3MarketdataStream11(in *jlexer.Lexer, out *CryptoTrade) { diff --git a/marketdata/stream/message.go b/marketdata/stream/message.go index b6ea9ee..35e8dcf 100644 --- a/marketdata/stream/message.go +++ b/marketdata/stream/message.go @@ -20,6 +20,7 @@ type msgHandler interface { handleCorrection(d *msgpack.Decoder, n int) error handleOrderbook(d *msgpack.Decoder, n int) error handleNews(d *msgpack.Decoder, n int) error + handleFuturesPricing(d *msgpack.Decoder, n int) error } func (c *client) handleMessage(b []byte) error { @@ -91,6 +92,8 @@ func (c *client) handleMessageType(msgType string, d *msgpack.Decoder, n int) er return c.handler.handleOrderbook(d, n) case "n": return c.handler.handleNews(d, n) + case "p": + return c.handler.handleFuturesPricing(d, n) case "subscription": return c.handleSubscriptionMessage(d, n) case msgTypeError: @@ -431,15 +434,20 @@ func (h *stocksMsgHandler) handleNews(d *msgpack.Decoder, n int) error { return discardMapContents(d, n) } +func (h *stocksMsgHandler) handleFuturesPricing(d *msgpack.Decoder, n int) error { + // should not happen! + return discardMapContents(d, n) +} + type cryptoMsgHandler struct { - mu sync.RWMutex - tradeHandler func(trade CryptoTrade) - quoteHandler func(quote CryptoQuote) - barHandler func(bar CryptoBar) - updatedBarHandler func(bar CryptoBar) - dailyBarHandler func(bar CryptoBar) - orderbookHandler func(ob CryptoOrderbook) - pricingDataHandler func(pd PerpPricingData) + mu sync.RWMutex + tradeHandler func(trade CryptoTrade) + quoteHandler func(quote CryptoQuote) + barHandler func(bar CryptoBar) + updatedBarHandler func(bar CryptoBar) + dailyBarHandler func(bar CryptoBar) + orderbookHandler func(ob CryptoOrderbook) + futuresPricingHandler func(pd FuturesPricing) } var _ msgHandler = (*cryptoMsgHandler)(nil) @@ -480,9 +488,8 @@ func (h *cryptoMsgHandler) handleTrade(d *msgpack.Decoder, n int) error { return nil } -// TODO: Need to update -func (h *cryptoMsgHandler) handlePricingData(d *msgpack.Decoder, n int) error { - pricing := PerpPricingData{} +func (h *cryptoMsgHandler) handleFuturesPricing(d *msgpack.Decoder, n int) error { + pricing := FuturesPricing{} for i := 0; i < n; i++ { key, err := d.DecodeString() if err != nil { @@ -493,8 +500,29 @@ func (h *cryptoMsgHandler) handlePricingData(d *msgpack.Decoder, n int) error { pricing.Symbol, err = d.DecodeString() case "x": pricing.Exchange, err = d.DecodeString() + case "ip": + pricing.IndexPrice, err = d.DecodeFloat64() + case "mp": + pricing.MarkPrice, err = d.DecodeFloat64() + case "fr": + pricing.FundingRate, err = d.DecodeFloat64() + case "oi": + pricing.OpenInterest, err = d.DecodeFloat64() + case "t": + pricing.Timestamp, err = d.DecodeTime() + case "ft": + pricing.NextFundingTime, err = d.DecodeTime() + default: + err = d.Skip() + } + if err != nil { + return err } } + h.mu.RLock() + pricingHandler := h.futuresPricingHandler + h.mu.RUnlock() + pricingHandler(pricing) return nil } @@ -794,6 +822,11 @@ func (h *optionsMsgHandler) handleNews(d *msgpack.Decoder, n int) error { return discardMapContents(d, n) } +func (h *optionsMsgHandler) handleFuturesPricing(d *msgpack.Decoder, n int) error { + // should not happen! + return discardMapContents(d, n) +} + type newsMsgHandler struct { mu sync.RWMutex newsHandler func(news News) @@ -891,6 +924,11 @@ func (h *newsMsgHandler) handleNews(d *msgpack.Decoder, n int) error { return nil } +func (h *newsMsgHandler) handleFuturesPricing(d *msgpack.Decoder, n int) error { + // should not happen! + return discardMapContents(d, n) +} + func discardMapContents(d *msgpack.Decoder, n int) error { for i := 0; i < n; i++ { // key diff --git a/marketdata/stream/subscription.go b/marketdata/stream/subscription.go index 79cc0ed..8508a8f 100644 --- a/marketdata/stream/subscription.go +++ b/marketdata/stream/subscription.go @@ -154,11 +154,11 @@ func (cc *CryptoClient) SubscribeToOrderbooks(handler func(CryptoOrderbook), sym return cc.client.handleSubChange(true, subscriptions{orderbooks: symbols}) } -func (cc *CryptoClient) SubscribeToPricingData(handler func(PerpPricingData), symbols ...string) error { +func (cc *CryptoClient) SubscribeToFuturesPricing(handler func(FuturesPricing), symbols ...string) error { cc.handler.mu.Lock() - cc.handler.pricingDataHandler = handler + cc.handler.futuresPricingHandler = handler cc.handler.mu.Unlock() - return cc.client.handleSubChange(true, subscriptions{pricingData: symbols}) + return cc.client.handleSubChange(true, subscriptions{futuresPricing: symbols}) } func (cc *CryptoClient) UnsubscribeFromTrades(symbols ...string) error { @@ -185,8 +185,8 @@ func (cc *CryptoClient) UnsubscribeFromOrderbooks(symbols ...string) error { return cc.handleSubChange(false, subscriptions{orderbooks: symbols}) } -func (cc *CryptoClient) UnsubscribeFromPricingData(symbols ...string) error { - return cc.handleSubChange(false, subscriptions{pricingData: symbols}) +func (cc *CryptoClient) UnsubscribeFromFuturesPricing(symbols ...string) error { + return cc.handleSubChange(false, subscriptions{futuresPricing: symbols}) } func (cc *OptionClient) SubscribeToTrades(handler func(OptionTrade), symbols ...string) error { @@ -223,24 +223,24 @@ func (nc *NewsClient) UnsubscribeFromNews(symbols ...string) error { } type subscriptions struct { - trades []string - quotes []string - bars []string - updatedBars []string - dailyBars []string - statuses []string - lulds []string - cancelErrors []string // Subscribed automatically. - corrections []string // Subscribed automatically. - orderbooks []string - news []string - pricingData []string + trades []string + quotes []string + bars []string + updatedBars []string + dailyBars []string + statuses []string + lulds []string + cancelErrors []string // Subscribed automatically. + corrections []string // Subscribed automatically. + orderbooks []string + news []string + futuresPricing []string } func (s subscriptions) noSubscribeCallNecessary() bool { return len(s.trades) == 0 && len(s.quotes) == 0 && len(s.bars) == 0 && len(s.updatedBars) == 0 && len(s.dailyBars) == 0 && len(s.statuses) == 0 && len(s.lulds) == 0 && - len(s.orderbooks) == 0 && len(s.news) == 0 + len(s.orderbooks) == 0 && len(s.news) == 0 && len(s.futuresPricing) == 0 } var timeAfter = time.After @@ -316,7 +316,7 @@ func getSubChangeMessage(subscribe bool, changes subscriptions) ([]byte, error) "lulds": changes.lulds, "orderbooks": changes.orderbooks, "news": changes.news, - "pricing": changes.pricingData, + "pricing": changes.futuresPricing, // No need to subscribe to cancel errors or corrections explicitly. }) }