Example #1
0
        public async Task <WrappedResponse <TradeFee> > GetTradeFee(OrderSideEnum orderSide, ISymbol symbol)
        {
            var relativeUrl = "TradeVolume";

            var nvc = new NameValueCollection();

            nvc.Add("pair", $"{Exchange.GetCurrencyCode(symbol.BaseCurrencyCode)}{Exchange.GetCurrencyCode(symbol.QuoteCurrencyCode)}");
            nvc.Add("fee-info", "true");

            return(await InternalRequest <KrakenTradeVolume, TradeFee>(true, relativeUrl, HttpMethod.Post, nvc));
        }
Example #2
0
 public async Task <WrappedResponse <TradeFee> > GetTradeFee(OrderSideEnum orderSide, ISymbol symbol)
 {
     return(await Task.Run(() =>
     {
         return new WrappedResponse <TradeFee>
         {
             StatusCode = WrappedResponseStatusCode.Ok,
             Data = new TradeFee
             {
                 CurrencyCode = symbol.QuoteCurrencyCode,
                 Taker = 0.003m,
                 Maker = 0.0m
             }
         };
     }));
 }
        public async Task Add(OrderSideEnum orderSide)
        {
            using (var context = ContextFactory.CreateDbContext(null))
            {
                var entity = new OrderSideEntity
                {
                    OrderSideId = (int)orderSide,
                    Label       = orderSide.ToString()
                };

                if (await context.OrderSide.FindAsync(entity.OrderSideId) == null)
                {
                    await context.OrderSide.AddAsync(entity);

                    await context.SaveChangesAsync();
                }
            }
        }
Example #4
0
        /// <summary>
        /// Helper method to send orders
        /// </summary>
        /// <param name="point"></param>
        /// <param name="side"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        protected ITransactionOrderModel CreateOrder(IPointModel point, OrderSideEnum side, double size)
        {
            var gateway    = point.Account.Gateway;
            var instrument = point.Account.Instruments[_asset];
            var order      = new TransactionOrderModel
            {
                Size       = size,
                Side       = side,
                Instrument = instrument,
                Type       = OrderTypeEnum.Market
            };

            gateway.OrderSenderStream.OnNext(new TransactionMessage <ITransactionOrderModel>
            {
                Action = ActionEnum.Create,
                Next   = order
            });

            return(order);
        }
Example #5
0
        public async Task <WrappedResponse <CreateOrder> > CreateOrder(ISymbol symbol, OrderTypeEnum orderType, OrderSideEnum orderSide, decimal price, decimal volume)
        {
            var relativeUrl = "/orders";

            var request = new CoinbaseProCreateOrderRequest
            {
                Size      = volume,
                Price     = price,
                Side      = orderSide == OrderSideEnum.Buy ? "buy" : "sell",
                ProductId = Exchange.EncodeProductId(symbol),
                Type      = orderType == OrderTypeEnum.Market ? "market" : "limit"
            };

            return(await InternalRequest <CoinbaseProCreateOrderResponse, CreateOrder>(true, relativeUrl, HttpMethod.Post, request));
        }
Example #6
0
 public Task <WrappedResponse <CreateOrder> > CreateOrder(ISymbol symbol, OrderTypeEnum orderType, OrderSideEnum orderSide, decimal price, decimal volume)
 {
     throw new NotImplementedException();
 }
Example #7
0
        public async Task <WrappedResponse <CreateOrder> > CreateOrder(ISymbol symbol, OrderTypeEnum orderType, OrderSideEnum orderSide, decimal price, decimal volume)
        {
            var relativeUrl = "v3/order";

            var query = new NameValueCollection();

            query.Add("symbol", Exchange.GetSymbol(symbol));
            query.Add("side", orderSide.ToString().ToUpper());
            query.Add("type", orderType.ToString().ToUpper());
            query.Add("quantity", volume.ToString());

            if (orderType == OrderTypeEnum.Limit)
            {
                query.Add("price", price.ToString());
                query.Add("timeInForce", "GTC");
            }

            return(await InternalRequest <BinanceNewOrder, CreateOrder>(true, relativeUrl, HttpMethod.Post, query));
        }
