Skip to content

Commit a835e79

Browse files
refactor: route websocket data by market first for overlapping event types (#551)
1 parent f647ac3 commit a835e79

File tree

3 files changed

+235
-130
lines changed

3 files changed

+235
-130
lines changed

websocket/config.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ const (
8181
type Market string
8282

8383
const (
84-
Stocks Market = "stocks"
85-
Options Market = "options"
86-
Forex Market = "forex"
87-
Crypto Market = "crypto"
88-
Indices Market = "indices"
89-
Futures Market = "futures"
84+
Stocks Market = "stocks"
85+
Options Market = "options"
86+
Forex Market = "forex"
87+
Crypto Market = "crypto"
88+
Indices Market = "indices"
89+
Futures Market = "futures"
90+
FuturesCME Market = "futures/cme"
91+
FuturesCBOT Market = "futures/cbot"
92+
FuturesNYMEX Market = "futures/nymex"
93+
FuturesCOMEX Market = "futures/comex"
9094
)
9195

9296
func (m Market) supports(topic Topic) bool {
@@ -103,6 +107,10 @@ func (m Market) supports(topic Topic) bool {
103107
return isBusinessFairMarketValue || (topic > forexMin && topic < forexMax)
104108
case Crypto:
105109
return isBusinessFairMarketValue || (topic > cryptoMin && topic < cryptoMax)
110+
case Indices:
111+
return topic == IndexSecAggs || topic == IndexMinAggs || topic == IndexValue
112+
case Futures, FuturesCME, FuturesCBOT, FuturesNYMEX, FuturesCOMEX:
113+
return topic > futuresMin && topic < futuresMax
106114
}
107115

108116
return true // assume user knows what they're doing if they use some unknown market

websocket/models/models.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,21 +407,24 @@ type FairMarketValue struct {
407407
// FuturesTrade represents a futures trade event.
408408
type FuturesTrade struct {
409409
EventType
410-
Symbol string `json:"sym,omitempty"`
411-
Price float64 `json:"p,omitempty"`
412-
Size int64 `json:"s,omitempty"`
413-
Timestamp int64 `json:"t,omitempty"`
410+
Symbol string `json:"sym,omitempty"`
411+
Price float64 `json:"p,omitempty"`
412+
Size int64 `json:"s,omitempty"`
413+
Timestamp int64 `json:"t,omitempty"`
414+
SequenceNumber int64 `json:"q,omitempty"`
414415
}
415416

416417
// FuturesQuote represents a futures quote event.
417418
type FuturesQuote struct {
418419
EventType
419-
Symbol string `json:"sym,omitempty"`
420-
BidPrice float64 `json:"bp,omitempty"`
421-
BidSize int64 `json:"bs,omitempty"`
422-
AskPrice float64 `json:"ap,omitempty"`
423-
AskSize int64 `json:"as,omitempty"`
424-
Timestamp int64 `json:"t,omitempty"`
420+
Symbol string `json:"sym,omitempty"`
421+
BidPrice float64 `json:"bp,omitempty"`
422+
BidSize int64 `json:"bs,omitempty"`
423+
BidTimestamp int64 `json:"bt,omitempty"`
424+
AskPrice float64 `json:"ap,omitempty"`
425+
AskSize int64 `json:"as,omitempty"`
426+
AskTimestamp int64 `json:"at,omitempty"`
427+
Timestamp int64 `json:"t,omitempty"`
425428
}
426429

427430
// FuturesAggregate represents an aggregate event (e.g., second or minute) for a futures contract.

0 commit comments

Comments
 (0)