private async Task OnMarketBestPairChanged(object sender, MarketBestPairChangedEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } // get current opened orders by token var openOrdersResponse = await GetOpenedOrdersAsync(Symbol); // cancel already opened orders (if necessary) if (openOrdersResponse != null) { await CancelOrdersAsync(openOrdersResponse); } // find new market position Quote q = MarketStrategy.Process(e.MarketBestPair); // if position found then create order if (q != null) { var newOrderRequest = new CreateOrderRequest { Symbol = Symbol, Quantity = Decimal.Round(q.Volume, decimals: MarketStrategy.Config.QuoteAssetPrecision), Price = Decimal.Round(q.Price, decimals: MarketStrategy.Config.PricePrecision), Side = q.Direction, Type = OrderType.Limit, TimeInForce = TimeInForce.GoodTillCancel, RecvWindow = (int)MarketStrategy.Config.ReceiveWindow.TotalMilliseconds }; var createOrderResponse = await CreateOrderAsync(newOrderRequest); if (createOrderResponse != null) { Logger.Warn($"Limit order was created. Price: {createOrderResponse.Price}. Volume: {createOrderResponse.Quantity}"); } } }
private async Task OnMarketBestPairChanged(object sender, MarketBestPairChangedEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } // get current opened orders by token var openOrdersResponse = await GetOpenedOrdersAsync(Symbol); // cancel already opened orders (if necessary) await CancelOrdersAsync(openOrdersResponse); // find new market position Quote q = MarketStrategy.Process(e.MarketBestPair); // if position found then create order if (q != null) { var newOrderRequest = new CreateOrderRequest { Symbol = Symbol, Quantity = q.Volume, Price = q.Price, Side = q.Direction, Type = OrderType.Limit, TimeInForce = TimeInForce.GTC // 'Good Till Cancelled' marketStrategy }; await CreateOrderAsync(newOrderRequest); Logger.Info($"Limit order created. Price: {newOrderRequest.Price}. Volume: {newOrderRequest.Quantity}"); } Console.WriteLine(Environment.NewLine); // only for beauty console output purposes }