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