Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Divide by 0 when Live trading with IB.

Open desimonk opened this issue 11 years ago • 4 comments

Bug fix request. See the discussion: https://groups.google.com/forum/#!topic/lean-engine/i3HBPn9Uo0E

20150926 20:56:57 ERROR:: BrokerageSetupHandler.Setup(): Attempted to divide by zero. at System.Decimal.FCallDivide(Decimal& d1, Decimal& d2) at System.Decimal.op_Division(Decimal d1, Decimal d2) at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage.Get UsdConversion(String currency) in c:\Users\Desi\SuperTrader\lean\Brokerages\I nteractiveBrokers\InteractiveBrokersBrokerage.cs:line 643 at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage.b__e(KeyValuePair2 x) in c:\Users\Desi\SuperTrader\lean\Brokera ges\InteractiveBrokers\InteractiveBrokersBrokerage.cs:line 322 at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage.Get CashBalance() in c:\Users\Desi\SuperTrader\lean\Brokerages\InteractiveBrokers \InteractiveBrokersBrokerage.cs:line 322 at QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler.Setup(IAlgorithm algo rithm, IBrokerage& brokerage, AlgorithmNodePacket job, IResultHandler resultHand ler, ITransactionHandler transactionHandler, IRealTimeHandler realTimeHandler) i n c:\Users\Desi\SuperTrader\lean\Engine\Setup\BrokerageSetupHandler.cs:line 2 50

20150926 20:56:57 ERROR:: 26/09/2015 8:54:27 PM: Error >> Failed to initialize a lgorithm: Error getting cash balance from brokerage: Attempted to divide by zero

desimonk avatar Sep 27 '15 05:09 desimonk

Interestingly this code hasn't changed since the end of April. Looking at the error/stack trace, it looks like this line gets runs but is set to a zero value. Do you know what currency it is trying to get a conversion for?

mchandschuh avatar Sep 27 '15 18:09 mchandschuh

USDCAD, isolated to a Saturday. We did see some failing re-deploys for IB as well (a few IB ones died yesterday for some reason)

Perhaps we need a more reliable/24-7 API for the initial fx value setting?

On Sun, Sep 27, 2015 at 2:38 PM, Michael [email protected] wrote:

Interestingly this code hasn't changed since the end of April. Looking at the error/stack trace, it looks like this line https://github.com/QuantConnect/Lean/blob/master/Brokerages/InteractiveBrokers/InteractiveBrokersBrokerage.cs#L630 gets runs but is set to a zero value. Do you know what currency it is trying to get a conversion for?

— Reply to this email directly or view it on GitHub https://github.com/QuantConnect/Lean/issues/177#issuecomment-143583235.

Jared Broad

www.quantconnect.com Phone-USA: +1 917 327 0556 Democratizing Finance, Empowering Individuals Facebook http://www.facebook.com/QuantConnect | Twitter https://twitter.com/#!/QuantConnect | LinkedIn http://www.linkedin.com/company/quantconnect | Skype: jaredbroad

jaredbroad avatar Sep 27 '15 21:09 jaredbroad

Canadian. Both usa and canadian forex market was closed at that the time I was trying this.

You are right that it is not related to code churn but rather time at witch I tried this.

JB and I think this is the same reason why my live deployment was getting runtime error. On Sep 27, 2015 2:38 PM, "Michael" [email protected] wrote:

Interestingly this code hasn't changed since the end of April. Looking at the error/stack trace, it looks like this line https://github.com/QuantConnect/Lean/blob/master/Brokerages/InteractiveBrokers/InteractiveBrokersBrokerage.cs#L630 gets runs but is set to a zero value. Do you know what currency it is trying to get a conversion for?

— Reply to this email directly or view it on GitHub https://github.com/QuantConnect/Lean/issues/177#issuecomment-143583235.

desimonk avatar Sep 28 '15 01:09 desimonk

This should be fixed in https://github.com/QuantConnect/Lean/commit/a6da4e15bf5340d70abad611cc47a24d8d95a3ac

mchandschuh avatar Sep 30 '15 18:09 mchandschuh