respond automatically to quote requests
This commit is contained in:
@ -17,6 +17,7 @@ type application struct {
|
|||||||
onLogon func(quickfix.SessionID)
|
onLogon func(quickfix.SessionID)
|
||||||
onLogout func(quickfix.SessionID)
|
onLogout func(quickfix.SessionID)
|
||||||
onQuote func(quote.Quote, quickfix.SessionID)
|
onQuote func(quote.Quote, quickfix.SessionID)
|
||||||
|
onQuoteRequest func(quoterequest.QuoteRequest, quickfix.SessionID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApplication(n domain.Notifier) *application {
|
func newApplication(n domain.Notifier) *application {
|
||||||
@ -99,6 +100,10 @@ func (a *application) handleQuoteRequest(msg quoterequest.QuoteRequest, sessionI
|
|||||||
"session", sessionID.String(),
|
"session", sessionID.String(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if a.onQuoteRequest != nil {
|
||||||
|
a.onQuoteRequest(msg, sessionID)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import (
|
|||||||
"quantex.com/qfixdpl/quickfix/gen/enum"
|
"quantex.com/qfixdpl/quickfix/gen/enum"
|
||||||
"quantex.com/qfixdpl/quickfix/gen/field"
|
"quantex.com/qfixdpl/quickfix/gen/field"
|
||||||
"quantex.com/qfixdpl/quickfix/gen/fix50sp2/quote"
|
"quantex.com/qfixdpl/quickfix/gen/fix50sp2/quote"
|
||||||
|
"quantex.com/qfixdpl/quickfix/gen/fix50sp2/quoterequest"
|
||||||
"quantex.com/qfixdpl/quickfix/store/file"
|
"quantex.com/qfixdpl/quickfix/store/file"
|
||||||
"quantex.com/qfixdpl/src/app"
|
"quantex.com/qfixdpl/src/app"
|
||||||
"quantex.com/qfixdpl/src/common/tracerr"
|
"quantex.com/qfixdpl/src/common/tracerr"
|
||||||
@ -43,6 +44,7 @@ func (m *Manager) Start() error {
|
|||||||
fixApp := newApplication(m.notify)
|
fixApp := newApplication(m.notify)
|
||||||
fixApp.onLogon = m.onLogon
|
fixApp.onLogon = m.onLogon
|
||||||
fixApp.onLogout = m.onLogout
|
fixApp.onLogout = m.onLogout
|
||||||
|
fixApp.onQuoteRequest = m.handleQuoteRequest
|
||||||
m.app = fixApp
|
m.app = fixApp
|
||||||
|
|
||||||
f, err := os.Open(m.cfg.SettingsFile)
|
f, err := os.Open(m.cfg.SettingsFile)
|
||||||
@ -166,3 +168,27 @@ func (m *Manager) SendQuote(clOrdID, quoteID, symbol, currency string, bidPx, of
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleQuoteRequest auto-responds to an incoming QuoteRequest with a quote at price 99.6.
|
||||||
|
func (m *Manager) handleQuoteRequest(msg quoterequest.QuoteRequest, sessionID quickfix.SessionID) {
|
||||||
|
quoteReqID, err := msg.GetQuoteReqID()
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("handleQuoteRequest: missing QuoteReqID", "error", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var symbol, currency string
|
||||||
|
|
||||||
|
relatedSyms, relErr := msg.GetNoRelatedSym()
|
||||||
|
if relErr == nil && relatedSyms.Len() > 0 {
|
||||||
|
sym := relatedSyms.Get(0)
|
||||||
|
symbol, _ = sym.GetSymbol()
|
||||||
|
currency, _ = sym.GetCurrency()
|
||||||
|
}
|
||||||
|
|
||||||
|
price := decimal.NewFromFloat(99.6)
|
||||||
|
|
||||||
|
if sendErr := m.SendQuote(quoteReqID, quoteReqID, symbol, currency, price, price, decimal.Zero, decimal.Zero); sendErr != nil {
|
||||||
|
slog.Error("handleQuoteRequest: failed to send quote", "quoteReqID", quoteReqID, "error", sendErr.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user