Beispiel #1
0
func main() {
	flag.Parse()

	cfg, err := os.Open(*fixconfig)
	if err != nil {
		log.Fatal(err)
	}

	appSettings, err := quickfix.ParseSettings(cfg)
	if err != nil {
		log.Fatal(err)
	}

	// logFactory, err := quickfix.NewFileLogFactory(appSettings)
	logFactory := quickfix.NewNullLogFactory()
	if err != nil {
		log.Fatal(err)
	}

	storeFactory := quickfix.NewMemoryStoreFactory()

	initiator, err := quickfix.NewInitiator(app, storeFactory, appSettings, logFactory)
	if err != nil {
		log.Fatal(err)
	}
	if err = initiator.Start(); err != nil {
		log.Fatal(err)
	}

	<-start

	for i := 0; i < *sampleSize; i++ {
		order := newordersingle.Message{}
		order.ClOrdID = "100"
		order.HandlInst = "1"
		order.Symbol = "TSLA"
		order.Side = enum.Side_BUY
		order.TransactTime = time.Now()
		order.OrdType = enum.OrdType_MARKET

		quickfix.SendToTarget(order, SessionID)
		// time.Sleep(1 * time.Millisecond)
	}

	time.Sleep(2 * time.Second)
}
Beispiel #2
0
func (e *Executor) OnFIX42NewOrderSingle(msg fix42nos.Message, sessionID quickfix.SessionID) (err quickfix.MessageRejectError) {
	symbol, err := msg.Symbol()
	if err != nil {
		return
	}

	side, err := msg.Side()
	if err != nil {
		return
	}

	orderQty, err := msg.OrderQty()
	if err != nil {
		return
	}

	ordType, err := msg.OrdType()
	if err != nil {
		return
	}

	if ordType.Value != enum.OrdType_LIMIT {
		err = quickfix.ValueIsIncorrect(ordType.Tag())
		return
	}

	price, err := msg.Price()
	if err != nil {
		return
	}

	clOrdID, err := msg.ClOrdID()
	if err != nil {
		return
	}

	execReport := fix42er.Builder(
		field.NewOrderID(e.genOrderID()),
		field.NewExecID(e.genExecID()),
		field.NewExecTransType(enum.ExecTransType_NEW),
		field.NewExecType(enum.ExecType_FILL),
		field.NewOrdStatus(enum.OrdStatus_FILLED),
		symbol,
		side,
		field.NewLeavesQty(0),
		field.NewCumQty(orderQty.Value),
		field.NewAvgPx(price.Value))

	execReport.Body().Set(clOrdID)
	execReport.Body().Set(orderQty)
	execReport.Body().Set(field.NewLastShares(orderQty.Value))
	execReport.Body().Set(field.NewLastPx(price.Value))

	if acct, err := msg.Account(); err != nil {
		execReport.Body().Set(acct)
	}

	quickfix.SendToTarget(execReport.MessageBuilder, sessionID)

	return
}