QuantConnect / Lean.Brokerages.Samco

Samco Brokerage Plugin
Apache License 2.0
1 stars 6 forks source link

Exception in LiveAuxiliaryDataSynchronizingEnumerator #20

Open Amol-Gupta opened 1 year ago

Amol-Gupta commented 1 year ago

Actual Behavior

I am facing an exception on LiveAuxiliaryDataSynchronizingEnumerator.cs

2023-01-25 11:10:00 Runtime Error: Instant out of range for DateTime in LiveAuxiliaryDataSynchronizingEnumerator.cs:line 179
2023-01-25 11:10:00 Runtime Error: Instant out of range for DateTime in LiveAuxiliaryDataSynchronizingEnumerator.cs:line 179: StackTrace: System.Exception: Instant out of range for DateTime in LiveAuxiliaryDataSynchronizingEnumerator.cs:line 179
 ---> System.InvalidOperationException: Instant out of range for DateTime
   at NodaTime.Instant.ToDateTimeUtc()
   at NodaTime.ZonedDateTime.ToDateTimeUtc()
   at QuantConnect.Lean.Engine.DataFeeds.Enumerators.LiveAuxiliaryDataSynchronizingEnumerator.DataPointEmitted(DateTime frontierUtc) in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\Enumerators\LiveAuxiliaryDataSynchronizingEnumerator.cs:line 179
   at QuantConnect.Lean.Engine.DataFeeds.Enumerators.LiveAuxiliaryDataSynchronizingEnumerator.MoveNext() in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\Enumerators\LiveAuxiliaryDataSynchronizingEnumerator.cs:line 76
   at QuantConnect.Lean.Engine.DataFeeds.Enumerators.FillForwardEnumerator.MoveNext() in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\Enumerators\FillForwardEnumerator.cs:line 138
   at QuantConnect.Lean.Engine.DataFeeds.Enumerators.FrontierAwareEnumerator.MoveNext() in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\Enumerators\FrontierAwareEnumerator.cs:line 83
   at QuantConnect.Lean.Engine.DataFeeds.Enumerators.SubscriptionFilterEnumerator.MoveNext() in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\Enumerators\SubscriptionFilterEnumerator.cs:line 123
   at QuantConnect.Lean.Engine.DataFeeds.Enumerators.SubscriptionDataEnumerator.MoveNext() in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\Enumerators\SubscriptionDataEnumerator.cs:line 71
   at QuantConnect.Lean.Engine.DataFeeds.Subscription.MoveNext() in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\Subscription.cs:line 206
   at QuantConnect.Lean.Engine.DataFeeds.SubscriptionSynchronizer.Sync(IEnumerable`1 subscriptions, CancellationToken cancellationToken)+MoveNext() in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\SubscriptionSynchronizer.cs:line 116
   at QuantConnect.Lean.Engine.DataFeeds.LiveSynchronizer.StreamData(CancellationToken cancellationToken)+MoveNext() in C:\Users\amolg\source\repos\LeanSetups\Setup_2\Lean\Engine\DataFeeds\LiveSynchronizer.cs:line 118

Expected Behavior

I have tried debugging the LiveAuxiliaryDataSynchronizingEnumerator.cs at line 179. It is trying to convert the EndTime to UTC. EndTime was already matching with the UTC. I am in India which is GMT+5:30 (TimeZones.Kolkata). I am not sure what the actual behavior but the aforementioned behavior is incorrect. Also, all subscribed symbols are unsubscribed on the first tick.

Potential Solution

Reproducing the Problem

Checkout following 2 repos in empty https://github.com/Amol-Gupta/Lean.git https://github.com/Amol-Gupta/Lean.Brokerages.Samco.git

checkout temp1 branch On both repo. Fill in credentials for samco. Build, Run. that will help in reporoducing the isssue

System Information

Windows 11. Visual studio.

Checklist

Martin-Molinero commented 1 year ago

Hi @Amol-Gupta! Thanks for the report. Lean expects data to be emitted in exchange time zone as per the market-hours-database specifications.

It is trying to convert the EndTime to UTC. EndTime was already matching with the UTC.

That sounds like the bug, ref https://github.com/QuantConnect/Lean.Brokerages.Samco/blob/master/QuantConnect.SamcoBrokerage/SamcoBrokerage.cs#L838