orderbook for trading match engine 交易撮合引擎订单簿
go get github.com/san-pang/orderbook
import github.com/san-pang/orderbook
buyorder := newMyOrder("010", "ord1", decimal.NewFromFloat(12.34), decimal.NewFromInt(300), SIDE_BUY)
sellorder := newMyOrder("030", "ord3", decimal.NewFromFloat(12.36), decimal.NewFromInt(500), SIDE_SELL)
orderbook := NewOrderBook("000776")
// add order
if err := orderbook.AddOrder(buyorder.GetSide(), buyorder); err != nil {
fmt.Println("add order failed:", err)
}
if err := orderbook.AddOrder(sellorder.GetSide(), sellorder); err != nil {
fmt.Println("add order failed:", err)
}
// cancel order
if err := orderbook.CancelOrder(buyorder.GetSide(), buyorder.GetClOrdID()); err != nil {
fmt.Println("cancel order failed:", err)
}
// update order
replaceOrder := *sellorder
replaceOrder.Qty = decimal.NewFromInt(1100)
if err := orderbook.UpdateOrder(replaceOrder.GetSide(), sellorder, &replaceOrder); err != nil {
fmt.Println("update order failed:", err)
}
more examples can be found in test file.