Closed P9avel closed 1 year ago
This can be handled in ITradeListener implementation.
I am draw my idea ![Uploading 123.png…]()
It can be done in MatchingEngine, but to me it seems that having one call per trade is simple design and will be used most.
We may achieve this in ITradeListener implementation, below is sample code.
class MyTradeListener : ITradeListener
{
private OrderId? lastIncomingOrderId;
private List<Fill> fills = new();
public void OnAccept(OrderId orderId)
{
FlushCombinedTradeForIncomingOrder();
//Handle Accept;
}
public void OnCancel(OrderId orderId, Quantity remainingQuantity, Quantity cost, Quantity fee, CancelReason cancelReason)
{
FlushCombinedTradeForIncomingOrder();
//Handle Cancel;
}
public void OnOrderTriggered(OrderId orderId)
{
FlushCombinedTradeForIncomingOrder();
//Handle Trigger;
}
public void OnTrade(OrderId incomingOrderId, OrderId restingOrderId, Price matchPrice, Quantity matchQuantiy, Quantity? askRemainingQuantity, Quantity? askFee, Quantity? bidCost, Quantity? bidFee)
{
if (lastIncomingOrderId == incomingOrderId)
{
AddFills(incomingOrderId, restingOrderId, matchPrice, matchQuantiy, askRemainingQuantity, askFee, bidCost, bidFee);
}
else
{
FlushCombinedTradeForIncomingOrder();
AddFills(incomingOrderId, restingOrderId, matchPrice, matchQuantiy, askRemainingQuantity, askFee, bidCost, bidFee);
}
}
private void AddFills(OrderId incomingOrderId, OrderId restingOrderId, Price matchPrice, Quantity matchQuantiy, Quantity? askRemainingQuantity, Quantity? askFee, Quantity? bidCost, Quantity? bidFee)
{
fills.Add(new Fill
{
TakerOrderId = incomingOrderId,
MakerOrderId = restingOrderId,
//TODO Rest of the fields
});
lastIncomingOrderId = incomingOrderId;
}
private void FlushCombinedTradeForIncomingOrder()
{
//TODO process multiple fills for same orderId
fills.Clear();
lastIncomingOrderId = null;
}
}
Your thoughts?
Yes, i am understood you. But in case if (lastIncomingOrderId == incomingOrderId) i am always not recived last trade. For your code need wait new input Order for recive prior trade. And your code set delay between trading and reciveng trade info. My suggetion give last trades when filling complete. My idea in pseudo code
OnTrading(inputOrder);
while(true) { Onrade(inputOrder, completedOrder); }
OnTraded(inputOrder, IList
Advantages: 1) I am always recived all trades and last trade 2) I am recived trade info without delay
Hmm, if you are getting lots of order every seconds then for humans it would be hard to notice it. But If you are not getting that much orders then you set a delay/timer to trigger it if no fills received for 100ms then flush fills.
You are right. But i think my solution is simpler.....
I would wait and see if there is demand for combined fills API, then I would implement it.
Ok, no problem. please look again closed https://github.com/ArjunVachhani/order-matcher/issues/38
Hi, thank you for new release. In common case one incomingOrder can closed many restingOrder. I am planning to use NoSql dbms MongoDb and want to get trade with many mached orders. Possible can you to rewrite ITradeListener.OnTrade or add new event ITradeListener.OnTradeComplete for example?