Getting a market data snapshot
In the previous recipe, we learned how to get historical data. In some situations, we may need the current market price. In Chapter 12, Deploy Strategies to a Live Environment, we’ll use the current market price to create methods to target specific values or percentage allocations in our portfolio.
The API uses tick types, each representing a specific category of market data, such as last trade price, volume, or bid and ask. These tick types let us access real-time pricing information, which is important for making informed trading decisions. This recipe will show you how to get real-time market data.
Getting ready…
We assume you’ve created the app.py
, client.py
, and wrapper.py
files in the trading-app
directory. If not, do it now.
How to do it…
We’ll update app.py
, client.py
, and wrapper.py
to request the last price for a contract.
- Open
client.py
and include the following method in theIBClient...