Example #1
0
        private async Task SendClientOrder(Core.Model.OrderSide orderSide)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(selectedOrderType))
                {
                    throw new Exception("Order not valid: No order type.");
                }

                var clientOrder = new Core.Model.ClientOrder
                {
                    Symbol              = SelectedSymbol?.ExchangeSymbol,
                    Type                = SelectedOrderType.GetOrderType(),
                    Side                = orderSide,
                    Quantity            = Quantity,
                    Price               = Price,
                    StopPrice           = StopPrice,
                    BaseAccountBalance  = BaseAccountBalance?.GetCoreAccountBalance(),
                    QuoteAccountBalance = QuoteAccountBalance?.GetCoreAccountBalance()
                };

                SelectedSymbol.GetCoreSymbol().ValidateClientOrder(clientOrder);

                await ExchangeService.PlaceOrder(Account.AccountInfo.User.Exchange, Account.AccountInfo.User, clientOrder).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                OnException("TradeViewModel.SendClientOrder", e);
            }
        }
Example #2
0
        private async Task SendClientOrder(Core.Model.OrderSide orderSide)
        {
            try
            {
                var clientOrder = new Core.Model.ClientOrder
                {
                    Symbol              = SelectedSymbol?.ExchangeSymbol,
                    Type                = SelectedOrderType.GetOrderType(),
                    Side                = orderSide,
                    Quantity            = Quantity,
                    Price               = Price,
                    StopPrice           = StopPrice,
                    BaseAccountBalance  = BaseAccountBalance?.GetCoreAccountBalance(),
                    QuoteAccountBalance = QuoteAccountBalance?.GetCoreAccountBalance()
                };

                SelectedSymbol.GetCoreSymbol().ValidateClientOrder(clientOrder);

                await ExchangeService.PlaceOrder(Account.AccountInfo.User.Exchange, Account.AccountInfo.User, clientOrder).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                OnException($"{nameof(TradePanelViewModel)} - {ex.Message}", ex);
            }
        }
Example #3
0
        public async Task <Core.Model.Order> PlaceOrder(Core.Model.User user, Core.Model.ClientOrder clientOrder, long recWindow = 0, CancellationToken cancellationToken = default)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var binanceApi = new BinanceApi();

            using var apiUser = new BinanceApiUser(user.ApiKey, user.ApiSecret);
            var order  = OrderHelper.GetOrder(apiUser, clientOrder);
            var result = await binanceApi.PlaceAsync(order).ConfigureAwait(false);

            return(NewOrder(user, result));
        }
Example #4
0
        public static ClientOrder GetOrder(BinanceApiUser apiUser, Core.Model.ClientOrder clientOrder)
        {
            if (apiUser == null)
            {
                throw new ArgumentNullException(nameof(apiUser));
            }

            if (clientOrder == null)
            {
                throw new ArgumentNullException(nameof(clientOrder));
            }

            var orderType = (OrderType)clientOrder.Type;

            return(orderType switch
            {
                OrderType.Market => new MarketOrder(apiUser)
                {
                    Symbol = clientOrder.Symbol, Side = (OrderSide)clientOrder.Side, Quantity = clientOrder.Quantity
                },
                OrderType.StopLoss => new StopLossOrder(apiUser)
                {
                    Symbol = clientOrder.Symbol, Side = (OrderSide)clientOrder.Side, Quantity = clientOrder.Quantity, StopPrice = clientOrder.StopPrice
                },
                OrderType.TakeProfit => new TakeProfitOrder(apiUser)
                {
                    Symbol = clientOrder.Symbol, Side = (OrderSide)clientOrder.Side, Quantity = clientOrder.Quantity, StopPrice = clientOrder.StopPrice
                },
                OrderType.Limit => new LimitOrder(apiUser)
                {
                    Symbol = clientOrder.Symbol, Side = (OrderSide)clientOrder.Side, Quantity = clientOrder.Quantity, Price = clientOrder.Price
                },
                OrderType.LimitMaker => new LimitMakerOrder(apiUser)
                {
                    Symbol = clientOrder.Symbol, Side = (OrderSide)clientOrder.Side, Quantity = clientOrder.Quantity, Price = clientOrder.Price
                },
                OrderType.StopLossLimit => new StopLossLimitOrder(apiUser)
                {
                    Symbol = clientOrder.Symbol, Side = (OrderSide)clientOrder.Side, Quantity = clientOrder.Quantity, StopPrice = clientOrder.StopPrice, Price = clientOrder.Price
                },
                OrderType.TakeProfitLimit => new TakeProfitLimitOrder(apiUser)
                {
                    Symbol = clientOrder.Symbol, Side = (OrderSide)clientOrder.Side, Quantity = clientOrder.Quantity, StopPrice = clientOrder.StopPrice, Price = clientOrder.Price
                },
                _ => throw new ArgumentOutOfRangeException($"Order type not supported for {nameof(clientOrder)}"),
            });
Example #5
0
 public Task <Core.Model.Order> PlaceOrder(Exchange exchange, Core.Model.User user, Core.Model.ClientOrder clientOrder, long recWindow = 0, CancellationToken cancellationToken = default)
 {
     return(exchangeService.PlaceOrder(exchange, user, clientOrder, recWindow, cancellationToken));
 }