只接入撮合引擎
go get github.com/yzimhao/trading_engine/trading_core
var object *trading_core.TradePair
object = trading_core.NewTradePair("symbol", 2, 6)
uniq := fmt.Sprintf("a-%s", orderId)
createTime := time.Now().Unix()
item := trading_core.NewAskLimitItem(uniq, price, quantity, createTime)
object.PushNewOrder(item)
item = trading_core.NewAskMarketQtyItem(uniq, quantity, createTime)
object.PushNewOrder(item)
item = trading_core.NewAskMarketAmountItem(uniq, amount, maxQty, createTime)
object.PushNewOrder(item)
uniq := fmt.Sprintf("b-%s", orderId)
createTime := time.Now().Unix()
item := trading_core.NewBidLimitItem(uniq, price, quantity, createTime)
object.PushNewOrder(item)
item = trading_core.NewBidMarketQtyItem(uniq, quantity, maxAmount, createTime)
object.PushNewOrder(item)
item = trading_core.NewBidMarketAmountItem(uniq, amount, createTime)
object.PushNewOrder(item)
if strings.HasPrefix(orderId, "a-") {
object.CancelOrder(trading_core.OrderSideSell, uniq)
} else {
object.CancelOrder(trading_core.OrderSideBuy, uniq)
}
ask := object.GetAskDepth(10)
bid := object.GetBidDepth(10)
for {
select{
case tradelog := <-object.ChTradeResult:
...
case orderId := <- object.ChCancelResult:
...
default:
time.Sleep(time.Duration(50) * time.Millisecond)
}
}