Exemple #1
0
        public async Task <OrderDto> PlaceOrderAsync(Instrument instrument, double price, double quantity, TradeSide side, OrderType orderType)
        {
            if (!ExchangeConfig.SupportedInstruments.ContainsKey(instrument))
            {
                _logger.Log(LogLevel.Error, $"{ExchangeConfig.ExchangeName} does not support the {instrument} instrument");

                return(null);
            }

            if (!ExchangeConfig.SupportedOrderTypes.ContainsKey(orderType))
            {
                _logger.Log(LogLevel.Error, $"{ExchangeConfig.ExchangeName} does not support orders of type {orderType}");

                return(null);
            }

            IRequest request = null;
            var      ot      = ExchangeConfig.SupportedOrderTypes[orderType];

            switch (orderType)
            {
            case OrderType.Market:
                request = new PlaceMarketOrderRequest
                {
                    Symbol    = _exchangeApi.ToSymbol(instrument),
                    OrderQty  = quantity,
                    Side      = side.ToString(),
                    OrderType = ot
                };
                break;

            case OrderType.Limit:
                request = new PlaceLimitOrderRequest
                {
                    Symbol    = _exchangeApi.ToSymbol(instrument),
                    OrderQty  = quantity,
                    Side      = side.ToString(),
                    Price     = price,
                    OrderType = ot
                };
                break;

            case OrderType.LimitMarket:
                break;

            case OrderType.Stop:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(orderType), orderType, null);
            }

            var channelPath = ExchangeConfig.SupportedRestChannels[ExchangeChannel.Order];

            return(await _exchangeApi.PostAsync <OrderDto, OrderResponse>(channelPath, request));
        }