Exemplo n.º 1
0
        private static OrderSide GetOrderSide(CommonOrderSide side)
        {
            if (side == CommonOrderSide.Sell)
            {
                return(OrderSide.Sell);
            }
            if (side == CommonOrderSide.Buy)
            {
                return(OrderSide.Buy);
            }

            throw new ArgumentException("Unsupported order side for Bitfinex order: " + side);
        }
Exemplo n.º 2
0
        async Task <WebCallResult <OrderId> > ISpotClient.PlaceOrderAsync(string symbol, CommonOrderSide side, CommonOrderType type, decimal quantity, decimal?price, string?accountId, string?clientOrderId, CancellationToken ct)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException(nameof(symbol) + " required for Bitfinex " + nameof(ISpotClient.PlaceOrderAsync), nameof(symbol));
            }

            int?clientId = null;

            if (clientOrderId != null)
            {
                if (!int.TryParse(clientOrderId, out var id))
                {
                    throw new ArgumentException("ClientOrderId for Bitfinex should be parsable to int");
                }
                else
                {
                    clientId = id;
                }
            }

            var result = await Trading.PlaceOrderAsync(symbol, GetOrderSide(side), GetOrderType(type), quantity, price ?? 0, clientOrderId : clientId, ct : ct).ConfigureAwait(false);

            if (!result)
            {
                return(result.As <OrderId>(null));
            }

            return(result.As(new OrderId
            {
                SourceObject = result.Data,
                Id = result.Data.Id.ToString(CultureInfo.InvariantCulture)
            }));
        }
Exemplo n.º 3
0
        async Task <WebCallResult <OrderId> > ISpotClient.PlaceOrderAsync(string symbol, CommonOrderSide side, CommonOrderType type, decimal quantity, decimal?price, string?accountId, string?clientOrderId, CancellationToken ct)
        {
            if (price == null && type == CommonOrderType.Limit)
            {
                throw new ArgumentException("Price parameter null while placing a limit order", nameof(price));
            }

            if (string.IsNullOrEmpty(symbol))
            {
                throw new ArgumentException(nameof(symbol) + " required for CoinEx " + nameof(ISpotClient.PlaceOrderAsync), nameof(symbol));
            }

            var result = await Trading.PlaceOrderAsync(
                symbol,
                side == CommonOrderSide.Sell?OrderSide.Sell : OrderSide.Buy,
                type == CommonOrderType.Limit?OrderType.Limit : OrderType.Market,
                quantity,
                price,
                clientOrderId : clientOrderId,
                ct : ct).ConfigureAwait(false);

            if (!result)
            {
                return(result.As <OrderId>(null));
            }

            return(result.As(new OrderId {
                SourceObject = result.Data, Id = result.Data.Id.ToString(CultureInfo.InvariantCulture)
            }));
        }