/// <summary>
        /// cancel old orders and place the new ones
        /// </summary>
        private void DoActAsMarketMaker(Ticker ticker)
        {
            // cancel all the previous orders
            SendMassCancelRequest(ticker.Id);

            // place new orders
            var sides = new[] { OrderSide.Buy, OrderSide.Sell };

            foreach (var side in sides)
            {
                var sign      = side == OrderSide.Buy ? 1 : -1;
                var priceBase = priceMaker.GetFairPrice(ticker.Id, side, settings.PricingSets);
                for (var i = 0; i < settings.TradeSets.MarketLevelsCount; i++)
                {
                    var price        = priceBase + sign * i * ticker.PriceStep;
                    var priceRounded = ticker.RoundAndScalePrice(price);
                    var volume       = ticker.RoundAndScaleVolume(ticker.MinVolume * settings.TradeSets.MarketMakerOrderLots);
                    var req          = new OrderRequest
                    {
                        AutoCancel        = AutoCancel.ON,
                        OrderType         = OrderType.LIMIT,
                        TimeInForce       = TimeInForce.GTK,
                        ClearingAccountId = ClearingAccountId,
                        TraderAccountId   = AccountId,
                        Flags             = 0,
                        InstrumentId      = ticker.Id,
                        Comment           = "MM",
                        OrderSide         = side,
                        Price             = priceRounded,
                        Amount            = volume
                    };

                    SendNewOrderRequest(req);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// calculate price for an order being placed
        /// </summary>
        private void CalculateOrderPrice(Ticker ticker, OrderRequest req)
        {
            var marketPrice = priceMaker.GetFairPrice(ticker.Id, req.OrderSide, settings.PricingSets);

            req.Price = ticker.RoundAndScalePrice(marketPrice);
        }