當前位置: 首頁>>代碼示例>>Golang>>正文


Golang pqueue.OrderNode類代碼示例

本文整理匯總了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)
	}
}
開發者ID:jmptrader,項目名稱:matching_engine,代碼行數:9,代碼來源:matcher.go

示例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)
}
開發者ID:jmptrader,項目名稱:matching_engine,代碼行數:11,代碼來源:matcher.go

示例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")
}
開發者ID:vdt,項目名稱:matching_engine,代碼行數:11,代碼來源:trefmatcher_test.go

示例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
		}
	}
}
開發者ID:jmptrader,項目名稱:matching_engine,代碼行數:38,代碼來源:matcher.go

示例5: addSell

func (m *M) addSell(s *pqueue.OrderNode) {
	q := m.getMatchQueues(s.StockId())
	if !m.fillableSell(s, q) {
		q.PushSell(s)
	}
}
開發者ID:jmptrader,項目名稱:matching_engine,代碼行數:6,代碼來源:matcher.go

示例6: completeNotCancelled

func (m *M) completeNotCancelled(nc *pqueue.OrderNode) {
	ncm := msg.Message{}
	nc.CopyTo(&ncm)
	ncm.Kind = msg.NOT_CANCELLED
	m.Out.Write(ncm)
}
開發者ID:jmptrader,項目名稱:matching_engine,代碼行數:6,代碼來源:matcher.go

示例7: completeCancelled

func (m *M) completeCancelled(c *pqueue.OrderNode) {
	cm := msg.Message{}
	c.CopyTo(&cm)
	cm.Kind = msg.CANCELLED
	m.Out.Write(cm)
}
開發者ID:jmptrader,項目名稱:matching_engine,代碼行數:6,代碼來源:matcher.go

示例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()})
}
開發者ID:jmptrader,項目名稱:matching_engine,代碼行數:4,代碼來源:matcher.go

示例9: completeNotCancelled

func completeNotCancelled(out chan<- *msg.Message, nc *pqueue.OrderNode) {
	ncm := &msg.Message{}
	nc.CopyTo(ncm)
	ncm.Kind = msg.NOT_CANCELLED
	out <- ncm
}
開發者ID:vdt,項目名稱:matching_engine,代碼行數:6,代碼來源:matcher.go

示例10: completeCancelled

func completeCancelled(out chan<- *msg.Message, c *pqueue.OrderNode) {
	cm := &msg.Message{}
	c.CopyTo(cm)
	cm.Kind = msg.CANCELLED
	out <- cm
}
開發者ID:vdt,項目名稱:matching_engine,代碼行數:6,代碼來源:matcher.go

示例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
}
開發者ID:vdt,項目名稱:matching_engine,代碼行數:6,代碼來源:matcher.go

示例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")
}
開發者ID:vdt,項目名稱:matching_engine,代碼行數:37,代碼來源:matcher.go


注:本文中的github.com/fmstephe/matching_engine/matcher/pqueue.OrderNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。