Example #1
0
        private ExecutionReport OrderToTrade(Order order)
        {
            var id             = order.Id;
            var execTime       = order.Timestamp;
            var orderPrice     = order.Price;
            var originalVolume = order.OriginalAmount;
            var tradeType      = BitfinexModelConverter.ConvertTradeType(order.TradeType);
            var status         = order.ConvertOrderStatus();

            return(new ExecutionReport(new Instrument(order.Symbol), execTime, orderPrice, originalVolume, order.ExecutedAmount, tradeType, id, status, order.OrderType, order.AvgExecutionPrice)
            {
                ExecType = ExecType.Trade,
                Success = true,
                FailureType = OrderStatusUpdateFailureType.None,
                RemainingVolume = order.RemainingAmount,
            });
        }
Example #2
0
        public override async Task <ExecutionReport> AddOrderAndWaitExecution(TradingSignal signal, TimeSpan timeout, long orderIdToReplace = 0)
        {
            var symbol    = _modelConverter.LykkeSymbolToExchangeSymbol(signal.Instrument.Name);
            var volume    = signal.Volume;
            var orderType = signal.IsMarginOrder ? _modelConverter.ConvertToMarginOrderType(signal.OrderType) : _modelConverter.ConvertToSpotOrderType(signal.OrderType);
            var tradeType = _modelConverter.ConvertTradeType(signal.TradeType);
            var price     = signal.Price == 0 ? 1 : signal.Price ?? 1;

            using (var cts = new CancellationTokenSource(timeout))
            {
                var newOrderRequest = new NewOrderRequest
                {
                    OrderIdToReplace = orderIdToReplace,
                    Symbol           = symbol,
                    Аmount           = volume,
                    Price            = price,
                    Side             = tradeType,
                    Type             = orderType
                };

                Order order;

                if (orderIdToReplace > 0)
                {
                    order = await ExecuteApiMethod(_exchangeApi.ReplaceOrderAsync, newOrderRequest, cts.Token);
                }
                else
                {
                    order = await ExecuteApiMethod(_exchangeApi.AddOrderAsync, newOrderRequest, cts.Token);
                }

                await _snapshotStorage.CreateNewEntity(_xApiKey, order);

                return(OrderToTrade(order));
            }
        }