public async Task <MarketPricesResult> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this, ""); var r = await api.GetTickerAsync(pairCode).ConfigureAwait(false); if (r.last.HasValue == false) { throw new NoAssetPairException(context.Pair, this); } var price = new MarketPrice(Network, context.Pair, r.last.Value) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.ask, r.bid, r.low, r.high), Volume = new NetworkPairVolume(Network, context.Pair, r.volume, r.volume_quote) }; return(new MarketPricesResult(price)); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r.success == false || r.data == null) { throw new ApiResponseException(r.msg, this); } var pairs = new AssetPairs(); foreach (var rCurrentTicker in r.data) { pairs.Add(rCurrentTicker.symbol.ToAssetPair(this)); } return(pairs); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProvider.GetApi(context); var body = new Dictionary <string, object> { { "listingCurrency", context.Pair.Asset1.ShortCode }, { "referenceCurrency", context.Pair.Asset2.ShortCode }, { "type", context.IsBuy ? "buy" : "sell" }, { "amount", context.Quantity.ToDecimalValue().ToString() } }; var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(new PlacedOrderLimitResponse(r)); }
public async Task <WalletAddresses> GetAddressesAsync(WalletAddressContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetAllBalancesAsync().ConfigureAwait(false); CheckResponseErrors(r); var addresses = new WalletAddresses(); foreach (var rBalance in r.result) { addresses.Add(new WalletAddress(this, rBalance.Currency.ToAsset(this)) { Address = rBalance.CryptoAddress }); } return(addresses); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetMarketsAsync().ConfigureAwait(false); if (r.success == false || r.result.Length == 0) { throw new ApiResponseException(r.message, this); } var pairs = new AssetPairs(); foreach (var rCurrentTicker in r.result) { pairs.Add(rCurrentTicker.MarketName.ToAssetPair(this)); } return(pairs); }
public async Task <MarketPricesResult> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetLatestPricesAsync(context.Pair.Asset1.ToRemoteCode(this)).ConfigureAwait(false); var rPrice = r.FirstOrDefault(x => x.symbol.Equals(context.Pair.ToTicker(this, ""))); if (rPrice == null || rPrice.lastPrice.HasValue == false) { throw new NoAssetPairException(context.Pair, this); } var price = new MarketPrice(Network, context.Pair, rPrice.lastPrice.Value) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, rPrice.askPrice, rPrice.bidPrice, rPrice.lowPrice, rPrice.highPrice), Volume = new NetworkPairVolume(Network, context.Pair, rPrice.volume24h) }; return(new MarketPricesResult(price)); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProvider.GetApi(context); var body = new Dictionary <string, object> { { "market", context.Pair.ToTicker(this).ToLower() }, { "side", context.IsBuy ? "buy" : "sell" }, { "volume", context.Quantity.ToDecimalValue() }, { "price", context.Rate.ToDecimalValue() } }; //TODO: SC - Documentation does not show example of response, so this has to be tested with real money to see what the endpoint returns var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(new PlacedOrderLimitResponse(r.id)); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetSymbolsAsync().ConfigureAwait(false); if (r == null || r.symbols.Length == 0) { throw new ApiResponseException("No asset pairs returned", this); } var pairs = new AssetPairs(); foreach (var currentSymbol in r.symbols) { pairs.Add(currentSymbol.symbol.ToAssetPair(this, 3)); } return(pairs); }
public async Task <WalletAddresses> GetAddressesForAssetAsync(WalletAddressAssetContext context) { var api = ApiProvider.GetApi(context); var rRaw = await api.GetDepositAddressAsync(context.Asset.ShortCode).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); var walletAddresses = new WalletAddresses { new WalletAddress(this, context.Asset) { Address = r.address } }; return(walletAddresses); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProvider.GetApi(context); var body = new BitfinexSchema.NewOrderRequest.Descriptor { symbol = context.Pair.ToTicker(this), amount = context.Quantity.ToString(CultureInfo.InvariantCulture), price = context.Rate.ToDecimalValue().ToString(CultureInfo.InvariantCulture), side = context.IsSell ? "sell" : "buy" }; var rRaw = await api.PlaceNewOrderAsync(body).ConfigureAwait(false); CheckBitfinexResponseErrors(rRaw); var r = rRaw.GetContent(); return(new PlacedOrderLimitResponse(r.order_id.ToString())); }
private async Task <List <QuoineSchema.ProductResponse> > GetAllProductsAsync() { var api = ApiProvider.GetApi(); var r = await api.GetProductsAsync().ConfigureAwait(false); if (r == null || r.Length == 0) { throw new ApiResponseException("No products returned", this); } var products = r.Where(x => x.product_type.Equals("CurrencyPair", StringComparison.InvariantCultureIgnoreCase)).ToList(); if (products == null || products.Any() == false) { throw new ApiResponseException("No products with currency pairs returned", this); } return(products); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r == null || r.responseStatus?.message?.Equals("OK", StringComparison.InvariantCultureIgnoreCase) == false || r.tickers == null || r.tickers.Length == 0) { throw new ApiResponseException("No asset pairs returned.", this); } var pairs = new AssetPairs(); foreach (var rCurrentTicker in r.tickers) { pairs.Add(rCurrentTicker.currencyPair.ToAssetPair(this, 3)); } return(pairs); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetAssetPairsAsync().ConfigureAwait(false); if (r == null || r.pairs.Count == 0) { throw new ApiResponseException("No asset pairs returned.", this); } var pairs = new AssetPairs(); foreach (string entry in r.pairs.Keys) { pairs.Add(entry.ToAssetPair(this, '_')); } return(pairs); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetSymbolsAsync().ConfigureAwait(false); var pairs = new AssetPairs(); foreach (var rSymbol in r) { var assetPair = ParseAssetPair(rSymbol); if (assetPair != null) { pairs.Add(assetPair); } } return(pairs); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetAssetPairsAsync().ConfigureAwait(false); if (r.Length == 0) { throw new ApiResponseException("No asset pairs returned", this); } var pairs = new AssetPairs(); foreach (var rCurrentTicker in r) { pairs.Add(rCurrentTicker.ToAssetPair(this)); } return(pairs); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProvider.GetApi(context); var market = context.Pair.ToTicker(this); var side = context.IsBuy ? "Buy" : "Sell"; var rRaw = await api.CreateNewLimitOrderAsync("Limit", side, market, context.Quantity.ToDecimalValue(), context.Rate.ToDecimalValue() ).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(new PlacedOrderLimitResponse(r.orderID)); }
private async Task <List <TradeOrderStatus> > GetOrdersAsync(MarketOrdersContext context, bool isOpen) { var api = ApiProvider.GetApi(context); string market = null; // Market not required. if (context.HasMarket) { market = context.Market.ToTicker(this); } var rRaw = await api.GetOrdersAsync(market, isOpen? "{\"open\": true}" : null).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(r.Where(x => !x.ordStatus.Equals("new", StringComparison.OrdinalIgnoreCase)).Select(ParseTradeOrderStatus).ToList()); }
public async Task <BalanceResults> GetBalancesAsync(NetworkProviderPrivateContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetAccountsAsync().ConfigureAwait(false); var results = new BalanceResults(this); foreach (var a in r.data) { if (a.balance == null) { continue; } var c = a.balance.currency.ToAsset(this); results.Add(c, a.balance.amount, 0); } return(results); }
public async Task <WithdrawalConfirmationResult> ConfirmWithdrawalAsync(WithdrawalConfirmationContext context) { var api = ApiProvider.GetApi(context); var body = new Dictionary <string, object> { { "token", context.WithdrawalRemoteId } }; var rRaw = await api.ConfirmWithdrawalAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(new WithdrawalConfirmationResult() { WithdrawalRemoteId = r.transactID }); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProvider.GetApi(context); var body = new CryptopiaSchema.SubmitTradeRequest { Market = context.Pair.ToTicker(this, "/"), Type = context.IsBuy ? "Buy" : "Sell", Rate = context.Rate, Amount = context.Quantity }; var rRaw = await api.SubmitTradeAsync(body).ConfigureAwait(false); CheckCryptopiaResponseErrors(rRaw); var r = rRaw.GetContent(); return(new PlacedOrderLimitResponse(r.Data.OrderId.ToString())); }
public async Task <BalanceResults> GetBalancesAsync(NetworkProviderPrivateContext context) { var api = ApiProvider.GetApi(context); var body = CreateKrakenBody(); var r = await api.GetBalancesAsync(body).ConfigureAwait(false); CheckResponseErrors(r); var results = new BalanceResults(this); foreach (var pair in r.result) { var asset = pair.Key.ToAsset(this); results.Add(asset, pair.Value, 0); } return(results); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var buy = context.IsBuy; var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var body = CreatePoloniexBody(buy ? PoloniexBodyType.LimitOrderBuy : PoloniexBodyType.LimitOrderSell); body.Add("currencyPair", pairCode); body.Add("rate", context.Rate.ToDecimalValue()); body.Add("amount", context.Quantity.ToDecimalValue()); var rRaw = await api.PlaceOrderLimitAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(new PlacedOrderLimitResponse(r.orderNumber, r.resultingTrades.Select(x => x.tradeID))); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var assetPairs = new AssetPairs(); var r = await api.GetMarketsAsync().ConfigureAwait(false); foreach (var rMarket in r) { var pieces = rMarket.product_code.Split('_'); if (pieces.Length != 2) { continue; } assetPairs.Add(rMarket.product_code.ToAssetPair(this, '_')); } return(assetPairs); }
private async Task <BitBaySchema.OrdersResponse> GetOrderResponseByOrderId(RemoteIdContext context) { var api = ApiProvider.GetApi(context); var body = CreatePostBody("orders"); var rRaw = await api.QueryOrdersAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); var order = r.FirstOrDefault(x => x.order_id.Equals(context.RemoteGroupId)); if (order == null) { throw new NoTradeOrderException(context, this); } return(order); }
public async Task <PlacedOrderLimitResponse> PlaceOrderLimitAsync(PlaceOrderLimitContext context) { var api = ApiProvider.GetApi(context); var body = CreatePostBody("trade"); body.Add("type", context.IsBuy ? "buy" : "sell"); body.Add("currency", context.Pair.Asset1.ToRemoteCode(this)); body.Add("amount", context.Quantity); body.Add("payment_currency", context.Pair.Asset2.ToRemoteCode(this)); body.Add("rate", context.Rate.ToDecimalValue()); var rRaw = await api.NewOrderAsync(body).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); return(new PlacedOrderLimitResponse(r.order_id)); }
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 } }); }
public async Task <WalletAddressesResult> GetAddressesForAssetAsync(WalletAddressAssetContext context) { var api = ApiProvider.GetApi(context); var rAccountId = await GetFirstAccountId(context).ConfigureAwait(false); var r = await api.GetAddressesAsync(rAccountId.Result).ConfigureAwait(false); //if (r.data.Count == 0 && context.CanGenerateAddress) //{ // var cr = await api.CreateAddressAsync(accid); // if (cr != null) // r.data.AddRange(cr.data); //} var addresses = new WalletAddressesResult() { ApiHitsCount = rAccountId.ApiHitsCount + 1 }; foreach (var a in r.data) { if (string.IsNullOrWhiteSpace(a.address)) { continue; } var forasset = FromNetwork(a.network); if (!context.Asset.Equals(forasset)) { continue; } addresses.Add(new WalletAddress(this, context.Asset) { Address = a.address }); } return(addresses); }
public async Task <PublicVolumeResponse> GetPublicVolumeAsync(PublicVolumesContext context) { var api = ApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this).ToLower(); var rRaw = await api.GetMarketSummaryAsync(pairCode).ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); var summary = r.result.FirstOrDefault(); var remoteMarker = summary.MarketName.ToAssetPair(this); if (summary == null || !remoteMarker.Equals(context.Pair)) { throw new AssetPairNotSupportedException(context.Pair, this); } return(new PublicVolumeResponse(Network, context.Pair, summary.BaseVolume, summary.Volume)); }
public async Task <TradeOrders> GetOrderHistoryAsync(PrivatePairContext context) { var api = ApiProvider.GetApi(context); var remotePair = context.RemotePairOrNull(this); var r = await api.GetAccountHistory(remotePair).ConfigureAwait(false); CheckResponseErrors(r); var orders = new TradeOrders(Network); foreach (var order in r.result) { orders.Add(new TradeOrder(order.OrderUuid, Network, order.Exchange.ToAssetPair(this), GetTradeOrderType(order.Type), order.Price) { Quantity = order.Quantity, QuantityRemaining = order.QuantityRemaining }); } return(orders); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = ApiProvider.GetApi(context); var rRaw = await api.GetTickerAsync().ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); var pairs = new AssetPairs(); foreach (var rPair in r) { var pair = rPair.Key.ToAssetPair(this); pairs.Add(pair); } return(pairs); }