public async Task <bool> TestPrivateApiAsync(ApiPrivateTestContext context) { var api = ApiProviderPrivate.GetApi(context); var r = await api.GetUserInfoAsync().ConfigureAwait(false); return(r != null && r.success); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProviderPrivate.GetApi(context); var body = new Dictionary <string, object> { { "pair", context.Pair.ToTicker(this) }, { "type", context.IsBuy ? "buy" : "sell" }, { "amount", context.Quantity }, { "rate", context.Rate.ToDecimalValue() } }; var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); if (r.success == false) { throw new ApiResponseException("Unsuccessful request in PlaceOrderLimitAsync"); } return(new PlacedOrderLimitResponse(r.returnData.order_id)); }
public async Task <WithdrawalPlacementResult> PlaceWithdrawalAsync(WithdrawalPlacementContext context) { var api = ApiProviderPrivate.GetApi(context); if (context.HasDescription) { throw new ApiResponseException("Exchange does not support tags.", this); } var body = CreatePostBody(); body.Add("method", ApiMethodsConfig[ApiMethodNamesTiLiWe.WithdrawCoin]); body.Add("coinName", context.Amount.Asset.ShortCode); body.Add("amount", context.Amount.ToDecimalValue()); body.Add("address", context.Address.Address); var r = await api.WithdrawCoinAsync(body).ConfigureAwait(false); CheckResponse(r); return(new WithdrawalPlacementResult() { WithdrawalRemoteId = r.return_.tId.ToString() }); }
public virtual async Task <TradeOrderStatus> GetOrderStatusAsync(RemoteIdContext 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); } return(new TradeOrderStatus(context.RemoteGroupId, order.status == 0, order.status == 2 || order.status == 3) { Rate = order.rate, AmountInitial = order.start_amount, AmountRemaining = order.amount }); }
public async Task <OpenOrdersResponse> GetOpenOrdersAsync(OpenOrdersContext context) { var api = ApiProviderPrivate.GetApi(context); var body = CreatePostBody(); body.Add("method", ApiMethodsConfig[ApiMethodNamesTiLiWe.ActiveOrders]); if (context.HasMarket) { body.Add("pair", context.Market.ToTicker(this).ToLower()); } var r = await api.GetActiveOrders(body).ConfigureAwait(false); CheckResponse(r); var orders = new List <TradeOrderStatus>(); if (r.return_ != null) { foreach (var order in r.return_) { orders.Add(ParseTradeOrderStatus(order.Key, order.Value)); } } return(new OpenOrdersResponse(orders)); }
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 = 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 } }); }
public async Task <bool> TestPrivateApiAsync(ApiPrivateTestContext context) { var api = ApiProviderPrivate.GetApi(context); var rRaw = await api.GetBalanceAsync().ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(r != null && r.status.Equals("success")); }
public async Task <bool> TestPrivateApiAsync(ApiPrivateTestContext context) { var api = ApiProviderPrivate.GetApi(context); var body = CreateBody(); var rRaw = await api.GetBalancesAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(r != null && r.success == 1); }
public async Task <bool> TestPrivateApiAsync(ApiPrivateTestContext context) { var timeStamp = (long)(DateTime.UtcNow.ToUnixTimeStamp()); var body = new Dictionary <string, object> { { "method", "getInfo" }, { "nonce", timeStamp } }; var api = ApiProviderPrivate.GetApi(context); var r = await api.GetUserInfoAsync(body).ConfigureAwait(false); return(r != null && r.success); }
public virtual async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProviderPrivate.GetApi(context); var body = CreatePostBody(); body.Add("method", ApiMethodsConfig[ApiMethodNamesTiLiWe.Trade]); body.Add("pair", context.Pair.ToTicker(this).ToLower()); body.Add("type", context.IsBuy ? "buy" : "sell"); body.Add("rate", context.Rate.ToDecimalValue()); body.Add("amount", context.Quantity.ToDecimalValue()); var r = await api.TradeAsync(body).ConfigureAwait(false); CheckResponse(r); return(new PlacedOrderLimitResponse(r.return_.order_id.ToString())); }
public async Task <WithdrawalPlacementResult> PlaceWithdrawalAsync(WithdrawalPlacementContext context) { var api = ApiProviderPrivate.GetApi(context); var body = CreateBody(); body.Add("method", "WithdrawCoinsToAddress"); body.Add("coinName", context.Amount.Asset.ShortCode); body.Add("amount", context.Amount.ToDecimalValue()); body.Add("address", context.Address.Address); var rRaw = await api.SubmitWithdrawRequestAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); // No id is returned from exchange. return(new WithdrawalPlacementResult()); }
public async Task <TradeOrderStatus> GetOrderStatusAsync(RemoteIdContext context) { var api = ApiProviderPrivate.GetApi(context); if (!context.HasMarket) { throw new ApiResponseException("Market should be specified when querying order status", this); } var bodyActiveOrders = new Dictionary <string, object> { { "pair", context.Market.ToTicker(this) } }; var bodyOrderInfo = new Dictionary <string, object> { { "order_id", context.RemoteGroupId } }; //Checks if this order is contained in active list. var rActiveOrdersRaw = await api.QueryActiveOrdersAsync(bodyActiveOrders).ConfigureAwait(false); CheckResponseErrors(rActiveOrdersRaw); //If the active list contains this order and the request for active orders was successful, then it is active. Otherwise it is not active. bool isOpen = rActiveOrdersRaw.GetContent().success&& rActiveOrdersRaw.GetContent().returnData.ContainsKey(context.RemoteGroupId); var rOrderRaw = await api.QueryOrderInfoAsync(bodyOrderInfo).ConfigureAwait(false); CheckResponseErrors(rOrderRaw); var order = rOrderRaw.GetContent(); if (order == null || order.success == false) { throw new NoTradeOrderException(context, this); } return(new TradeOrderStatus(context.RemoteGroupId, isOpen, false) { Rate = order.returnData.Value.rate, AmountInitial = new Money(order.returnData.Value.start_amount, context.Market.Asset2) }); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProviderPrivate.GetApi(context); var body = CreateBody(); body.Add("method", "Trade"); body.Add("pair", context.Pair.ToTicker(this)); body.Add("type", context.IsBuy ? "buy" : "sell"); body.Add("amount", context.Quantity); body.Add("rate", context.Rate.ToDecimalValue()); var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(new PlacedOrderLimitResponse(r.returnData.order_id)); }
public virtual async Task <BalanceResults> GetBalancesAsync(NetworkProviderPrivateContext context) { var api = ApiProviderPrivate.GetApi(context); var body = CreatePostBody(); body.Add("method", ApiMethodsConfig[ApiMethodNamesTiLiWe.GetInfoExt]); var r = await api.GetUserInfoExtAsync(body).ConfigureAwait(false); CheckResponse(r); var balances = new BalanceResults(this); foreach (var fund in r.return_.funds) { var c = fund.Key.ToAsset(this); balances.Add(c, fund.Value.value, fund.Value.inOrders); } return(balances); }
public async Task <WithdrawalPlacementResult> PlaceWithdrawalAsync(WithdrawalPlacementContext context) { var api = ApiProviderPrivate.GetApi(context); var body = new Dictionary <string, object> { { "coinName", context.Amount.Asset.ShortCode }, { "amount", context.Amount.ToDecimalValue() }, { "address", context.Address.Address } }; var rRaw = await api.SubmitWithdrawRequestAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); if (rRaw.GetContent().success == false) { throw new ApiResponseException("Unsuccessful request in PlaceWithdrawalAsync"); } // No id is returned. return(new WithdrawalPlacementResult()); }
private async Task <YobitSchema.OrderInfoEntryResponse> GetOrderReponseByIdAsync(RemoteIdContext context) { var api = ApiProviderPrivate.GetApi(context); var bodyOrderInfo = CreateBody(); bodyOrderInfo.Add("method", "OrderInfo"); bodyOrderInfo.Add("order_id", context.RemoteGroupId); var rOrderRaw = await api.QueryOrderInfoAsync(bodyOrderInfo).ConfigureAwait(false); CheckResponseErrors(rOrderRaw); var orderContent = rOrderRaw.GetContent(); if (!orderContent.returnData.Key.Equals(context.RemoteGroupId)) { throw new NoTradeOrderException(context, this); } var order = orderContent.returnData.Value; return(order); }