Comments (11)
Was the market open when you ran this? The ticker is not returning a price, hence the error.
from thetagang.
Yes. Also at this moment same error. Even with 1.8.1
from thetagang.
Odd. Does IBKR return a price for the same symbol? There are some weird edge cases (like things with very low liquidity) where sometimes it doesn't return data. It should normally return the midpoint price, or the last trade price if that's not available. This is a tricky case because it's not safe to keep going if you can't get a valid price for the symbol, it will lead to undefined behaviour.
See here: https://ib-insync.readthedocs.io/api.html#ib_insync.ticker.Ticker.marketPrice
from thetagang.
Argh, yes there was one option with a price of 0.00. Just bought it for 0.01 to close that position. Fixed the issue instantly. Thanks for the hint.
from thetagang.
That's odd, I guess there must have been no bids or asks, and no trades. Maybe I will have it handle that one particular case more gracefully by skipping over contracts with no price, but I want to think about it for a bit to make sure I don't inadvertently introduce a footgun. I think it's probably safe to just ignore this specific case, but that means it won't be able to roll the contract (ideally it would expire worthless).
from thetagang.
The put option (T Feb16 14Put) was sold with a very low commission. Unfortunately, I hadn't used minimum_credit yet, which could probably have prevented it (which is btw just working in the latest tag, not main).
As a result, the option was too far out of the money.
Of course, the option would have simply expired - that's not a problem. The problem, however, is that all other options were set to "pause" because the script was always interrupted as a result.
So maybe it's not such a bad idea to distinguish whether the option price is 0.00 or does not return a value at all?
from thetagang.
What's especially confusing to me is that it's actually failing on getting the market price for the stock, not the option itself. That should certainly not be returning 0 or NaN. It should already gracefully handle cases where the option has no price, usually it'll print an error and continue anyway.
So, I'm either failing to understand the problem, or I've missed some key piece of information.
Was there any other detail in the stack trace from before? I'm thinking that stack trace is actually a red herring and the error is somewhere else.
If I were to guess, it's failing after this function (which tries to handle this as gracefully as possible, but could still return a 0 or NaN in some cases):
Lines 207 to 222 in 42af123
The error itself is caused by a failed type conversion from a float to an integer, which doesn't quite make sense because the prices are handled as floats. I will make a tiny correction so that in the case that ticker.marketPrice()
is NaN, it'll return 0.0 instead.
from thetagang.
Something odd is happening here:
Log from yesterday attached. It just happens in my paper account. The live account does not have any issues.
I'm using the cash management in the paper only. Currently the paper only have SGOV in account.
It somehow fails to caluclate target positions.
Maybe this helps to find whats happening.
Error.txt
from thetagang.
One of those two values (either the market price, or the weights) has to be NaN. It's not the weight, because it prints that earlier (showing 20%), so it must be the market price.
What do you have this setting set to:
Line 386 in dfd37f4
The only thing I can think of, is that if ib_insync.api_response_wait_time
is too small, it won't wait long enough for the API to get the market prices. Anything less than 5 is probably going to frequently cause problems.
In any case, I'll make one more tweak to this code, which will hopefully handle this situation better.
from thetagang.
api_response_wait_time = 60
for both paper/live
from thetagang.
Now it is just working. Haven't changed anything. But thanks for digging into this rare issue.
from thetagang.
Related Issues (20)
- runtime error HOT 3
- Docker image broken HOT 2
- Error when running Docker HOT 3
- No support for different currencies HOT 2
- A key error raised HOT 3
- ValueError: cannot convert float NaN to integer HOT 8
- java.awt.AWTError: Can't connect to X11 window server using ':1' as the value of the DISPLAY variable. HOT 10
- Empty docker image? HOT 2
- only support USD currency HOT 3
- Add a cash management strategy
- IBC setup on Docker HOT 5
- ValueError: cannot convert float NaN to integer HOT 2
- How to keep ib's client long-running? HOT 4
- RuntimeError: No valid contracts found for ABNB. HOT 2
- Issue running thetagang with IBC in Poetry HOT 6
- Exhausted retries waiting on predicate. HOT 2
- Rolling puts with increasing Delta HOT 2
- Position not rolled - conditions met HOT 2
- Change from ib_insync to ib_async HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thetagang.