public override void OnBar(string symbolCode, TimeFrame timeFrame, TimedBar bar) { if (i++ % 111 == 0) { l.LogInformation($"{this.GetType().Name} [{timeFrame.Name}] {symbolCode} {bar}"); } }
public override void OnBar(string symbolCode, TimeFrame timeFrame, TimedBar bar) { if (i++ % 4810 == 0) { Console.WriteLine($"{this.GetType().Name} [{timeFrame.Name}] {symbolCode} {bar}"); } }
//protected virtual void UpdateDesiredSubscriptions() //{ // // Disabled for now // //this.DesiredSubscriptions = new List<MarketDataSubscription>() // //{ // // new MarketDataSubscription(this.Template.Symbol, Template.TimeFrame) // // //new MarketDataSubscription(this.Config.Symbol, "t1") // //}; //} //protected void OnSimulationTickFinished() //{ // //logger.LogInformation("bot OnSimulationTickFinished " + (Market as BacktestMarket).SimulationTime); // Evaluate(); //} //long i = 0; public override void OnBar(string symbolCode, TimeFrame timeFrame, TimedBar bar) { if (bar.IsValid) { Console.WriteLine("OnBar: " + bar); Evaluate(); } //if (i++ % 48 == 0) //{ // Console.WriteLine($"{this.GetType().Name} [{timeFrame.Name}] {symbolCode} {bar}"); //} }
private async void barHandler(TimedBar bar) { try { OnBar(MarketSeries.SymbolCode, MarketSeries.TimeFrame, bar); } catch (Exception ex) { this.FaultException = ex; MarketSeries.Bar += barHandler; await this.OnFault(ex).ConfigureAwait(false); } }
private void TickToMinuteBar(string symbolCode, TimedBar bar) { lock (TickToMinuteBarLock) { //var bar = tickToMinuteBars[symbolCode]; if (!bar.IsValid) { return; } GetMarketSeriesInternal(symbolCode, TimeFrame.m1).OnBar(bar, true); tickToMinuteBars[symbolCode] = TimedBar.Invalid; } }
public override void OnBar(string symbolCode, TimeFrame timeFrame, TimedBar bar) { //if (indicator.MarketSeries == null) //{ // indicator.MarketSeries = Market.Data.LiveDataSources.GetMarketSeries("XAUUSD", TimeFrame.h1); //} indicator.CalculateIndex(indicator.MarketSeries.Count - 1); if (i++ % 111 == 0) { Console.WriteLine($"{indicator.ToString()} h:{indicator.Top.LastValue} m:{indicator.Middle.LastValue} l:{indicator.Bottom.LastValue}"); //Console.WriteLine($"{this.GetType().Name} [{timeFrame.Name}] {symbolCode} {bar}"); } }
private void MarketSeries_Bar(TimedBar obj) { //Console.WriteLine("[bar] " + obj); Evaluate(); }
// Hardcoded to Bid prices // Move elsewhere, potentially reuse? private void TickToMinuteHandler(SymbolTick tick) { if (!tick.Time.IsSameMinute(ServerTimeFromTick) && tick.Time < serverTickToMinuteTime) { logger.LogWarning($"[TICK] Got old {tick.Symbol} tick for time {tick.Time} when server tick to minute time is {serverTickToMinuteTime} and server time from tick is {ServerTimeFromTick}"); } if (tick.Time > ServerTimeFromTick) { ServerTimeFromTick = tick.Time; // May trigger a bar from previous minute, for all symbols, after a delay (to wait for remaining ticks to come in) } TimedBar bar = tickToMinuteBars.TryGetValue(tick.Symbol, TimedBar.Invalid); if (bar.IsValid && !bar.OpenTime.IsSameMinute(tick.Time)) { // Immediately Trigger a finished bar even after starting the timer above. TickToMinuteBar(tick.Symbol, bar); bar = TimedBar.Invalid; } if (!bar.IsValid) { var minuteBarOpen = new DateTime(tick.Time.Year, tick.Time.Month, tick.Time.Day, tick.Time.Hour, tick.Time.Minute, 0); bar = new TimedBar(minuteBarOpen); } if (!double.IsNaN(tick.Bid)) { if (double.IsNaN(bar.Open)) { bar.Open = tick.Bid; } bar.Close = tick.Bid; if (double.IsNaN(bar.High) || bar.High < tick.Bid) { bar.High = tick.Bid; } if (double.IsNaN(bar.Low) || bar.Low > tick.Bid) { bar.Low = tick.Bid; } } if (double.IsNaN(bar.Volume)) // REVIEW - is this correct for volume? { bar.Volume = 1; } else { bar.Volume++; } if (tickToMinuteBars.ContainsKey(tick.Symbol)) { tickToMinuteBars[tick.Symbol] = bar; } else { tickToMinuteBars.Add(tick.Symbol, bar); } }