private bool FillWithBid(Order order, Bid bid)
{
if (order.Side != OrderSide.Sell)
return false;
while (true)
{
switch (order.Type)
{
case OrderType.Market:
case OrderType.Pegged:
Fill(order, bid.Price, bid.Size);
return true;
case OrderType.Stop:
if (bid.Price <= order.StopPx)
{
if (!FillAtStopPrice)
{
order.Type = OrderType.Market;
continue;
}
Fill(order, order.StopPx, bid.Size);
return true;
}
break;
case OrderType.Limit:
if (bid.Price >= order.Price)
{
Fill(order, FillAtLimitPrice ? order.Price : bid.Price, bid.Size);
return true;
}
return false;
case OrderType.StopLimit:
if (bid.Price <= order.StopPx)
{
order.Type = OrderType.Limit;
continue;
}
break;
}
break;
}
return false;
}