本文整理匯總了Golang中github.com/fmstephe/matching_engine/matcher/pqueue.OrderNode類的典型用法代碼示例。如果您正苦於以下問題:Golang OrderNode類的具體用法?Golang OrderNode怎麽用?Golang OrderNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了OrderNode類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addBuy
func (m *M) addBuy(b *pqueue.OrderNode) {
if b.Price() == msg.MARKET_PRICE {
panic("It is illegal to send a buy at market price")
}
q := m.getMatchQueues(b.StockId())
if !m.fillableBuy(b, q) {
q.PushBuy(b)
}
}
示例2: cancel
func (m *M) cancel(o *pqueue.OrderNode) {
q := m.getMatchQueues(o.StockId())
ro := q.Cancel(o)
if ro != nil {
m.completeCancelled(ro)
m.slab.Free(ro)
} else {
m.completeNotCancelled(o)
}
m.slab.Free(o)
}
示例3: push
func (rm *refmatcher) push(o *pqueue.OrderNode) {
if o.Kind() == msg.BUY {
rm.matchQueues.PushBuy(o)
return
}
if o.Kind() == msg.SELL {
rm.matchQueues.PushSell(o)
return
}
panic("Unsupported trade kind pushed")
}
示例4: fillableBuy
func (m *M) fillableBuy(b *pqueue.OrderNode, q *pqueue.MatchQueues) bool {
for {
s := q.PeekSell()
if s == nil {
return false
}
if b.Price() >= s.Price() {
if b.Amount() > s.Amount() {
amount := s.Amount()
price := price(b.Price(), s.Price())
s.Remove()
m.slab.Free(s)
b.ReduceAmount(amount)
m.completeTrade(msg.PARTIAL, msg.FULL, b, s, price, amount)
continue // The sell has been used up
}
if s.Amount() > b.Amount() {
amount := b.Amount()
price := price(b.Price(), s.Price())
s.ReduceAmount(amount)
m.completeTrade(msg.FULL, msg.PARTIAL, b, s, price, amount)
m.slab.Free(b)
return true // The buy has been used up
}
if s.Amount() == b.Amount() {
amount := b.Amount()
price := price(b.Price(), s.Price())
m.completeTrade(msg.FULL, msg.FULL, b, s, price, amount)
s.Remove()
m.slab.Free(s)
m.slab.Free(b)
return true // The buy and sell have been used up
}
} else {
return false
}
}
}
示例5: addSell
func (m *M) addSell(s *pqueue.OrderNode) {
q := m.getMatchQueues(s.StockId())
if !m.fillableSell(s, q) {
q.PushSell(s)
}
}
示例6: completeNotCancelled
func (m *M) completeNotCancelled(nc *pqueue.OrderNode) {
ncm := msg.Message{}
nc.CopyTo(&ncm)
ncm.Kind = msg.NOT_CANCELLED
m.Out.Write(ncm)
}
示例7: completeCancelled
func (m *M) completeCancelled(c *pqueue.OrderNode) {
cm := msg.Message{}
c.CopyTo(&cm)
cm.Kind = msg.CANCELLED
m.Out.Write(cm)
}
示例8: completeTrade
func (m *M) completeTrade(brk, srk msg.MsgKind, b, s *pqueue.OrderNode, price, amount uint64) {
m.Out.Write(msg.Message{Kind: brk, Price: price, Amount: amount, TraderId: b.TraderId(), TradeId: b.TradeId(), StockId: b.StockId()})
m.Out.Write(msg.Message{Kind: srk, Price: price, Amount: amount, TraderId: s.TraderId(), TradeId: s.TradeId(), StockId: s.StockId()})
}
示例9: completeNotCancelled
func completeNotCancelled(out chan<- *msg.Message, nc *pqueue.OrderNode) {
ncm := &msg.Message{}
nc.CopyTo(ncm)
ncm.Kind = msg.NOT_CANCELLED
out <- ncm
}
示例10: completeCancelled
func completeCancelled(out chan<- *msg.Message, c *pqueue.OrderNode) {
cm := &msg.Message{}
c.CopyTo(cm)
cm.Kind = msg.CANCELLED
out <- cm
}
示例11: completeTrade
func completeTrade(out chan<- *msg.Message, brk, srk msg.MsgKind, b, s *pqueue.OrderNode, price uint64, amount uint32) {
br := &msg.Message{Kind: brk, Price: price, Amount: amount, TraderId: b.TraderId(), TradeId: b.TradeId(), StockId: b.StockId()}
sr := &msg.Message{Kind: srk, Price: price, Amount: amount, TraderId: s.TraderId(), TradeId: s.TradeId(), StockId: s.StockId()}
out <- br
out <- sr
}
示例12: fillableSell
func (m *M) fillableSell(s *pqueue.OrderNode, q *pqueue.MatchQueues) bool {
for {
b := q.PeekBuy()
if b == nil {
return false
}
if b.Price() >= s.Price() {
if b.Amount() > s.Amount() {
amount := s.Amount()
price := price(b.Price(), s.Price())
b.ReduceAmount(amount)
completeTrade(m.Out, msg.PARTIAL, msg.FULL, b, s, price, amount)
m.slab.Free(s)
return true // The sell has been used up
}
if s.Amount() > b.Amount() {
amount := b.Amount()
price := price(b.Price(), s.Price())
s.ReduceAmount(amount)
completeTrade(m.Out, msg.FULL, msg.PARTIAL, b, s, price, amount)
m.slab.Free(q.PopBuy())
continue
}
if s.Amount() == b.Amount() {
amount := b.Amount()
price := price(b.Price(), s.Price())
completeTrade(m.Out, msg.FULL, msg.FULL, b, s, price, amount)
m.slab.Free(q.PopBuy())
m.slab.Free(s)
return true // The sell has been used up
}
} else {
return false
}
}
panic("Unreachable")
}