Quoting
Quoting algorithm allows you to control the position of the registered orders in the order book. The necessary of such functionality occurs when you need to quickly open and close positions at favorable prices. Also, due to the quick monitoring of the order book, the quoting allows to realize scalping tools for over small time frames.
Also, the quoting can emulate market orders on a exchanges, where the OrderTypes.Market type of orders is not supported.
Prerequisites
To implement the quoting the S# includes the QuotingStrategy class. This is the base abstract class for all derivative algorithms:
- MarketQuotingStrategy – this algorithm monitors the best quote (Security.BestBid for buy or Security.BestAsk for sell), registering its orders for the same price or a little better, depending on the MarketQuotingStrategy.PriceOffset value. Additionally, the MarketQuotingStrategy includes the MarketQuotingStrategy.PriceType, parameter, which controls the position of the order movement in spread: MarketPriceTypes.Following – the algorithm looks the best quote, MarketQuotingStrategy.PriceType, MarketPriceTypes.Middle – the algorithm will put the order in the middle of the spread. This parameter affects how soon the order will be matched.
- BestByVolumeQuotingStrategy – looks what total volume has a better price than quoted order and if it exceeds the permitted limit BestByVolumeQuotingStrategy.VolumeExchange, the order is moved to the edge of the spread.
- BestByPriceQuotingStrategy – looks how far the quoted order is from the best quote. If the tolerance interval BestByPriceQuotingStrategy.BestPriceOffset has been exceeded, the order is moved to the edge of the spread.
- LastTradeQuotingStrategy – is similar to the MarketQuotingStrategy except that it monitors not order book depth, but the last trade Security.LastTrade.
- LevelQuotingStrategy – quoting by the specified level in the order book.
- LimitQuotingStrategy – quoting by the limited price.
Quoting adding to the SampleSMA
It is necessary to enable the export of the order book before starting work, so the moving average algorithm described in the iteration model, section begin to work in association with the strategy:
if (!_isAaplOrderBookStarted) { _connector.SubscribeMarketDepth(aapl); _isAaplOrderBookStarted = true; }
It is necessary to replace the code in the SmaStrategy class from:
base.RegisterOrder(order);
to:
var strategy = new MarketQuotingStrategy(direction, volume); ChildStrategies.Add(strategy);