private Candle?CreateCandle(IBinanceKline kline, string market, Timeframe timefame) { var c = new Candle { CloseTimeTicks = kline.CloseTime.Ticks, IsComplete = kline.CloseTime <= DateTime.UtcNow ? (byte)1 : (byte)0, CloseBid = (float)kline.CommonClose, HighBid = (float)kline.CommonHigh, LowBid = (float)kline.CommonLow, OpenTimeTicks = kline.OpenTime.Ticks, OpenBid = (float)kline.CommonOpen, Volume = (float)kline.CommonVolume, CloseAsk = (float)kline.CommonClose, HighAsk = (float)kline.CommonHigh, LowAsk = (float)kline.CommonLow, OpenAsk = (float)kline.CommonOpen }; var interval = (c.CloseTime() - c.OpenTime()).TotalSeconds; if ((int)timefame != Math.Round(interval)) { // throw new ApplicationException("Candle timeframe wrong"); // Some candles are wrong length (Seen some in 2018 date ranges) } if (c.OpenTimeTicks > c.CloseTimeTicks) { //throw new ApplicationException("Candle open time is later the close time"); Log.Warn($"Binance candle ignored {market} {c} {timefame}"); return(null); } return(c); }
private bool CheckKline(Interval interval) { KlineInterval kline = interval.ToBinance(); IEnumerable <IBinanceKline> candles = _client.Spot.Market .GetKlines(Pair, kline, null, null, 2) .GetResult(); IBinanceKline candle = candles.First(); decimal profit = EurAvailable + EurAvailable * Profit / 100; decimal crypto = EurAvailable / candle.Open; decimal cryptoBuy = crypto - crypto * TakerFee; decimal cryptoSell = cryptoBuy - cryptoBuy * TakerFee; decimal wantedHigh = profit / cryptoSell; return(candle.Open <= candle.Close && wantedHigh <= candle.High); }