// Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved. package gofix /* #cgo CFLAGS: -I./include #cgo LDFLAGS: -L/usr/lib #cgo linux LDFLAGS: -lboost_system -lquickfix -lufx_security -lcfix -pthread -lm #include #include extern void GoOnMdMessage(TickFull* tick, void* ctx); void OnMdMessage(TickFull* tick, void* ctx) { GoOnMdMessage(tick, ctx); } */ import "C" import ( "errors" "log" "unsafe" ) const MAX_BID_ASK_COUNT = 25 type FixTick struct { AskPrice [MAX_BID_ASK_COUNT]float64 BidPrice [MAX_BID_ASK_COUNT]float64 AskVolume [MAX_BID_ASK_COUNT]float64 BidVolume [MAX_BID_ASK_COUNT]float64 Symbol [8]byte Time int32 Millisecond int32 AskCount int32 BidCount int32 } func Symbol(symbol [8]byte) string { for i, v := range symbol { if v == 0 { return string(symbol[:i]) } } return string(symbol[:]) } type App struct { symbolMap map[string]string account, password string Ch chan *FixTick } func NewApp(symbolMap map[string]string, account, password string) *App { return &App{ symbolMap: symbolMap, account: account, password: password, Ch: make(chan *FixTick, 1024), } } func (app *App) Run(fname string) error { cacc := C.CString(app.account) defer C.free(unsafe.Pointer(cacc)) cpswd := C.CString(app.password) defer C.free(unsafe.Pointer(cpswd)) capp := C.CreateApp(cacc, cpswd) if capp == nil { return errors.New(" C.CreateApp() error") } for key, val := range app.symbolMap { csym := C.CString(key) cexchange := C.CString(val) C.AddSymbol(capp, csym, cexchange) C.free(unsafe.Pointer(csym)) C.free(unsafe.Pointer(cexchange)) } fn := C.fnOnMdMessage(C.OnMdMessage) C.Reg_OnMdMessage(capp, fn, unsafe.Pointer(app)) cfname := C.CString(fname) defer C.free(unsafe.Pointer(cfname)) C.AppRun(capp, cfname) return nil } func (app *App) onMdMessage(tick *FixTick) { log.Println("App.onMdMessage", string(tick.Symbol[:]), tick.Time) select { case app.Ch <- tick: default: } }