Пример #1
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "id", context.RemoteGroupId }
            };

            var rRaw = await api.GetOrderInfoAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var order = rRaw.GetContent();

            var isOpen = order.state.IndexOf("wait", StringComparison.OrdinalIgnoreCase) >= 0;
            var isBuy  = order.side.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            // TODO: AY: Sean - check schema during real money testing.
            return(new TradeOrderStatusResponse(Network, order.id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Rate = order.price
                }
            });
        }
        public virtual async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProviderPrivate.GetApi(context);

            var body = CreatePostBody();

            body.Add("method", ApiMethodsConfig[ApiMethodNamesTiLiWe.OrderInfo]);
            body.Add("order_id", context.RemoteGroupId);

            var r = await api.GetOrderInfoAsync(body).ConfigureAwait(false);

            CheckResponse(r);

            if (r.return_.Count == 0 || !r.return_.TryGetValue(context.RemoteGroupId, out var order))
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy = order.type.Equals("buy", StringComparison.OrdinalIgnoreCase);

            return(new TradeOrderStatusResponse(Network, context.RemoteGroupId, isBuy, order.status == 0, order.status == 2 || order.status == 3)
            {
                TradeOrderStatus =
                {
                    Market        = order.pair.ToAssetPair(this),
                    Rate          = order.rate,
                    AmountInitial = order.amount
                }
            });
        }
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rRaw = await api.QueryOrdersAsync().ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var order = r.FirstOrDefault(x => x.Code.Equals(context.RemoteGroupId));

            if (order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy = order.Type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.Code, isBuy, true, false)
            {
                TradeOrderStatus =
                {
                    Rate          = order.LimitPrice,
                    AmountInitial = order.OriginalAmount,
                    Market        = $"{order.ListingCurrency}_{order.ReferenceCurrency}".ToUpper().ToAssetPair(this)
                }
            });
        }
Пример #4
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rRaw = await api.GetOrdersAsync(filter : $"{{\"orderID\": \"{context.RemoteGroupId}\"}}").ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var rOrders = rRaw.GetContent();

            var rOrder = rOrders.FirstOrDefault(x => x.orderID.Equals(context.RemoteGroupId, StringComparison.Ordinal));

            if (rOrder == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isOpen = rOrder.ordStatus.Equals("new", StringComparison.OrdinalIgnoreCase);// rOpenOrders.Exists(x => x.orderID.Equals(context.RemoteGroupId, StringComparison.Ordinal));

            var order = ParseTradeOrderStatus(rOrder);

            order.IsOpen = isOpen;

            return(new TradeOrderStatusResponse(order));
        }
Пример #5
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rOrdersRaw = await api.QueryOrdersAsync().ConfigureAwait(false);

            CheckResponseErrors(rOrdersRaw);

            var rOrders = rOrdersRaw.GetContent();

            //TODO - SC - Documentation does not specify response example, so this is just an assumption
            var order = rOrders.data.FirstOrDefault(x => x.id.Equals(context.RemoteGroupId));

            if (order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy  = order.type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;
            var isOpen = order.status.IndexOf("active", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Rate          = order.rate,
                    AmountInitial = order.amount
                }
            });
        }
Пример #6
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "MsgType", "U4" },
                { "OrdersReqID", 1 }
            };

            var rActiveOrdersRaw = await api.QueryActiveOrdersAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rActiveOrdersRaw);

            var rActiveOrders = rActiveOrdersRaw.GetContent();

            var activeOrder = rActiveOrders.OrdListGrp?.FirstOrDefault(x => x.OrderID.Equals(context.RemoteGroupId));

            if (activeOrder == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy = activeOrder.Side == 1;

            return(new TradeOrderStatusResponse(Network, activeOrder.OrderID, isBuy, true, false)
            {
                TradeOrderStatus =
                {
                    Rate   = activeOrder.Price,
                    Market = activeOrder.Symbol.ToAssetPair(this)
                }
            });
        }
Пример #7
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rRaw = await api.QueryOrderAsync(context.RemoteGroupId).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            if (r == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isOpen = r.Status.IndexOf("New", StringComparison.OrdinalIgnoreCase) >= 0;
            var isBuy  = r.Side.IndexOf("Buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, r.Id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Rate            = r.Price,
                    AmountInitial   = r.InitialAmount,
                    AmountRemaining = r.RemainingAmount,
                    Market          = r.Symbol
                }
            });
        }
