private void CallBTCeAPITicker() { int TimeOut = 10; string queryStr = string.Format(BTCeAPITickerURL, BtcePairHelper.ToString(currency)); var request = (HttpWebRequest)WebRequest.Create(queryStr); request.GetResponse(); request.Timeout = TimeOut * 1000; if (request == null) { throw new Exception("Non HTTP WebRequest"); } TickerInfo ticker = TickerInfo.ReadFromJSON(new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd()); if (PriceChanged != null) { if ( latestTicker == null || PriceChangePushIndicator == PUSH_PRICE_CHANGE_ALWAYS || ((PriceChangePushIndicator & PUSH_PRICE_CHANGE_BUY) > 0 && latestTicker.Buy != ticker.Buy) || ((PriceChangePushIndicator & PUSH_PRICE_CHANGE_SELL) > 0 && latestTicker.Sell != ticker.Sell) || ((PriceChangePushIndicator & PUSH_PRICE_CHANGE_BUY_DOWN) > 0 && latestTicker.Buy > ticker.Buy) || ((PriceChangePushIndicator & PUSH_PRICE_CHANGE_BUY_UP) > 0 && latestTicker.Buy < ticker.Buy) || ((PriceChangePushIndicator & PUSH_PRICE_CHANGE_SELL_DOWN) > 0 && latestTicker.Sell > ticker.Sell) || ((PriceChangePushIndicator & PUSH_PRICE_CHANGE_SELL_UP) > 0 && latestTicker.Sell < ticker.Sell) ) { PriceChanged( ticker, EventArgs.Empty); } latestTicker = ticker; } else { latestTicker = ticker; } Ticker.Start(); }
public static OrderInfo ReadFromJSON(string order, int orderId) { JObject o = JObject.Parse(order) as JObject; if (o == null) { return(null); } OrderInfo orderInfo = new OrderInfo() { Pair = BtcePairHelper.FromString(o.Value <string>("pair")), Type = TradeTypeHelper.FromString(o.Value <string>("type")), Amount = o.Value <decimal>("amount"), Rate = o.Value <decimal>("rate"), TimestampCreated = o.Value <UInt32>("timestamp_created"), Status = (BTCeOrderStatus)o.Value <int>("status"), Id = orderId }; return(orderInfo); }
private void CallBTCeAPIActiveOrders() { var resultStr = Query(new Dictionary <string, string>() { { "method", "ActiveOrders" }, { "pair", BtcePairHelper.ToString(currency) } }); if (ActiveOrdersReceived != null || ActiveOrdersCountChanged != null || ActiveOrdersTotalAmountChanged != null) { try { OrdersList orders = OrdersList.ReadFromJSON(resultStr); var totalAmount = orders.List.Sum(x => x.Value.Amount); if (ActiveOrdersReceived != null) { ActiveOrdersReceived(orders, EventArgs.Empty); } if (ActiveOrdersCountChanged != null) { if (latestActiveOrdersCount > -1 && latestActiveOrdersCount != orders.List.Count) { ActiveOrdersCountChanged(orders, new DecimalEventArgs(latestActiveOrdersCount)); } } if (ActiveOrdersTotalAmountChanged != null) { if (latestTotalAmount > -1 && latestTotalAmount != totalAmount) { ActiveOrdersTotalAmountChanged(orders, new DecimalEventArgs(latestTotalAmount)); } } if (latestActiveOrdersCount != orders.List.Count) { latestActiveOrdersCount = orders.List.Count; } if (latestTotalAmount != totalAmount) { latestTotalAmount = totalAmount; } ActiveOrders.Start(); } catch (BTCeAPIException e) { ActiveOrdersReceived(e, EventArgs.Empty); } catch (Exception ex) { ActiveOrdersReceived(ex, EventArgs.Empty); } } }