예제 #1
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
                }
            });
        }
예제 #2
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)
                }
            });
        }
예제 #3
0
        public async Task <bool> TestPrivateApiAsync(ApiPrivateTestContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

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

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(r.result);
        }
예제 #4
0
        public async Task <bool> TestPrivateApiAsync(ApiPrivateTestContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

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

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

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(r != null);
        }
예제 #5
0
        public async Task <WithdrawalPlacementResult> PlaceWithdrawalAsync(WithdrawalPlacementContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "currency", context.Amount.Asset.ShortCode },
                { "amount", context.Amount.ToDecimalValue() },
                { "address", context.Address.Address }
            };

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

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new WithdrawalPlacementResult());
        }
예제 #6
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "amount", context.Quantity.ToDecimalValue() },
                { "rate", context.Rate.ToDecimalValue() },
                { "currencyPair", context.Pair.ToTicker(this) }
            };

            var rRaw = await api.NewOrderAsync(context.IsBuy? "buy" : "sell", body).ConfigureAwait(false);

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(null));
        }
예제 #7
0
        public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context)
        {
            var api = ApiPrivateProvider.GetApi(context);

            var body = new Dictionary <string, object>
            {
                { "MsgType", "D" },
                { "ClOrdID", 1 },
                { "Symbol", context.Pair.ToTicker(this) },
                { "Side", context.IsBuy ? "1" : "2" },
                { "OrdType", "2" },
                { "Price", context.Rate.ToInt64(null) },
                { "OrderQty", context.Quantity.ToInt32(null) },
                { "BrokerID", 5 }
            };

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

            CheckResponseErrors(rRaw);

            var r = rRaw.GetContent();

            return(new PlacedOrderLimitResponse(r.OrderID));
        }