Skip to content

Commit

Permalink
ability to set the market data buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
robaho committed Jul 22, 2024
1 parent 00dfe8f commit 7ef7019
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/marketmaker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func main() {
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
senderCompID := flag.String("id", "MM", "set the SenderCompID")
symbolAsCompID := flag.Bool("sid", false, "use symbol as SenderCompID")
mdbs := flag.String("mdbs", "", "market data buffer size (e.g. 1M, 16384, etc.)")

flag.Parse()

Expand Down Expand Up @@ -89,6 +90,9 @@ func main() {
}
p.SetString("fix", *fix)
p.SetString("senderCompID", *senderCompID)
if *mdbs!="" {
p.SetString("marketdata_buffer", *mdbs)
}

if len(quotedSymbols)>0 {
// have to use symbol as senderCompID if quoting multiple symbols since multiple connections are used
Expand Down
15 changes: 15 additions & 0 deletions pkg/common/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type Properties interface {
GetString(key string, def string) string
SetString(key string, value string)
GetBytes(key string, def int) int
Clone() Properties
}

Expand All @@ -34,6 +35,20 @@ func (p properties) SetString(key string, value string) {
p.props[key] = value
}

func (p properties) GetBytes(key string, def int) int {
key = strings.TrimSpace(key)
v, ok := p.props[key]
if !ok {
return def
}
v = strings.ToUpper(v)
if strings.HasSuffix(v,"M") {
return ParseInt(v[:len(v)-1]) * 1024 * 1024
}
return ParseInt(v)
}


func (p properties) Clone() Properties {
return properties{props: maps.Clone(p.props)}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/marketdata/marketdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func StartMarketDataReceiver(c ExchangeConnector, callback ConnectorCallback, pr
panic(err)
}
log.Println("listening for market data on", l.LocalAddr())
l.SetReadBuffer(16 * 1024 * 1024)
l.SetReadBuffer(props.GetBytes("marketdata_buffer",1024*1024))
b := make([]byte, protocol.MaxMsgSize)
for {
n, _, err := l.ReadFromUDP(b)
Expand Down

0 comments on commit 7ef7019

Please sign in to comment.