Пример #8
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = CreateBody();

            body.Add("command", "open_orders");
            body.Add("market", context.Market.ToTicker(this).ToLower());

            var rActiveOrdersRaw = await api.QueryActiveOrdersAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rActiveOrdersRaw);

            var rActiveOrders = rActiveOrdersRaw.GetContent();

            var activeOrder = rActiveOrders.order_open.FirstOrDefault(x => x.order_number.Equals(context.RemoteGroupId));

            if (activeOrder == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy = activeOrder.type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, activeOrder.order_number, isBuy, true, false)
            {
                TradeOrderStatus =
                {
                    Rate          = activeOrder.price,
                    AmountInitial = activeOrder.amount,
                    Market        = activeOrder.market.ToAssetPair(this)
                }
            });
        }
Пример #9
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "orderNumber", context.RemoteGroupId },
                { "currencyPair", context.Market.ToTicker(this) }
            };

            var rRaw = await api.QueryOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            if (r?.order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy  = r.order.type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;
            var isOpen = r.order.status.IndexOf("open", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, r.order.id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Rate            = r.order.rate,
                    AmountInitial   = r.order.initial_amount,
                    AmountRemaining = r.order.amount
                }
            });
        }
Пример #10
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            if (!context.HasMarket)
            {
                throw new MarketNotSpecifiedException(this);
            }

            var api = ApiProvider.GetApi(context);

            var rRaw = await api.QueryOrderAsync(context.RemoteGroupId).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var order = rRaw.GetContent();

            if (order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy  = order.side.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;
            var isOpen = order.state.IndexOf("wait", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Rate            = order.price,
                    Market          = order.market,
                    AmountRemaining = order.remaining_volume,
                    AmountInitial   = order.remaining_volume - order.executed_volume
                }
            });
        }
Пример #11
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            if (!context.HasMarket)
            {
                throw new MarketNotSpecifiedException(this);
            }

            var api = ApiProvider.GetApi(context);

            if (!long.TryParse(context.RemoteGroupId, out var orderId))
            {
                throw new ApiResponseException("Incorrect order ID specified - must be a number", this);
            }

            var rRaw = await api.QueryOrderAsync(context.Market.ToTicker(this), orderId).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var isCancelRequested = r.status.Equals("pending_cancel", StringComparison.OrdinalIgnoreCase);
            var isOpen            = r.status.Equals("new", StringComparison.OrdinalIgnoreCase);

            var isBuy = r.side.Equals("buy", StringComparison.OrdinalIgnoreCase);

            return(new TradeOrderStatusResponse(Network, r.orderId.ToString(), isBuy, isOpen, isCancelRequested)
            {
                TradeOrderStatus =
                {
                    Rate            = r.price,
                    AmountInitial   = r.origQty,
                    AmountRemaining = r.origQty - r.executedQty
                }
            });
        }
Пример #12
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProviderPrivate.GetApi(context);

            var order = await GetOrderReponseByIdAsync(context).ConfigureAwait(false);

            var bodyActiveOrders = CreateBody();

            bodyActiveOrders.Add("method", "ActiveOrders");
            bodyActiveOrders.Add("pair", order.pair);

            // Checks if this order is contained in active list.
            var rActiveOrdersRaw = await api.QueryActiveOrdersAsync(bodyActiveOrders).ConfigureAwait(false);

            CheckResponseErrors(rActiveOrdersRaw);

            var activeOrders = rActiveOrdersRaw.GetContent().returnData;
            // If the active list contains this order and the request for active orders was successful, then it is active. Otherwise it is not active.
            var isOpen = activeOrders.ContainsKey(context.RemoteGroupId);

            var isBuy = order.type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, context.RemoteGroupId, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Market        = order.pair.ToAssetPair(this),
                    Rate          = order.rate,
                    AmountInitial = order.start_amount
                }
            });
        }
