public List <MarketCandle> GetKlinesWebsocket(string symbol, KlineInterval interval) { List <MarketCandle> candles = TickerKLines[symbol]; candles = AggregateCandlesIntoRequestedTimePeriod(KlineInterval.kline_1m, interval, candles); return(candles); }
public static decimal GetDivergence(string coinpair, KlineInterval interval) { var defaultDivergence = API.config.default_divergence; var currentPrice = DataManager.GetPrice(coinpair); return(currentPrice * defaultDivergence * IntervalDivergenceMultiplicator[interval]); }
private object SubscribeCandle(string instrument, string field, int interval) { var key = instrument + "|" + interval; if (SubscribedCandle.ContainsKey(key)) { BinanceStreamKlineData stream; if (CandleCache.TryGetValue(key, out stream)) { return(DecodeCandle(stream, field)); } else { return(SubscriptionManager.UninitializedValue); } } else { KlineInterval klineInterval = (KlineInterval)interval; SubscribedCandle.Add(key, true); Task.Run(() => socketClient.SubscribeToKlineStream(instrument, klineInterval, (stream) => { CandleCache[key] = stream; CacheCandle(stream, interval); })); return(SubscriptionManager.UninitializedValue); } }
public static Core.Enums.Period ToCoreEquivalent(this KlineInterval period) { switch (period) { case KlineInterval.OneDay: return(Core.Enums.Period.Day); case KlineInterval.FiveMinutes: return(Core.Enums.Period.FiveMinutes); case KlineInterval.OneHour: return(Core.Enums.Period.Hour); case KlineInterval.OneMinute: return(Core.Enums.Period.Minute); case KlineInterval.ThirtyMinutes: return(Core.Enums.Period.HalfAnHour); case KlineInterval.FourHour: return(Core.Enums.Period.FourHours); case KlineInterval.TwoHour: return(Core.Enums.Period.TwoHours); case KlineInterval.FiveteenMinutes: return(Core.Enums.Period.QuarterOfAnHour); default: throw new ArgumentException($"{period} is an unknown value for Period"); } }
public void Unsubscribe(string symbol, KlineInterval interval) { var intervalStr = string.Format("kline_{0}", TransferNameConverter.Convert(interval)); var msg = new { method = "unsubscribe", topic = intervalStr, symbols = new[] { symbol } }; _ws.Send(msg); }
public TrendlineIndicator(string coin, KlineInterval interval, int numberOfCandles) { this.coinPair = coin; this.interval = interval; this.candleNumber = numberOfCandles; analyseTimer = new Timer((obj) => { AnalyseCoin(); }, null, 0, 1000 * 10); }
//-------------------------------------需要慎重的两个函数------开始------------------- // public async Task <List <KlineInfo> > GetHistoryKlines( string symbol, KlineInterval interval, DateTime start, DateTime end, int limit = 800) { long s = new DateTimeOffset(start).ToUnixTimeMilliseconds(); long e = new DateTimeOffset(end).ToUnixTimeMilliseconds(); //string path = "/v2/candles/trade:" // + ConvertHelper.ObtainEnumValue(interval) // + ":t" + symbol.ToUpper() // + "/hist?limit=" + limit.ToString() // + "&start=" + s.ToString() // + "&end=" + e.ToString() // + "&sort=1"; BaseInfo args = GeneratePayload("GetHistoryKlines"); args.Add("symbol", symbol); args.Add("interval", ConvertHelper.ObtainEnumValue(interval)); args.Add("start", s); args.Add("end", e); args.Add("limit", limit); return(await ProcessAuthenticated <List <KlineInfo> >(args)); //return await ProcessPublic<List<KlineInfo>>(path); }
/// <summary> /// Gets candlestick/kline bars for a symbol. Bars are uniquely identified by their open time. /// </summary> /// <returns></returns> public List <KlinesResponse> GetKlines(string symbol, KlineInterval interval, int limit = 300, long startTime = 0, long endTime = 0) { //Call specific settings string urlPattern = "{0}/klines?symbol={1}&interval={2}&limit={3}"; string url = string.Format(urlPattern, _env.HttpsApiAddress, symbol, TransferNameConverter.Convert(interval), limit); StringBuilder sbQueryFilter = new StringBuilder(); if (startTime > 0) { sbQueryFilter.AppendFormat("&startTime={0}", startTime); } if (endTime > 0) { sbQueryFilter.AppendFormat("&endTime={0}", endTime); } if (sbQueryFilter.Length > 0) { url = string.Format("{0}{1}", url, sbQueryFilter); } int callsPerSecondAllowed = 10; //Generic items for calls var response = GetStringResponse(url, urlPattern, callsPerSecondAllowed); //Call specific processing of returned values var ret = JsonConvert.DeserializeObject <List <KlinesResponse> >(response); return(ret); }
public static IPeriodCode ToPeriodCode(this KlineInterval interval) { switch (interval) { case KlineInterval.OneMinute: return(PeriodCode.MINUTE); case KlineInterval.FiveMinutes: return(PeriodCode.FIVE_MINUTES); case KlineInterval.FifteenMinutes: return(PeriodCode.QUARTER_HOUR); case KlineInterval.ThirtyMinutes: return(PeriodCode.HALF_HOUR); case KlineInterval.OneHour: return(PeriodCode.HOUR); case KlineInterval.FourHour: return(PeriodCode.FOUR_HOUR); case KlineInterval.OneDay: return(PeriodCode.DAY); default: throw new Exception($"Not supported perion {interval.ToString()}"); } }
public void SubscribingToCandleUpdates_Should_TriggerWithCandleUpdate(KlineInterval timeframe) { // arrange var socket = new TestSocket(); socket.CanConnect = true; var client = TestHelpers.CreateSocketClient(socket); BitfinexKline[] result = null; var subTask = client.SpotStreams.SubscribeToKlineUpdatesAsync("tBTCUSD", timeframe, data => result = data.Data.ToArray()); var subResponse = new CandleSubscriptionResponse() { Channel = "candles", Event = "subscribed", ChannelId = 1, Symbol = "BTCUSD", Key = "trade:" + JsonConvert.SerializeObject(timeframe, new KlineIntervalConverter(false)) + ":tBTCUSD" }; socket.InvokeMessage(subResponse); subTask.Wait(5000); BitfinexKline[] expected = new[] { new BitfinexKline() }; // act socket.InvokeMessage($"[1, {JsonConvert.SerializeObject(expected)}]"); // assert Assert.IsTrue(TestHelpers.AreEqual(result[0], expected[0])); }
public void SubscribingToCandleUpdates_Should_SubscribeSuccessfully(KlineInterval timeframe) { // arrange var socket = new TestSocket(); socket.CanConnect = true; var client = TestHelpers.CreateSocketClient(socket, new BitfinexSocketClientOptions() { LogLevel = LogLevel.Debug }); var subTask = client.SpotStreams.SubscribeToKlineUpdatesAsync("tBTCUSD", timeframe, data => { }); var subResponse = new CandleSubscriptionResponse() { Channel = "candles", Event = "subscribed", ChannelId = 1, Symbol = "BTCUSD", Key = "trade:" + JsonConvert.SerializeObject(timeframe, new KlineIntervalConverter(false)) + ":tBTCUSD" }; // act socket.InvokeMessage(subResponse); subTask.Wait(5000); // assert Assert.IsTrue(subTask.Result.Success); }
public ResistanceAnalysation(string pair, KlineInterval interval) { this.coinPair = pair; this.interval = interval; this.lastPrice = DataManager.GetPrice(pair); // Update Resistances every 5 Minutes this.updateResistanceTimer = new Timer(this.UpdateResistances, null, 0, 5 * 1000); }
/// <summary> /// Connect to the Kline WebSocket /// </summary> /// <param name="symbol"></param> /// <param name="interval"></param> /// <param name="messageEventHandler"></param> /// <returns></returns> public Guid ConnectToKlineWebSocket(string symbol, KlineInterval interval, BinanceWebSocketMessageHandler <BinanceKlineData> messageEventHandler) { Guard.AgainstNullOrEmpty(symbol, nameof(symbol)); Logger.Debug("Connecting to Kline Web Socket"); var endpoint = new Uri($"{BaseWebsocketUri}/{symbol.ToLower()}@kline_{EnumExtensions.GetEnumMemberValue(interval)}"); return(CreateBinanceWebSocket(endpoint, messageEventHandler)); }
public CandleData(string coinPair, KlineInterval interval) { this.coinPair = coinPair; this.interval = interval; int minutes = Helper.IntervalToMinuteMatrix[interval]; Update(0); this.updateTimer = new Timer(this.Update, null, (int)(60 * 1000 * MinToNextCall(interval)), 60 * 1000 * minutes); }
public CandleJob(string symbol, DateTime start, DateTime end, KlineInterval interval) { Working = false; Done = false; Symbol = symbol; Start = start; End = end; Interval = interval; }
public async Task <List <KlinesResponse> > GetKlinesAsync(string symbol, KlineInterval interval, int limit = 300, long startTime = 0, long endTime = 0) { var br = await Task <List <KlinesResponse> > .Run(() => { return(GetKlines(symbol, interval, limit, startTime, endTime)); }); return(br); }
public static void AddCandleTracking(string pair, KlineInterval interval) { if (candleDatas.Find(x => x.coinPair == pair && x.interval == interval) != null) { throw new Exception("Tried to add candle tracking but tracker already exists for " + pair + "."); } candleDatas.Add(new CandleData(pair, interval)); }
public Trendline(decimal m, decimal n, int startpoint, KlineInterval interval, List <TrendPoint> linePoints, int candleDataSize) { this.movement = m; this.n = n; this.startpoint = startpoint; this.interval = interval; this.linePoints = linePoints; this.candleDataSize = candleDataSize; }
public IndicatorsManager(string coinPair, KlineInterval interval) { this.coinPair = coinPair; this.interval = interval; resistanceAnalysation = new ResistanceAnalysation(coinPair, interval); tli = new TrendlineIndicator(coinPair, interval, 100); sma = new SimpleMovingAverage(coinPair, interval, 9, 100); vol = new Volume(coinPair, interval, 100); }
public SimpleMovingAverage(string coinPair, KlineInterval interval, int numberOfCandles, int length) { this.coinPair = coinPair; this.interval = interval; this.numberOfCandles = numberOfCandles; this.length = length; getAverages(); }
private void AddKline(KlineInterval interval, BinanceKline klineValue) { klinesDictionary[interval].Add(klineValue); if (interval == klineInterval) { RaisePropertyChangedEvent("Klines"); } }
public static string Convert(KlineInterval interval) { var s = interval.ToString(); StringBuilder sb = new StringBuilder(); sb.Append(s[1]); sb.Append(s[0]); return(sb.ToString()); }
public static int ToSeconds(this KlineInterval interval) { if (interval == KlineInterval.OneMinute) { return(1 * 60); } if (interval == KlineInterval.ThreeMinute) { return(3 * 60); } if (interval == KlineInterval.FiveMinute) { return(5 * 60); } if (interval == KlineInterval.FiveteenMinute) { return(15 * 60); } if (interval == KlineInterval.ThirtyMinute) { return(30 * 60); } if (interval == KlineInterval.OneHour) { return(1 * 60 * 60); } if (interval == KlineInterval.TwoHour) { return(2 * 60 * 60); } if (interval == KlineInterval.FourHour) { return(4 * 60 * 60); } if (interval == KlineInterval.SixHour) { return(6 * 60 * 60); } if (interval == KlineInterval.TwelfHour) { return(12 * 60 * 60); } if (interval == KlineInterval.OneDay) { return(1 * 24 * 60 * 60); } if (interval == KlineInterval.ThreeDay) { return(3 * 24 * 60 * 60); } if (interval == KlineInterval.OneWeek) { return(7 * 24 * 60 * 60); } return(0); }
public void RetrieveKline(Action <CurrentKlineInfo> handler, KlineInterval interval) { if (_klineSocketId.HasValue) { AbortKline(); } _klineSocketId = AccessWebSocket.Subscribe( _symbol + "@kline_" + ConvertHelper.ObtainEnumValue(interval), handler); }
public static void ForceCandleUpdate(string pair, KlineInterval interval) { CandleData data = candleDatas.Find(x => x.coinPair == pair && x.interval == interval); if (data == null) { throw new Exception("Tried to update Candle Data for Pair and or Interval that isn't existing."); } data.Update(null); }
public static CandleData GetCandleDataForPairAndInterval(string pair, KlineInterval interval) { CandleData data = candleDatas.Find(x => x.coinPair == pair && x.interval == interval); if (data == null) { throw new Exception("Tried to get Candle Data for Pair and or Interval that isn't existing."); } return(data); }
// public async Task <List <Candlestick> > GetCandlesticks(string pair, KlineInterval interval, int?limit = null, long?startTime = null, long?endTime = null) { var req = new CandlestickRequest() { Symbol = pair, Interval = interval, Limit = limit, StartTime = startTime, EndTime = endTime }; Console.WriteLine(interval); var resp = await _connecter.PublicRequest(req); return(JsonConvert.DeserializeObject <List <Candlestick> >(resp.Content, new CustomCandlestickConverter())); }
public static CandleInfo LastCandleInDB(string market, KlineInterval interval) { var dt = DBHelper.GetDataTable("SELECT * FROM Candles WHERE Symbol='" + market + "' and Interval=" + interval.ToString() + " order by Id desc LIMIT 1"); if (dt.Rows.Count > 0) { return(new CandleInfo(dt.Rows[dt.Rows.Count - 1])); } else { return(null); } }
public async Task Start(string pricepairname = "NEBLBTC", KlineInterval kli = KlineInterval.OneMinute) { var subResult = await _socketClient.Spot.SubscribeToKlineUpdatesAsync(pricepairname, kli, data => { LastKline = data; OnKlineData?.Invoke(data); }); if (subResult.Success) { _subscription = subResult.Data; } }
private KlineInterval MapTimeFrame(Timeframe timeFrame) { var result = new KlineInterval(); switch (timeFrame) { case Timeframe.OneMinute: result = KlineInterval.OneMinute; break; case Timeframe.FiveMinute: result = KlineInterval.FiveMinutes; break; case Timeframe.FiveteenMinute: result = KlineInterval.FifteenMinutes; break; case Timeframe.ThirtyMinute: result = KlineInterval.ThirtyMinutes; break; case Timeframe.OneHour: result = KlineInterval.OneHour; break; case Timeframe.SixHour: result = KlineInterval.SixHour; break; case Timeframe.TwelveHour: result = KlineInterval.TwelveHour; break; case Timeframe.OneDay: result = KlineInterval.OneDay; break; case Timeframe.SevenDay: result = KlineInterval.OneWeek; break; case Timeframe.OneMonth: result = KlineInterval.OneMonth; break; default: break; } return(result); }