// Where pair like "TRXETH" and interval like "1m", "5m", "1h", ... public ZCandlestickMap GetCandlesticks(string pair, string interval) { var result = new ZCandlestickMap(CryptoExch.BINANCE, pair, interval); var res = GetOHLC(pair, interval, 500); foreach (var dp in res) { result.Add(dp.time, dp); } return(result); }
// Where pair like "BCHEUR" and interval like "1m", "5m", "1h", ... public ZCandlestickMap GetCandlesticks(string pair, string interval) { var result = new ZCandlestickMap(CryptoExch.KRAKEN, pair, interval); int minutes = int.Parse(ChartIntervals[interval]); var res = GetOHLC(pair, minutes); var ohlcList = res.Pairs[pair]; foreach (var dp in ohlcList) { result.Add(dp.time, dp); } return(result); }
// Where start/end are start and end times for the data // AND granularity is desired timeslice in seconds: {60, 300, 900, 3600, 21600, 86400} public ZCandlestickMap GetCandlesticks(string productId, string intervalSeconds, DateTime?start = null, DateTime?end = null) { var result = new ZCandlestickMap(CryptoExch.GDAX, productId, intervalSeconds); var productPair = GetProductPair(productId); int seconds = int.Parse(ChartIntervals[intervalSeconds]); var dtEnd = (end == null ? DateTime.Now : end.Value); var dtStart = (start == null ? dtEnd.Subtract(TimeSpan.FromSeconds(seconds * 100)) : start.Value); // returns list of list: [[ time, low, high, open, close, volume ], [ 1415398768, 0.32, 4.2, 0.35, 4.2, 12.3 ]] var sticks = AsyncHelpers.RunSync <IEnumerable <object[]> >(() => m_api.ProductsService.GetHistoricRatesAsync(productPair, dtStart, dtEnd, seconds)); //var sticks = await m_api.ProductsService.GetHistoricRatesAsync(productPair, dtStart, dtEnd, int.Parse(ChartIntervals[intervalSeconds])); //string url = BaseUrl + "/products/{0}/candles"; //var sticks = GET<List<List<float>>>(url, productId); foreach (var li in sticks) { var cs = new GdaxCandlestick(li); result.Add(cs.time, cs); } return(result); }
void ProcessBar(ZCandlestick bar, bool displayIndicator, bool displayDebug) { if (m_bars.ContainsKey(bar.time)) // this is a bar that is already in our list (should be an update of the last/latest bar) { var lastBar = m_bars.Last().Value; if (bar.time == lastBar.time) { m_bars[bar.time] = bar; if (displayDebug) { cout("{0}> update the LAST (latest) bar in our list: {1}", m_pair, bar.ToString()); } m_macdLive.UpdateLastTick((double)lastBar.close); CheckIndicator(m_macdLive, false, displayIndicator); } } else // otherwise, add this NEW bar to our list AND update the indicator with the previous last bar in our list { if (m_bars.Count > 0) { var lastBar = m_bars.Last().Value; if (displayDebug) { cout("{0}> updating indicator with LAST bar in our list: {1}", m_pair, lastBar.ToString()); } m_macd.ReceiveTick((double)lastBar.close); CheckIndicator(m_macd, true, displayIndicator); } m_macdLive.ReceiveTick((double)bar.close); CheckIndicator(m_macdLive, false, displayIndicator); m_bars.Add(bar.time, bar); if (displayDebug) { cout("{0}> added to bar list: {1}", m_pair, bar.ToString()); } } }
void ProcessBar(ZCandlestick bar, bool displayIndicator) { int indicator = 0; if (m_bars.ContainsKey(bar.time)) // this is a bar that is already in our list (should be an update of the last/latest bar) { var lastBar = m_bars.Last().Value; if (bar.time == lastBar.time) { m_bars[bar.time] = bar; if (m_displayDebug) { cout("{0}> update the 'real-time' indicator LAST (latest) bar in our list: {1}", PairId, bar.ToString()); } m_macdLive.UpdateLastTick((double)lastBar.close); indicator = CheckIndicator(m_macdLive, displayIndicator); // not a completed bar, so do NOT execute a trade } } else // otherwise, add this NEW bar to our list AND update the indicator with the previous last bar in our list { if (m_bars.Count > 0) { var lastBar = m_bars.Last().Value; if (m_displayDebug) { cout("{0}> update the 'bar-complete' indicator with LAST COMPLETE bar in our list: {1}", PairId, lastBar.ToString()); } m_macd.ReceiveTick((double)lastBar.close); indicator = CheckIndicator(m_macd, displayIndicator); // this IS a complete bar, so make a trade if (indicator == -1) // indicator = SHORT { if (m_pos > 0) // CHECK TO SEE IF WE CROSSED positive-to-negative { TradeSell(lastBar.time.ToDateTimeString(), lastBar.close); } else if (m_pos == 0) // if no position, then set our initial pos (DON'T trade) { m_pos = -1; } } else if (indicator == +1) // indicator = LONG { if (m_pos < 0) // CHECK TO SEE IF WE CROSSED positive-to-negative { TradeBuy(lastBar.time.ToDateTimeString(), lastBar.close); } else if (m_pos == 0) // if no position, then set our initial pos (DON'T trade) { m_pos = +1; } } } m_macdLive.ReceiveTick((double)bar.close); indicator = CheckIndicator(m_macdLive, displayIndicator); // not a completed bar, so do NOT execute a trade m_bars.Add(bar.time, bar); if (m_displayDebug) { cout("{0}> added to bar list: {1}", m_pair, bar.ToString()); } } }