changing to initiator
This commit is contained in:
@ -1,29 +1,26 @@
|
||||
// Package fix implements the QuickFIX acceptor application.
|
||||
// Package fix implements the QuickFIX initiator application.
|
||||
package fix
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"quantex.com/qfixdpl/quickfix"
|
||||
"quantex.com/qfixdpl/quickfix/gen/fix50sp2/newordersingle"
|
||||
"quantex.com/qfixdpl/src/domain"
|
||||
"quantex.com/qfixdpl/quickfix/gen/fix50sp2/quote"
|
||||
)
|
||||
|
||||
type application struct {
|
||||
router *quickfix.MessageRouter
|
||||
orderStore domain.OrderStore
|
||||
onLogon func(quickfix.SessionID)
|
||||
onLogout func(quickfix.SessionID)
|
||||
router *quickfix.MessageRouter
|
||||
onLogon func(quickfix.SessionID)
|
||||
onLogout func(quickfix.SessionID)
|
||||
onQuote func(quote.Quote, quickfix.SessionID)
|
||||
}
|
||||
|
||||
func newApplication(orderStore domain.OrderStore) *application {
|
||||
func newApplication() *application {
|
||||
app := &application{
|
||||
router: quickfix.NewMessageRouter(),
|
||||
orderStore: orderStore,
|
||||
router: quickfix.NewMessageRouter(),
|
||||
}
|
||||
|
||||
app.router.AddRoute(newordersingle.Route(app.handleNewOrderSingle))
|
||||
app.router.AddRoute(quote.Route(app.handleQuote))
|
||||
|
||||
return app
|
||||
}
|
||||
@ -33,14 +30,14 @@ func (a *application) OnCreate(sessionID quickfix.SessionID) {
|
||||
}
|
||||
|
||||
func (a *application) OnLogon(sessionID quickfix.SessionID) {
|
||||
slog.Info("FIX client logged on", "session", sessionID.String())
|
||||
slog.Info("FIX session logged on", "session", sessionID.String())
|
||||
if a.onLogon != nil {
|
||||
a.onLogon(sessionID)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *application) OnLogout(sessionID quickfix.SessionID) {
|
||||
slog.Info("FIX client logged out", "session", sessionID.String())
|
||||
slog.Info("FIX session logged out", "session", sessionID.String())
|
||||
if a.onLogout != nil {
|
||||
a.onLogout(sessionID)
|
||||
}
|
||||
@ -58,48 +55,19 @@ func (a *application) FromApp(msg *quickfix.Message, sessionID quickfix.SessionI
|
||||
return a.router.Route(msg, sessionID)
|
||||
}
|
||||
|
||||
func (a *application) handleNewOrderSingle(msg newordersingle.NewOrderSingle, sessionID quickfix.SessionID) quickfix.MessageRejectError {
|
||||
clOrdID, err := msg.GetClOrdID()
|
||||
func (a *application) handleQuote(msg quote.Quote, sessionID quickfix.SessionID) quickfix.MessageRejectError {
|
||||
quoteID, err := msg.GetQuoteID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
symbol, err := msg.GetSymbol()
|
||||
if err != nil {
|
||||
return err
|
||||
symbol, _ := msg.GetSymbol()
|
||||
|
||||
slog.Info("Quote received", "quoteID", quoteID, "symbol", symbol, "session", sessionID.String())
|
||||
|
||||
if a.onQuote != nil {
|
||||
a.onQuote(msg, sessionID)
|
||||
}
|
||||
|
||||
side, err := msg.GetSide()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ordType, err := msg.GetOrdType()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
orderQty, err := msg.GetOrderQty()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
price, _ := msg.GetPrice() // Price is optional for some OrdTypes
|
||||
|
||||
order := domain.Order{
|
||||
ClOrdID: clOrdID,
|
||||
Symbol: symbol,
|
||||
Side: string(side),
|
||||
OrdType: string(ordType),
|
||||
OrderQty: orderQty,
|
||||
Price: price,
|
||||
SessionID: sessionID.String(),
|
||||
ReceivedAt: time.Now(),
|
||||
}
|
||||
|
||||
a.orderStore.SaveOrder(order)
|
||||
|
||||
slog.Info("NewOrderSingle received", "clOrdID", clOrdID, "symbol", symbol, "side", order.Side)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user