Пример #13
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            if (!long.TryParse(context.RemoteGroupId, out var remoteId))
            {
                throw new ApiBaseException("Order remote id should be of a number type", this);
            }

            var body = new BitfinexSchema.OrderStatusRequest.Descriptor()
            {
                order_id = remoteId
            };

            var rRaw = await api.GetOrderStatusAsync(body).ConfigureAwait(false);

            CheckBitfinexResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var isBuy = r.side.Equals("buy", StringComparison.OrdinalIgnoreCase);

            return(new TradeOrderStatusResponse(Network, r.id.ToString(), isBuy, r.is_live, r.is_cancelled)
            {
                TradeOrderStatus =
                {
                    Market          = r.symbol.ToAssetPair(this,                                                                         3),
                    Rate            = r.type.Equals("exchange limit", StringComparison.OrdinalIgnoreCase) ? r.price : r.avg_execution_price,
                    AmountInitial   = r.original_amount,
                    AmountRemaining = r.remaining_amount
                }
            });
        }
Пример #14
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rActiveOrdersRaw = await api.QueryActiveOrdersAsync().ConfigureAwait(false);

            CheckResponseErrors(rActiveOrdersRaw);

            var rActiveOrders = rActiveOrdersRaw.GetContent();

            var activeOrder = rActiveOrders.data.FirstOrDefault(x => x.id.Equals(context.RemoteGroupId));

            if (activeOrder == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy = activeOrder.type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, activeOrder.id, isBuy, true, false)
            {
                TradeOrderStatus =
                {
                    Rate          = activeOrder.price,
                    AmountInitial = activeOrder.amount,
                    Market        = activeOrder.trade_pair.ToAssetPair(this, '/')
                }
            });
        }
Пример #15
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rRaw = await api.GetAccountOrder(context.RemoteGroupId).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var order = r.result;

            var isBuy = order.Type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.OrderUuid, isBuy, order.IsOpen, order.CancelInitiated)
            {
                TradeOrderStatus =
                {
                    Market          = order.Exchange.ToAssetPair(this),
                    Rate            = order.Limit,
                    AmountInitial   = order.Quantity,
                    AmountRemaining = order.QuantityRemaining
                }
            });
        }
Пример #16
0
        private void GetTradeOrderStatusTest(IOrderLimitProvider provider, string remoteOrderId, AssetPair market = null)
        {
            var context = new RemoteMarketIdContext(UserContext.Testing, remoteOrderId, market);

            var r = AsyncContext.Run(() => provider.GetOrderStatusAsync(context)).TradeOrderStatus;

            Assert.True(remoteOrderId.Equals(r.RemoteOrderId, StringComparison.Ordinal), "Remote trade order ids don't match");

            DisplayOrderStatusInfo(r, market);
        }
Пример #17
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var openOrders = await GetOpenOrdersAsync(context).ConfigureAwait(false);

            var order = openOrders.FirstOrDefault(x => x.RemoteOrderId.Equals(context.RemoteGroupId));

            decimal?  amountInitial;
            decimal?  amountRemaining;
            decimal?  rate;
            AssetPair market;

            var isOpen = true;
            var isBuy  = false;

            if (order != null)
            {
                amountInitial   = order.AmountInitial;
                amountRemaining = order.AmountRemaining;
                rate            = order.Rate;
                isBuy           = order.IsBuy;
                market          = order.Market;
            }
            else
            {
                var tradeHistory = await GetTradeHistoryAsync(context).ConfigureAwait(false);

                var trade = tradeHistory.FirstOrDefault(x => x.RemoteOrderId.Equals(context.RemoteGroupId));

                if (trade == null)
                {
                    throw new NoTradeOrderException(context, this);
                }

                amountInitial   = trade.AmountInitial;
                amountRemaining = trade.AmountRemaining;
                rate            = trade.Rate;
                isBuy           = trade.IsBuy;

                isOpen = false;
                market = trade.Market;
            }

            return(new TradeOrderStatusResponse(Network, context.RemoteGroupId, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Market          = market,
                    Rate            = rate,
                    AmountInitial   = amountInitial,
                    AmountRemaining = amountRemaining
                }
            });
        }
