Creating a Contract object with the IB API
When requesting market data or generating orders, we do it using the IB Contract
object. An IB Contract
contains all the information required for IB to correctly identify the instrument in question. Using one class, we can represent a broad spectrum of financial instruments, including stocks, options, futures, and more. In this recipe, we’ll create an IB Contract
.
The Contract
class is used to define the specifications of a financial instrument that we might want to trade or query. The class has all the necessary details that uniquely identify a financial instrument across various asset classes, such as stocks, options, futures, forex, bonds, and more.
A key attribute of the Contract
class is conId
(contract ID), which is a unique identifier assigned by IB to each financial instrument. However, in many cases, we do not need to specify this ID directly. Instead, we typically provide other descriptive attributes that the IB system...