public async Task <IEnumerable <OpenOrder> > OpenOrders(SymbolPair pair, CancellationToken?cancelToken = null) { const string basePath = "/open_orders"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); try { return(await this.PostToService( path, EmptyRequestParams, x => { var ja = x as JsonArray; return ja == null ? Enumerable.Empty <OpenOrder>() : ja.Select(OpenOrder.FromDynamic).ToArray(); }, cancelToken )); } catch (AggregateException ae) { throw ae.Flatten(); } }
internal static Ticker FromDynamic(SymbolPair symbolPair, dynamic data) { return(new Ticker { SymbolPair = symbolPair, Ask = JsonHelpers.ToDecimal(data["ask"]), Bid = JsonHelpers.ToDecimal(data["bid"]), High = JsonHelpers.ToDecimal(data["high"]), Last = JsonHelpers.ToDecimal(data["last"]), Low = JsonHelpers.ToDecimal(data["low"]), Volume = JsonHelpers.ToDecimal(data["volume"]), Timestamp = data["timestamp"] }); }
internal static Ticker FromDynamic(SymbolPair symbolPair, dynamic data) { return new Ticker { SymbolPair = symbolPair, Ask = decimal.Parse(data["ask"]), Bid = decimal.Parse(data["bid"]), High = decimal.Parse(data["high"]), Last = decimal.Parse(data["last"]), Low = decimal.Parse(data["low"]), Volume = decimal.Parse(data["volume"]), Timestamp = data["timestamp"] }; }
internal static Ticker FromDynamic(SymbolPair symbolPair, dynamic data) { return new Ticker { SymbolPair = symbolPair, Ask = JsonHelpers.ToDecimal(data["ask"]), Bid = JsonHelpers.ToDecimal(data["bid"]), High = JsonHelpers.ToDecimal(data["high"]), Last = JsonHelpers.ToDecimal(data["last"]), Low = JsonHelpers.ToDecimal(data["low"]), Volume = JsonHelpers.ToDecimal(data["volume"]), Timestamp = data["timestamp"] }; }
public async Task <OrderBook> OrderBook(SymbolPair pair, CancellationToken?cancelToken = null) { const string basePath = "/order_book"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); try { return(await this.GetFromService( path, Cex.OrderBook.FromDynamic, cancelToken )); } catch (AggregateException ae) { throw ae.Flatten(); } }
public async Task <Ticker> Ticker(SymbolPair pair, CancellationToken?cancelToken = null) { const string basePath = "/ticker"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); try { return(await this.GetFromService( path, json => Cex.Ticker.FromDynamic(pair, json), cancelToken )); } catch (AggregateException ae) { throw ae.Flatten(); } }
public async Task<OrderBook> OrderBook(SymbolPair pair, CancellationToken? cancelToken = null) { const string basePath = "/order_book"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); try { return await this.GetFromService( path, Cex.OrderBook.FromDynamic, cancelToken ); } catch (AggregateException ae) { throw ae.Flatten(); } }
public async Task<Ticker> Ticker(SymbolPair pair, CancellationToken? cancelToken = null) { const string basePath = "/ticker"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); try { return await this.GetFromService( path, json => Cex.Ticker.FromDynamic(pair, json), cancelToken ); } catch (AggregateException ae) { throw ae.Flatten(); } }
public async Task<IEnumerable<Trade>> TradeHistory(SymbolPair pair, TradeId? tradeId = null, CancellationToken? cancelToken = null) { const string basePath = "/trade_history"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); if (tradeId != null) path += string.Format("/?since={0}", tradeId.Value); try { return await this.GetFromService( path, Trade.FromDynamic, cancelToken ); } catch (AggregateException ae) { throw ae.Flatten(); } }
public async Task <IEnumerable <Trade> > TradeHistory(SymbolPair pair, TradeId?tradeId = null, CancellationToken?cancelToken = null) { const string basePath = "/trade_history"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); if (tradeId != null) { path += string.Format("/?since={0}", tradeId.Value); } try { return(await this.GetFromService( path, Trade.FromDynamic, cancelToken )); } catch (AggregateException ae) { throw ae.Flatten(); } }
public async Task <OpenOrder> PlaceOrder(SymbolPair pair, Order order, CancellationToken?cancelToken = null) { const string basePath = "/place_order"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); try { return(await this.PostToService( path, () => new[] { this.NewRequestParam("type", order.Type == OrderType.Sell ? "sell" : "buy"), this.NewRequestParam("price", order.Price), this.NewRequestParam("amount", order.Amount) }, OpenOrder.FromDynamic, cancelToken )); } catch (AggregateException ae) { throw ae.Flatten(); } }
public bool Equals(SymbolPair other) { return From == other.From && To == other.To; }
public bool Equals(SymbolPair other) { return(From == other.From && To == other.To); }
public async Task<OpenOrder> PlaceOrder(SymbolPair pair, Order order, CancellationToken? cancelToken = null) { const string basePath = "/place_order"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); try { return await this.PostToService( path, () => new[] { this.NewRequestParam("type", order.Type == OrderType.Sell ? "sell" : "buy"), this.NewRequestParam("price", order.Price), this.NewRequestParam("amount", order.Amount) }, OpenOrder.FromDynamic, cancelToken ); } catch (AggregateException ae) { throw ae.Flatten(); } }
public async Task<IEnumerable<OpenOrder>> OpenOrders(SymbolPair pair, CancellationToken? cancelToken = null) { const string basePath = "/open_orders"; var path = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To); try { return await this.PostToService( path, EmptyRequestParams, x => { var ja = x as JsonArray; return ja == null ? Enumerable.Empty<OpenOrder>() : ja.Select(OpenOrder.FromDynamic).ToArray(); }, cancelToken ); } catch (AggregateException ae) { throw ae.Flatten(); } }
private async void PlaceOrder(SymbolPair pair, Balance balance, OrderType orderType) { Order order = new Order(); OrderBook orderBook = await _cexClient.OrderBook(pair); _apiCallCount = ++_apiCallCount; IEnumerable<OrderBookOrder> bids = orderBook.Bids; order.Price = ((OrderBookOrder[]) (bids))[0].Price; decimal amount = 0; decimal availableBalance; if (orderType == OrderType.Buy) { if (pair.To == Symbol.NMC) { availableBalance = balance.NMC.Available; amount = PurchaseAmount(order.Price, availableBalance); } if (pair.To == Symbol.BTC) { availableBalance = balance.BTC.Available - udMaintanMinBtcBalance.Value; amount = PurchaseAmount(order.Price, availableBalance); } if (amount <= (decimal) 0.00000001) return; } if (orderType == OrderType.Sell) { if (pair.From == Symbol.IXC) { availableBalance = balance.IXC.Available; if (availableBalance < (decimal) .00000001) return; decimal saleValue = order.Price*availableBalance; if (saleValue < (decimal) .00000001) return; } } order.Type = orderType; order.Amount = amount; try { OpenOrder orderDetails = await _cexClient.PlaceOrder(pair, order); _apiCallCount = ++_apiCallCount; decimal totalOrder = order.Price*order.Amount; decimal totalOrderCostRounded = Math.Round(totalOrder, 8); richTextBox1.AppendText(string.Format(@"Sold:{8} {1} @ {2} for {0} {7}: Total: {3} @ {4} -- Order #{5}{6}", order.Amount, pair.To, order.Price, totalOrderCostRounded, DateTime.Now, orderDetails.Id, Environment.NewLine, pair.From, Math.Round(orderDetails.Price*order.Amount, 8))); _ghsPurchased = _ghsPurchased + order.Amount; _orderCount = ++_orderCount; UpdateUi(); } catch { Console.WriteLine(@"oops"); } }