// Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved. package saxocgo /* #cgo CFLAGS: -I./include #cgo LDFLAGS: -L./lib #cgo linux LDFLAGS: -L/usr/local/lib -lquickfix -lcfixsaxo -pthread -lm #include #include extern void GoOnSaxoMdMessage(TickFull* tick, void* ctx); void OnSaxoMdMessage(TickFull* tick, void* ctx) { GoOnSaxoMdMessage(tick, ctx); } */ import "C" import ( "errors" "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 { capp := C.SaxoCreateApp() if capp == nil { return errors.New("C.CreateApp() error") } for key, val := range app.symbolMap { cid := C.CString(key) csymbol := C.CString(val) C.SaxoAddSymbol(capp, cid, csymbol) C.free(unsafe.Pointer(cid)) C.free(unsafe.Pointer(csymbol)) } fn := C.fnSaxoOnMdMessage(C.OnSaxoMdMessage) C.SaxoReg_OnMdMessage(capp, fn, unsafe.Pointer(app)) cfname := C.CString(fname) defer C.free(unsafe.Pointer(cfname)) C.SaxoAppRun(capp, cfname) return nil } func (app *App) onMdMessage(tick *FixTick) { // log.Println("App.onMdMessage", tick) select { case app.Ch <- tick: default: } }