Example #8
0
        public async Task <WrappedResponse <CreateOrder> > CreateOrder(ISymbol symbol, OrderTypeEnum orderType, OrderSideEnum orderSide, decimal price, decimal volume)
        {
            Exchange.EnsureSymbol(symbol);

            var relativeUrl = "AddOrder";

            var nvc = new NameValueCollection();

            nvc.Add("pair", $"{Exchange.GetCurrencyCode(symbol.BaseCurrencyCode)}{Exchange.GetCurrencyCode(symbol.QuoteCurrencyCode)}");
            nvc.Add("type", orderSide == OrderSideEnum.Buy ? "buy" : "sell");
            nvc.Add("ordertype", orderType == OrderTypeEnum.Market ? "market" : "limit");
            if (orderType == OrderTypeEnum.Limit)
            {
                nvc.Add("price", price.ToString());
            }
            nvc.Add("volume", volume.ToString());

            return(await InternalRequest <KrakenAddOrderResult, CreateOrder>(true, relativeUrl, HttpMethod.Post, nvc));
        }
Example #9
0
        public async Task <IDataResult <PostOrderModelData> > PostStopLimitOrderAsync(BinanceTrOptions options, string symbol, OrderSideEnum side, decimal origQuoteQty, decimal limitPrice, decimal stopPrice, CancellationToken ct = default)
        {
            try
            {
                var parameters = new Dictionary <string, string>
                {
                    { "symbol", symbol },
                    { "side", side.GetDisplayName() },
                    { "type", OrderTypeEnum.STOP_LOSS_LIMIT.GetDisplayName() },
                    { "quantity", origQuoteQty.ToString(CultureInfo.InvariantCulture) },
                    { "stopPrice", stopPrice.ToString(CultureInfo.InvariantCulture) },
                    { "price", limitPrice.ToString(CultureInfo.InvariantCulture) },
                };

                var result = await SendRequestAsync(HttpMethod.Post, "/open/v1/orders", options, parameters, ct).ConfigureAwait(false);

                var data = CheckResult(result);
                if (!BinanceTrHelper.IsJson(data))
                {
                    return(new ErrorDataResult <PostOrderModelData>(data));
                }

                var model = JsonSerializer.Deserialize <PostOrderModel>(result);
                return(new SuccessDataResult <PostOrderModelData>(model.Data, model.Msg, model.Code));
            }
            catch (Exception ex)
            {
                return(new ErrorDataResult <PostOrderModelData>(ex.Message));
            }
        }
Example #10
0
        /// <summary>
        /// Helper method to send orders
        /// </summary>
        /// <param name="point"></param>
        /// <param name="side"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        protected ITransactionOrderModel CreateOrder(IPointModel point, OrderSideEnum side, double size)
        {
            var gateway    = point.Account.Gateway;
            var instrument = point.Account.Instruments[_asset];
            var order      = new TransactionOrderModel
            {
                Size       = size,
                Side       = side,
                Instrument = instrument,
                Type       = OrderTypeEnum.Market
            };

            switch (side)
            {
            case OrderSideEnum.Buy:

                order.Orders.Add(new TransactionOrderModel
                {
                    Size       = size,
                    Side       = OrderSideEnum.Sell,
                    Type       = OrderTypeEnum.Limit,
                    Price      = point.Ask + 2,
                    Instrument = instrument,
                    Container  = order
                });

                order.Orders.Add(new TransactionOrderModel
                {
                    Size       = size,
                    Side       = OrderSideEnum.Sell,
                    Type       = OrderTypeEnum.Stop,
                    Price      = point.Bid - 2,
                    Instrument = instrument,
                    Container  = order
                });

                break;

            case OrderSideEnum.Sell:

                order.Orders.Add(new TransactionOrderModel
                {
                    Size       = size,
                    Side       = OrderSideEnum.Buy,
                    Type       = OrderTypeEnum.Stop,
                    Price      = point.Bid + 2,
                    Instrument = instrument,
                    Container  = order
                });

                order.Orders.Add(new TransactionOrderModel
                {
                    Size       = size,
                    Side       = OrderSideEnum.Buy,
                    Type       = OrderTypeEnum.Limit,
                    Price      = point.Ask - 2,
                    Instrument = instrument,
                    Container  = order
                });

                break;
            }

            gateway.OrderSenderStream.OnNext(new TransactionMessage <ITransactionOrderModel>
            {
                Action = ActionEnum.Create,
                Next   = order
            });

            _date = point.Time;

            return(order);
        }