Пример #18
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rAccountId = await GetFirstAccountId(context).ConfigureAwait(false);

            var accountId = rAccountId.Result;

            var apiHits = rAccountId.ApiHitsCount;

            var rBuyRaw = await api.ShowBuyOrder(accountId, context.RemoteGroupId).ConfigureAwait(false);

            CoinbaseSchema.ShowOrderResponse order = null;
            apiHits++;

            if (rBuyRaw.ResponseMessage.StatusCode == HttpStatusCode.NotFound)
            {
                var rSellRaw = await api.ShowSellOrder(accountId, context.RemoteGroupId).ConfigureAwait(false);

                apiHits++;

                CheckResponseErrors(rSellRaw);

                order = rSellRaw.GetContent();
            }
            else if (rBuyRaw.ResponseMessage.IsSuccessStatusCode)
            {
                CheckResponseErrors(rBuyRaw);

                order = rBuyRaw.GetContent();
            }

            if (order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy  = order.data.resource.Equals("buy", StringComparison.OrdinalIgnoreCase);
            var isOpen = order.data.status.Equals("created", StringComparison.OrdinalIgnoreCase);

            return(new TradeOrderStatusResponse(Network, order.data.id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    AmountInitial = order.data.amount.amount,
                    Market        = new AssetPair(order.data.amount.currency,order.data.total.currency,this),
                    Rate          = order.data.subtotal.amount / order.data.amount.amount
                },
                ApiHitsCount = apiHits
            });
        }
Пример #19
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var order = await GetOrderResponseByOrderId(context).ConfigureAwait(false);

            var isOpen = order.status.Equals("active", StringComparison.OrdinalIgnoreCase);

            var isBuy = order.type.IndexOf("bid", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.order_id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Market        = new AssetPair(order.order_currency, order.payment_currency, this),
                    Rate          = order.current_price,
                    AmountInitial = order.start_price
                }
            });
        }
Пример #20
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var historyOrders = (await GetOrdersHistory(context).ConfigureAwait(false)).ToList();
            var openOrders    = (await GetOpenOrders(context).ConfigureAwait(false)).ToList();

            var allOrders = historyOrders.Concat(openOrders);

            var order = allOrders.FirstOrDefault(x => x.RemoteOrderId.Equals(context.RemoteGroupId));

            if (order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            return(new TradeOrderStatusResponse(order)
            {
                ApiHitsCount = 2
            });
        }
Пример #21
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            if (!context.HasMarket)
            {
                throw new MarketNotSpecifiedException(this);
            }

            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>()
            {
                { "currencyPair", context.Market }
            };

            var rRaw = await api.QueryOrdersAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var order = r.data.FirstOrDefault(x => x.id.Equals(context.RemoteGroupId));

            if (order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isOpen = order.status.IndexOf("open", StringComparison.OrdinalIgnoreCase) >= 0;
            var isBuy  = order.type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Rate            = order.price,
                    AmountInitial   = order.originalAmount,
                    AmountRemaining = order.remainingAmount,
                    Market          = context.Market
                }
            });
        }
Пример #22
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            if (!context.HasMarket)
            {
                throw new MarketNotSpecifiedException(this);
            }

            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "order_id", context.RemoteGroupId }
            };

            var rRaw = await api.QueryOrderAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var orderResponse = rRaw.GetContent();

            if (orderResponse == null || orderResponse.result.Length == 0)
            {
                throw new NoTradeOrderException(context, this);
            }

            var order = orderResponse.result[0];

            var isBuy = order.side.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.id, isBuy, !order.is_closed, false)
            {
                TradeOrderStatus =
                {
                    Rate            = order.price,
                    Market          = order.pair,
                    AmountInitial   = order.original_amount,
                    AmountRemaining = order.remaining_amount
                }
            });
        }
Пример #23
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rActiveOrdersRaw = await api.QueryActiveOrdersAsync().ConfigureAwait(false);

            //CheckResponseErrors(rActiveOrdersRaw);

            var rActiveOrders = rActiveOrdersRaw.GetContent();

            ExmoSchema.OrderInfoResponse order = null;

            foreach (var orderPair in rActiveOrders)
            {
                order = orderPair.Value.FirstOrDefault(x => x.order_id.Equals(context.RemoteGroupId));

                if (order != null)
                {
                    break;
                }
            }

            if (order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isBuy = order.type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.order_id, isBuy, true, false)
            {
                TradeOrderStatus =
                {
                    Rate          = order.price,
                    AmountInitial = order.amount,
                    Market        = order.pair
                }
            });
        }
