Repair after hours `.marketPrice()` logic
See original GitHub issueDuring non-market-hours the bid and ask are both -1 (or nan), so the range check fails, then the .midpoint()
also fails (because bid and asks are combinations of -1 and nan), so .marketPrice()
returns the previous day close instead of the most recent last price seen (example: currently for Sunday night, .marketPrice()
is returning the Thursday close price because of how the IBKR quote/ticker system updates open
/close
only at new market sessions).
Looks like the logic could be updated to either:
- just change the nan override to
.last
instead of.close
- or check for full accuracy:
- if (bid is nan or -1) and (ask is nan or -1), use
last
- if bids and asks are active, and if price is outside the spread, return synthetic
.midpoint()
- if (bid is nan or -1) and (ask is nan or -1), use
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Does After-Hours Trading Affect Stock Prices? - Investopedia
Trading stocks during after-hours trading sessions can have a big effect on the price that an investor will pay.
Read more >(FIX) Latest After Hours Trades - Nasdaq
After Hours Time (ET), After Hours Price, After Hours Share Volume. 16:14:07, $116, 20. 16:12:32, $116, 424. 16:12:32, $116, 248. 16:12:16, $116, 198....
Read more >What Is After-Hours Trading? – Forbes Advisor
Can You Buy Stocks After Hours? Yes. After-hours trading allows for stocks to be traded after the stock market's regular hours. However, ...
Read more >After-Hours Trading: Understanding the Risks - SEC.gov
The prices of some stocks traded during the after-hours session may not reflect the prices of those stocks during regular hours, either at...
Read more >After-Hours Trading: What It Is and How It Works
After -hours trading takes place after the trading day for a stock exchange, and it allows you to buy or sell stocks outside...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mattsta What I notice is that you still get a last value even without bid/ask. So the last value is still useful by itself and I will update the logic to take this into account.
When I try today (Monday morning, European servers), I get a ticker with only
ticker.close=157.28
. This is visible in TWS as well, there’s no grayed-out bid/ask anymore.also for reference using
.reqTickers()
: