Esempio n. 1
0
func DoTrade(order *ems.Order, quantity float64, price float64) {
	log.Println(fmt.Sprintf("fill %v: %v @ %v", order.OrderId, quantity, price))
	er.NewTradeExecution(order, quantity, price, "")

	if orac.IsCompleted(order) {
		UnRegisterOrder(order)
		OrderUpdateChan <- order
	}
}
Esempio n. 2
0
func (m *OrderBook) ProcessOrderBookUpdate(triggerQuote *marketdata.Quote) {
	bidQuotes, askQuotes := m.ConstrucOrderBookLinkedList()

	for _, order := range m.OrdersList {
		if orac.IsCompleted(order) {
			continue
		}

		var quotebands *QuoteBand
		if order.Side == ems.Side_BUY {
			quotebands = askQuotes
		} else {
			quotebands = bidQuotes
		}
		if quotebands == nil {
			continue
		}

		if order.OrderType == ems.OrderType_MARKET {
			for quotebands != nil && order.Quantity > order.FilledQuantity {
				fillQty := math.Min(quotebands.quantity, (order.Quantity - order.FilledQuantity))
				DoTrade(order, fillQty, quotebands.price)
				quotebands.quantity -= fillQty
				if quotebands.quantity == 0 {
					quotebands = quotebands.next
				}
			}
		}
		if triggerQuote.LastPrice == nil {
			continue
		}
		if order.OrderType == ems.OrderType_LIMIT {
			for quotebands != nil && order.Quantity > order.FilledQuantity {
				if order.Side == ems.Side_BUY {
					if order.LimitPrice < quotebands.price {
						break
					}
				} else {
					if order.LimitPrice > quotebands.price {
						break
					}
				}
				fillQty := math.Min(quotebands.quantity, (order.Quantity - order.FilledQuantity))
				DoTrade(order, fillQty, quotebands.price)
				quotebands.quantity -= fillQty
				if quotebands.quantity == 0 {
					quotebands = quotebands.next
				}
			}
		}
	}
}