Пример #24
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var market = context.Market.ToTicker(this).ToLower();

            var api = ApiProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "symbol", market },
                { "order_id", context.RemoteGroupId }
            };

            var rRaw = await api.GetOrderInfoAsync(body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var rOrders = rRaw.GetContent();

            var order = rOrders.orders?.FirstOrDefault(x => x.order_id.Equals(context.RemoteGroupId));

            if (order == null)
            {
                throw new NoTradeOrderException(context, this);
            }

            var isOpen = order.status == 0 || order.status == 1; //status:  0 = unfilled, 1 = partially filled, 2 = fully filled, 10 = cancelled

            var isBuy = order.type.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;

            return(new TradeOrderStatusResponse(Network, order.order_id, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Rate          = order.price,
                    Market        = order.symbol.ToAssetPair(this),
                    AmountInitial = order.amount
                }
            });
        }
Пример #25
0
        private async Task <IEnumerable <TradeOrderStatus> > GetTradeHistoryAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var body = new CryptopiaSchema.GetTradeHistoryRequest
            {
                Count  = 1000,
                Market = context.Market.ToTicker(this, "/")
            };

            var rRaw = await api.GetTradeHistoryAsync(body).ConfigureAwait(false);

            CheckCryptopiaResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(r.Data.Select(x => new TradeOrderStatus(Network, x.TradeId.ToString(), x.Type.Equals("buy", StringComparison.OrdinalIgnoreCase), false, false)
            {
                Market = x.Market.ToAssetPair(this, '/'),
                Rate = x.Rate,
                AmountInitial = x.Amount
            }));
        }
Пример #26
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            var api = ApiProvider.GetApi(context);

            var rRaw = await api.GetActiveOrderInfoAsync(context.RemoteGroupId).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            var isOpen            = r.status.Equals("new", StringComparison.OrdinalIgnoreCase);
            var isCancelRequested = r.status.Equals("canceled", StringComparison.OrdinalIgnoreCase);

            var isBuy = r.side.Equals("buy", StringComparison.OrdinalIgnoreCase);

            return(new TradeOrderStatusResponse(Network, r.clientOrderId, isBuy, isOpen, isCancelRequested)
            {
                TradeOrderStatus =
                {
                    Rate          = r.price,
                    AmountInitial = r.quantity
                }
            });
        }
Пример #27
0
        public async Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
        {
            if (context.Market == null)
            {
                throw new MarketNotSpecifiedException(this);
            }

            var api = ApiProvider.GetApi(context);

            var ticker = context.Market.ToTicker(this);

            var rActiveOrdersRaw = await api.QueryActiveOrdersAsync(ticker).ConfigureAwait(false);

            CheckResponseErrors(rActiveOrdersRaw);

            var rActiveOrders = rActiveOrdersRaw.GetContent();

            var rDealtOrdersRaw = await api.QueryDealtOrdersAsync(ticker).ConfigureAwait(false);

            CheckResponseErrors(rDealtOrdersRaw);

            var rDealtOrders = rDealtOrdersRaw.GetContent();

            var activeOrderBuy  = rActiveOrders.data.BUY.FirstOrDefault(x => x.oid.Equals(context.RemoteGroupId));
            var activeOrderSell = rActiveOrders.data.SELL.FirstOrDefault(x => x.oid.Equals(context.RemoteGroupId));
            var dealtOrder      = rDealtOrders.data.datas.FirstOrDefault(x => x.orderOid.Equals(context.RemoteGroupId));

            var price         = 0m;
            var amountInitial = 0m;
            var isOpen        = true;
            var isBuy         = false;

            if (activeOrderBuy != null)
            {
                price = activeOrderBuy.price;
                isBuy = true;
            }
            else if (activeOrderSell != null)
            {
                price = activeOrderSell.price;
                isBuy = false;
            }
            else if (dealtOrder != null)
            {
                price  = dealtOrder.dealPrice;
                isOpen = false;
                isBuy  = dealtOrder.direction.IndexOf("buy", StringComparison.OrdinalIgnoreCase) >= 0;
            }
            else
            {
                throw new NoTradeOrderException(context, this);
            }

            return(new TradeOrderStatusResponse(Network, context.RemoteGroupId, isBuy, isOpen, false)
            {
                TradeOrderStatus =
                {
                    Rate          = price,
                    AmountInitial = amountInitial
                }
            });
        }
Пример #28
0
 public Task <TradeOrderStatusResponse> GetOrderStatusAsync(RemoteMarketIdContext context)
 {
     throw new NotImplementedException();
 }