Exemplo n.º 1
0
        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}");
                }
            }
        }
Exemplo n.º 2
0
        public override async Task <BinancePlacedOrder> CreateOrderAsync(CreateOrderRequest order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            #if TEST_ORDER_CREATION_MODE
            WebCallResult <BinancePlacedOrder> response = await _binanceRestClient.Spot.Order.PlaceTestOrderAsync(
                symbol : order.Symbol,
                side : order.Side,
                type : order.Type,
                price : order.Price,
                quantity : order.Quantity,
                timeInForce : order.TimeInForce,
                newClientOrderId : order.NewClientOrderId,
                receiveWindow : order.RecvWindow)
                                                          .ConfigureAwait(false);
            #else
            WebCallResult <BinancePlacedOrder> response = await _binanceRestClient.Spot.Order.PlaceOrderAsync(
                symbol : order.Symbol,
                side : order.Side,
                type : order.Type,
                price : order.Price,
                quantity : order.Quantity,
                timeInForce : order.TimeInForce,
                newClientOrderId : order.NewClientOrderId,
                receiveWindow : order.RecvWindow)
                                                          .ConfigureAwait(false);
            #endif

            if (response.Error != null)
            {
                Logger.Error(response.Error.Message);
            }

            return(response.Data);
        }
Exemplo n.º 3
0
        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
        }
Exemplo n.º 4
0
 public abstract Task <BinancePlacedOrder> CreateOrderAsync(CreateOrderRequest order);
Exemplo n.º 5
0
 public abstract Task <BaseCreateOrderResponse> CreateOrderAsync(CreateOrderRequest order);