ibapi-stable 10.37.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ibapi/__init__.py +16 -0
- ibapi/account_summary_tags.py +70 -0
- ibapi/client.py +4891 -0
- ibapi/client_utils.py +412 -0
- ibapi/comm.py +100 -0
- ibapi/commission_and_fees_report.py +31 -0
- ibapi/common.py +315 -0
- ibapi/connection.py +126 -0
- ibapi/const.py +12 -0
- ibapi/contract.py +265 -0
- ibapi/decoder.py +1711 -0
- ibapi/decoder_utils.py +420 -0
- ibapi/enum_implem.py +20 -0
- ibapi/errors.py +43 -0
- ibapi/execution.py +95 -0
- ibapi/ineligibility_reason.py +18 -0
- ibapi/message.py +186 -0
- ibapi/news.py +13 -0
- ibapi/object_implem.py +12 -0
- ibapi/order.py +263 -0
- ibapi/order_cancel.py +21 -0
- ibapi/order_condition.py +289 -0
- ibapi/order_state.py +117 -0
- ibapi/orderdecoder.py +539 -0
- ibapi/protobuf/CancelOrderRequest_pb2.py +38 -0
- ibapi/protobuf/ComboLeg_pb2.py +37 -0
- ibapi/protobuf/Contract_pb2.py +39 -0
- ibapi/protobuf/DeltaNeutralContract_pb2.py +37 -0
- ibapi/protobuf/ErrorMessage_pb2.py +37 -0
- ibapi/protobuf/ExecutionDetailsEnd_pb2.py +37 -0
- ibapi/protobuf/ExecutionDetails_pb2.py +39 -0
- ibapi/protobuf/ExecutionFilter_pb2.py +37 -0
- ibapi/protobuf/ExecutionRequest_pb2.py +38 -0
- ibapi/protobuf/Execution_pb2.py +37 -0
- ibapi/protobuf/GlobalCancelRequest_pb2.py +38 -0
- ibapi/protobuf/OpenOrder_pb2.py +40 -0
- ibapi/protobuf/OpenOrdersEnd_pb2.py +37 -0
- ibapi/protobuf/OrderAllocation_pb2.py +37 -0
- ibapi/protobuf/OrderCancel_pb2.py +37 -0
- ibapi/protobuf/OrderCondition_pb2.py +37 -0
- ibapi/protobuf/OrderState_pb2.py +38 -0
- ibapi/protobuf/OrderStatus_pb2.py +37 -0
- ibapi/protobuf/Order_pb2.py +51 -0
- ibapi/protobuf/PlaceOrderRequest_pb2.py +39 -0
- ibapi/protobuf/SoftDollarTier_pb2.py +37 -0
- ibapi/reader.py +49 -0
- ibapi/scanner.py +77 -0
- ibapi/server_versions.py +159 -0
- ibapi/softdollartier.py +16 -0
- ibapi/tag_value.py +22 -0
- ibapi/ticktype.py +117 -0
- ibapi/utils.py +233 -0
- ibapi/wrapper.py +885 -0
- ibapi_stable-10.37.2.dist-info/METADATA +136 -0
- ibapi_stable-10.37.2.dist-info/RECORD +57 -0
- ibapi_stable-10.37.2.dist-info/WHEEL +5 -0
- ibapi_stable-10.37.2.dist-info/top_level.txt +1 -0
ibapi/decoder_utils.py
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2025 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
|
|
3
|
+
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
|
|
4
|
+
"""
|
|
5
|
+
from decimal import Decimal
|
|
6
|
+
|
|
7
|
+
from ibapi.contract import ComboLeg, Contract, DeltaNeutralContract
|
|
8
|
+
from ibapi.execution import Execution, OptionExerciseType
|
|
9
|
+
from ibapi.order import Order, OrderComboLeg
|
|
10
|
+
from ibapi.order_condition import OrderCondition, OperatorCondition, ContractCondition, PriceCondition, TimeCondition, MarginCondition, ExecutionCondition, VolumeCondition, PercentChangeCondition
|
|
11
|
+
from ibapi.order_state import OrderState, OrderAllocation
|
|
12
|
+
from ibapi.softdollartier import SoftDollarTier
|
|
13
|
+
from ibapi.tag_value import TagValue
|
|
14
|
+
from ibapi.utils import floatMaxString, getEnumTypeFromString, decimalMaxString
|
|
15
|
+
|
|
16
|
+
#from ibapi.protobuf.ComboLeg_pb2 import ComboLeg as ComboLegProto
|
|
17
|
+
from ibapi.protobuf.Contract_pb2 import Contract as ContractProto
|
|
18
|
+
from ibapi.protobuf.DeltaNeutralContract_pb2 import DeltaNeutralContract as DeltaNeutralContractProto
|
|
19
|
+
from ibapi.protobuf.Execution_pb2 import Execution as ExecutionProto
|
|
20
|
+
from ibapi.protobuf.Order_pb2 import Order as OrderProto
|
|
21
|
+
from ibapi.protobuf.OrderCondition_pb2 import OrderCondition as OrderConditionProto
|
|
22
|
+
from ibapi.protobuf.OrderState_pb2 import OrderState as OrderStateProto
|
|
23
|
+
from ibapi.protobuf.OrderAllocation_pb2 import OrderAllocation as OrderAllocatiionProto
|
|
24
|
+
from ibapi.protobuf.SoftDollarTier_pb2 import SoftDollarTier as SoftDollarTierProto
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def decodeContract(contractProto: ContractProto) -> Contract:
|
|
28
|
+
contract = Contract()
|
|
29
|
+
if contractProto.HasField('conId'): contract.conId = contractProto.conId
|
|
30
|
+
if contractProto.HasField('symbol'): contract.symbol = contractProto.symbol
|
|
31
|
+
if contractProto.HasField('secType'): contract.secType = contractProto.secType
|
|
32
|
+
if contractProto.HasField('lastTradeDateOrContractMonth'): contract.lastTradeDateOrContractMonth = contractProto.lastTradeDateOrContractMonth
|
|
33
|
+
if contractProto.HasField('strike'): contract.strike = contractProto.strike
|
|
34
|
+
if contractProto.HasField('right'): contract.right = contractProto.right
|
|
35
|
+
if contractProto.HasField('multiplier'): contract.multiplier = floatMaxString(contractProto.multiplier)
|
|
36
|
+
if contractProto.HasField('exchange'): contract.exchange = contractProto.exchange
|
|
37
|
+
if contractProto.HasField('currency'): contract.currency = contractProto.currency
|
|
38
|
+
if contractProto.HasField('localSymbol'): contract.localSymbol = contractProto.localSymbol
|
|
39
|
+
if contractProto.HasField('tradingClass'): contract.tradingClass = contractProto.tradingClass
|
|
40
|
+
if contractProto.HasField('comboLegsDescrip'): contract.comboLegsDescrip = contractProto.comboLegsDescrip
|
|
41
|
+
|
|
42
|
+
comboLegs = decodeComboLegs(contractProto)
|
|
43
|
+
if comboLegs is not None and comboLegs: contract.comboLegs = comboLegs
|
|
44
|
+
|
|
45
|
+
deltaNeutralContract = decodeDeltaNeutralContract(contractProto)
|
|
46
|
+
if deltaNeutralContract is not None: contract.deltaNeutralContract = deltaNeutralContract
|
|
47
|
+
|
|
48
|
+
return contract
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def decodeComboLegs(contractProto: ContractProto) -> list[ComboLeg]:
|
|
52
|
+
comboLegs = []
|
|
53
|
+
comboLegProtoList = contractProto.comboLegs
|
|
54
|
+
if comboLegProtoList:
|
|
55
|
+
for comboLegProto in comboLegProtoList:
|
|
56
|
+
comboLeg = ComboLeg()
|
|
57
|
+
if comboLegProto.HasField('conId'): comboLeg.conId = comboLegProto.conId
|
|
58
|
+
if comboLegProto.HasField('ratio'): comboLeg.ratio = comboLegProto.ratio
|
|
59
|
+
if comboLegProto.HasField('action'): comboLeg.action = comboLegProto.action
|
|
60
|
+
if comboLegProto.HasField('exchange'): comboLeg.exchange = comboLegProto.exchange
|
|
61
|
+
if comboLegProto.HasField('openClose'): comboLeg.openClose = comboLegProto.openClose
|
|
62
|
+
if comboLegProto.HasField('shortSalesSlot'): comboLeg.shortSalesSlot = comboLegProto.shortSalesSlot
|
|
63
|
+
if comboLegProto.HasField('designatedLocation'): comboLeg.designatedLocation = comboLegProto.designatedLocation
|
|
64
|
+
if comboLegProto.HasField('exemptCode'): comboLeg.exemptCode = comboLegProto.exemptCode
|
|
65
|
+
comboLegs.append(comboLeg)
|
|
66
|
+
|
|
67
|
+
return comboLegs
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def decodeOrderComboLegs(contractProto: ContractProto) -> list[OrderComboLeg]:
|
|
71
|
+
orderComboLegs = []
|
|
72
|
+
comboLegProtoList = contractProto.comboLegs
|
|
73
|
+
if comboLegProtoList:
|
|
74
|
+
for comboLegProto in comboLegProtoList:
|
|
75
|
+
orderComboLeg = OrderComboLeg()
|
|
76
|
+
if comboLegProto.HasField('perLegPrice'): orderComboLeg.price = comboLegProto.perLegPrice
|
|
77
|
+
orderComboLegs.append(orderComboLeg)
|
|
78
|
+
|
|
79
|
+
return orderComboLegs
|
|
80
|
+
|
|
81
|
+
@staticmethod
|
|
82
|
+
def decodeDeltaNeutralContract(contractProto: ContractProto) -> DeltaNeutralContract:
|
|
83
|
+
deltaNeutralContract = None
|
|
84
|
+
deltaNeutralContractProto = DeltaNeutralContractProto()
|
|
85
|
+
if contractProto.HasField('deltaNeutralContract'): deltaNeutralContractProto.CopyFrom(contractProto.deltaNeutralContract)
|
|
86
|
+
if deltaNeutralContractProto is not None:
|
|
87
|
+
deltaNeutralContract = DeltaNeutralContract()
|
|
88
|
+
if (deltaNeutralContractProto.HasField('conId')): deltaNeutralContract.conId = deltaNeutralContractProto.conId
|
|
89
|
+
if (deltaNeutralContractProto.HasField('delta')): deltaNeutralContract.delta = deltaNeutralContractProto.delta
|
|
90
|
+
if (deltaNeutralContractProto.HasField('price')): deltaNeutralContract.price = deltaNeutralContractProto.price
|
|
91
|
+
|
|
92
|
+
return deltaNeutralContract
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def decodeExecution(executionProto: ExecutionProto) -> Execution:
|
|
96
|
+
execution = Execution()
|
|
97
|
+
if executionProto.HasField('orderId'): execution.orderId = executionProto.orderId
|
|
98
|
+
if executionProto.HasField('clientId'): execution.clientId = executionProto.clientId
|
|
99
|
+
if executionProto.HasField('execId'): execution.execId = executionProto.execId
|
|
100
|
+
if executionProto.HasField('time'): execution.time = executionProto.time
|
|
101
|
+
if executionProto.HasField('acctNumber'): execution.acctNumber = executionProto.acctNumber
|
|
102
|
+
if executionProto.HasField('exchange'): execution.exchange = executionProto.exchange
|
|
103
|
+
if executionProto.HasField('side'): execution.side = executionProto.side
|
|
104
|
+
if executionProto.HasField('shares'): execution.shares = Decimal(executionProto.shares)
|
|
105
|
+
if executionProto.HasField('price'): execution.price = executionProto.price
|
|
106
|
+
if executionProto.HasField('permId'): execution.permId = executionProto.permId
|
|
107
|
+
if executionProto.HasField('isLiquidation'): execution.liquidation = 1 if executionProto.isLiquidation else 0
|
|
108
|
+
if executionProto.HasField('cumQty'): execution.cumQty = Decimal(executionProto.cumQty)
|
|
109
|
+
if executionProto.HasField('avgPrice'): execution.avgPrice = executionProto.avgPrice
|
|
110
|
+
if executionProto.HasField('orderRef'): execution.orderRef = executionProto.orderRef
|
|
111
|
+
if executionProto.HasField('evRule'): execution.evRule = executionProto.evRule
|
|
112
|
+
if executionProto.HasField('evMultiplier'): execution.evMultiplier = executionProto.evMultiplier
|
|
113
|
+
if executionProto.HasField('modelCode'): execution.modelCode = executionProto.modelCode
|
|
114
|
+
if executionProto.HasField('lastLiquidity'): execution.lastLiquidity = executionProto.lastLiquidity
|
|
115
|
+
if executionProto.HasField('isPriceRevisionPending'): execution.pendingPriceRevision = executionProto.isPriceRevisionPending
|
|
116
|
+
if executionProto.HasField('submitter'): execution.submitter = executionProto.submitter
|
|
117
|
+
if executionProto.HasField('optExerciseOrLapseType'): execution.optExerciseOrLapseType = getEnumTypeFromString(OptionExerciseType, executionProto.optExerciseOrLapseType)
|
|
118
|
+
return execution
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def decodeOrder(contractProto: ContractProto, orderProto: OrderProto) -> Order:
|
|
122
|
+
order = Order()
|
|
123
|
+
if orderProto.HasField('action'): order.action = orderProto.action
|
|
124
|
+
if orderProto.HasField('totalQuantity'): order.totalQuantity = orderProto.totalQuantity
|
|
125
|
+
if orderProto.HasField('orderType'): order.orderType = orderProto.orderType
|
|
126
|
+
if orderProto.HasField('lmtPrice'): order.lmtPrice = orderProto.lmtPrice
|
|
127
|
+
if orderProto.HasField('auxPrice'): order.auxPrice = orderProto.auxPrice
|
|
128
|
+
if orderProto.HasField('tif'): order.tif = orderProto.tif
|
|
129
|
+
if orderProto.HasField('ocaGroup'): order.ocaGroup = orderProto.ocaGroup
|
|
130
|
+
if orderProto.HasField('account'): order.account = orderProto.account
|
|
131
|
+
if orderProto.HasField('openClose'): order.openClose = orderProto.openClose
|
|
132
|
+
if orderProto.HasField('origin'): order.origin = orderProto.origin
|
|
133
|
+
if orderProto.HasField('orderRef'): order.orderRef = orderProto.orderRef
|
|
134
|
+
if orderProto.HasField('clientId'): order.clientId = orderProto.clientId
|
|
135
|
+
if orderProto.HasField('permId'): order.permId = orderProto.permId
|
|
136
|
+
if orderProto.HasField('outsideRth'): order.outsideRth = orderProto.outsideRth
|
|
137
|
+
if orderProto.HasField('hidden'): order.hidden = orderProto.hidden
|
|
138
|
+
if orderProto.HasField('discretionaryAmt'): order.discretionaryAmt = orderProto.discretionaryAmt
|
|
139
|
+
if orderProto.HasField('goodAfterTime'): order.goodAfterTime = orderProto.goodAfterTime
|
|
140
|
+
if orderProto.HasField('faGroup'): order.faGroup = orderProto.faGroup
|
|
141
|
+
if orderProto.HasField('faMethod'): order.faMethod = orderProto.faMethod
|
|
142
|
+
if orderProto.HasField('faPercentage'): order.faPercentage = orderProto.faPercentage
|
|
143
|
+
if orderProto.HasField('modelCode'): order.modelCode = orderProto.modelCode
|
|
144
|
+
if orderProto.HasField('goodTillDate'): order.goodTillDate = orderProto.goodTillDate
|
|
145
|
+
if orderProto.HasField('rule80A'): order.rule80A = orderProto.rule80A
|
|
146
|
+
if orderProto.HasField('percentOffset'): order.percentOffset = orderProto.percentOffset
|
|
147
|
+
if orderProto.HasField('settlingFirm'): order.settlingFirm = orderProto.settlingFirm
|
|
148
|
+
if orderProto.HasField('shortSaleSlot'): order.shortSaleSlot = orderProto.shortSaleSlot
|
|
149
|
+
if orderProto.HasField('designatedLocation'): order.designatedLocation = orderProto.designatedLocation
|
|
150
|
+
if orderProto.HasField('exemptCode'): order.exemptCode = orderProto.exemptCode
|
|
151
|
+
if orderProto.HasField('startingPrice'): order.startingPrice = orderProto.startingPrice
|
|
152
|
+
if orderProto.HasField('stockRefPrice'): order.stockRefPrice = orderProto.stockRefPrice
|
|
153
|
+
if orderProto.HasField('delta'): order.delta = orderProto.delta
|
|
154
|
+
if orderProto.HasField('stockRangeLower'): order.stockRangeLower = orderProto.stockRangeLower
|
|
155
|
+
if orderProto.HasField('stockRangeUpper'): order.stockRangeUpper = orderProto.stockRangeUpper
|
|
156
|
+
if orderProto.HasField('displaySize'): order.displaySize = orderProto.displaySize
|
|
157
|
+
if orderProto.HasField('blockOrder'): order.blockOrder = orderProto.blockOrder
|
|
158
|
+
if orderProto.HasField('sweepToFill'): order.sweepToFill = orderProto.sweepToFill
|
|
159
|
+
if orderProto.HasField('allOrNone'): order.allOrNone = orderProto.allOrNone
|
|
160
|
+
if orderProto.HasField('minQty'): order.minQty = orderProto.minQty
|
|
161
|
+
if orderProto.HasField('ocaType'): order.ocaType = orderProto.ocaType
|
|
162
|
+
if orderProto.HasField('parentId'): order.parentId = orderProto.parentId
|
|
163
|
+
if orderProto.HasField('triggerMethod'): order.triggerMethod = orderProto.triggerMethod
|
|
164
|
+
if orderProto.HasField('volatility'): order.volatility = orderProto.volatility
|
|
165
|
+
if orderProto.HasField('volatilityType'): order.volatilityType = orderProto.volatilityType
|
|
166
|
+
if orderProto.HasField('deltaNeutralOrderType'): order.deltaNeutralOrderType = orderProto.deltaNeutralOrderType
|
|
167
|
+
if orderProto.HasField('deltaNeutralAuxPrice'): order.deltaNeutralAuxPrice = orderProto.deltaNeutralAuxPrice
|
|
168
|
+
if orderProto.HasField('deltaNeutralConId'): order.deltaNeutralConId = orderProto.deltaNeutralConId
|
|
169
|
+
if orderProto.HasField('deltaNeutralSettlingFirm'): order.ddeltaNeutralSettlingFirm = orderProto.deltaNeutralSettlingFirm
|
|
170
|
+
if orderProto.HasField('deltaNeutralClearingAccount'): order.deltaNeutralClearingAccount = orderProto.deltaNeutralClearingAccount
|
|
171
|
+
if orderProto.HasField('deltaNeutralClearingIntent'): order.deltaNeutralClearingIntent = orderProto.deltaNeutralClearingIntent
|
|
172
|
+
if orderProto.HasField('deltaNeutralOpenClose'): order.deltaNeutralOpenClose = orderProto.deltaNeutralOpenClose
|
|
173
|
+
if orderProto.HasField('deltaNeutralShortSale'): order.deltaNeutralShortSale = orderProto.deltaNeutralShortSale
|
|
174
|
+
if orderProto.HasField('deltaNeutralShortSaleSlot'): order.deltaNeutralShortSaleSlot = orderProto.deltaNeutralShortSaleSlot
|
|
175
|
+
if orderProto.HasField('deltaNeutralDesignatedLocation'): order.deltaNeutralDesignatedLocation = orderProto.deltaNeutralDesignatedLocation
|
|
176
|
+
if orderProto.HasField('continuousUpdate'): order.continuousUpdate = orderProto.continuousUpdate
|
|
177
|
+
if orderProto.HasField('referencePriceType'): order.referencePriceType = orderProto.referencePriceType
|
|
178
|
+
if orderProto.HasField('trailStopPrice'): order.trailStopPrice = orderProto.trailStopPrice
|
|
179
|
+
if orderProto.HasField('trailingPercent'): order.trailingPercent = orderProto.trailingPercent
|
|
180
|
+
|
|
181
|
+
orderComboLegs = decodeOrderComboLegs(contractProto)
|
|
182
|
+
if orderComboLegs is not None and orderComboLegs: order.orderComboLegs = orderComboLegs
|
|
183
|
+
|
|
184
|
+
order.smartComboRoutingParams = decodeTagValueList(orderProto.smartComboRoutingParams)
|
|
185
|
+
|
|
186
|
+
if orderProto.HasField('scaleInitLevelSize'): order.scaleInitLevelSize = orderProto.scaleInitLevelSize
|
|
187
|
+
if orderProto.HasField('scaleSubsLevelSize'): order.scaleSubsLevelSize = orderProto.scaleSubsLevelSize
|
|
188
|
+
if orderProto.HasField('scalePriceIncrement'): order.scalePriceIncrement = orderProto.scalePriceIncrement
|
|
189
|
+
if orderProto.HasField('scalePriceAdjustValue'): order.scalePriceAdjustValue = orderProto.scalePriceAdjustValue
|
|
190
|
+
if orderProto.HasField('scalePriceAdjustInterval'): order.scalePriceAdjustInterval = orderProto.scalePriceAdjustInterval
|
|
191
|
+
if orderProto.HasField('scaleProfitOffset'): order.scaleProfitOffset = orderProto.scaleProfitOffset
|
|
192
|
+
if orderProto.HasField('scaleAutoReset'): order.scaleAutoReset = orderProto.scaleAutoReset
|
|
193
|
+
if orderProto.HasField('scaleInitPosition'): order.scaleInitPosition = orderProto.scaleInitPosition
|
|
194
|
+
if orderProto.HasField('scaleInitFillQty'): order.scaleInitFillQty = orderProto.scaleInitFillQty
|
|
195
|
+
if orderProto.HasField('scaleRandomPercent'): order.scaleRandomPercent = orderProto.scaleRandomPercent
|
|
196
|
+
if orderProto.HasField('hedgeType'): order.hedgeType = orderProto.hedgeType
|
|
197
|
+
if orderProto.HasField('hedgeType') and orderProto.HasField('hedgeParam') and orderProto.hedgeType: order.hedgeParam = orderProto.hedgeParam
|
|
198
|
+
if orderProto.HasField('optOutSmartRouting'): order.optOutSmartRouting = orderProto.optOutSmartRouting
|
|
199
|
+
if orderProto.HasField('clearingAccount'): order.clearingAccount = orderProto.clearingAccount
|
|
200
|
+
if orderProto.HasField('clearingIntent'): order.clearingIntent = orderProto.clearingIntent
|
|
201
|
+
if orderProto.HasField('notHeld'): order.notHeld = orderProto.notHeld
|
|
202
|
+
|
|
203
|
+
if orderProto.HasField('algoStrategy'):
|
|
204
|
+
order.algoStrategy = orderProto.algoStrategy
|
|
205
|
+
order.algoParams = decodeTagValueList(orderProto.algoParams)
|
|
206
|
+
|
|
207
|
+
if orderProto.HasField('solicited'): order.solicited = orderProto.solicited
|
|
208
|
+
if orderProto.HasField('whatIf'): order.whatIf = orderProto.whatIf
|
|
209
|
+
if orderProto.HasField('randomizeSize'): order.randomizeSize = orderProto.randomizeSize
|
|
210
|
+
if orderProto.HasField('randomizePrice'): order.randomizePrice = orderProto.randomizePrice
|
|
211
|
+
if orderProto.HasField('referenceContractId'): order.referenceContractId = orderProto.referenceContractId
|
|
212
|
+
if orderProto.HasField('isPeggedChangeAmountDecrease'): order.isPeggedChangeAmountDecrease = orderProto.isPeggedChangeAmountDecrease
|
|
213
|
+
if orderProto.HasField('peggedChangeAmount'): order.peggedChangeAmount = orderProto.peggedChangeAmount
|
|
214
|
+
if orderProto.HasField('referenceChangeAmount'): order.referenceChangeAmount = orderProto.referenceChangeAmount
|
|
215
|
+
if orderProto.HasField('referenceExchangeId'): order.referenceExchangeId = orderProto.referenceExchangeId
|
|
216
|
+
|
|
217
|
+
conditions = decodeConditions(orderProto)
|
|
218
|
+
if conditions is not None and conditions: order.conditions = conditions
|
|
219
|
+
if orderProto.HasField('conditionsIgnoreRth'): order.conditionsIgnoreRth = orderProto.conditionsIgnoreRth
|
|
220
|
+
if orderProto.HasField('conditionsCancelOrder'): order.conditionsCancelOrder = orderProto.conditionsCancelOrder
|
|
221
|
+
|
|
222
|
+
if orderProto.HasField('adjustedOrderType'): order.adjustedOrderType = orderProto.adjustedOrderType
|
|
223
|
+
if orderProto.HasField('triggerPrice'): order.triggerPrice = orderProto.triggerPrice
|
|
224
|
+
if orderProto.HasField('lmtPriceOffset'): order.lmtPriceOffset = orderProto.lmtPriceOffset
|
|
225
|
+
if orderProto.HasField('adjustedStopPrice'): order.adjustedStopPrice = orderProto.adjustedStopPrice
|
|
226
|
+
if orderProto.HasField('adjustedStopLimitPrice'): order.adjustedStopLimitPrice = orderProto.adjustedStopLimitPrice
|
|
227
|
+
if orderProto.HasField('adjustedTrailingAmount'): order.adjustedTrailingAmount = orderProto.adjustedTrailingAmount
|
|
228
|
+
if orderProto.HasField('adjustableTrailingUnit'): order.adjustableTrailingUnit = orderProto.adjustableTrailingUnit
|
|
229
|
+
|
|
230
|
+
softDollarTier = decodeSoftDollarTier(orderProto)
|
|
231
|
+
if softDollarTier is not None: order.softDollarTier = softDollarTier
|
|
232
|
+
|
|
233
|
+
if orderProto.HasField('cashQty'): order.cashQty = orderProto.cashQty
|
|
234
|
+
if orderProto.HasField('dontUseAutoPriceForHedge'): order.dontUseAutoPriceForHedge = orderProto.dontUseAutoPriceForHedge
|
|
235
|
+
if orderProto.HasField('isOmsContainer'): order.isOmsContainer = orderProto.isOmsContainer
|
|
236
|
+
if orderProto.HasField('discretionaryUpToLimitPrice'): order.discretionaryUpToLimitPrice = orderProto.discretionaryUpToLimitPrice
|
|
237
|
+
if orderProto.HasField('usePriceMgmtAlgo'): order.usePriceMgmtAlgo = orderProto.usePriceMgmtAlgo
|
|
238
|
+
if orderProto.HasField('duration'): order.duration = orderProto.duration
|
|
239
|
+
if orderProto.HasField('postToAts'): order.postToAts = orderProto.postToAts
|
|
240
|
+
if orderProto.HasField('autoCancelParent'): order.autoCancelParent = orderProto.autoCancelParent
|
|
241
|
+
if orderProto.HasField('minTradeQty'): order.minTradeQty = orderProto.minTradeQty
|
|
242
|
+
if orderProto.HasField('minCompeteSize'): order.minCompeteSize = orderProto.minCompeteSize
|
|
243
|
+
if orderProto.HasField('competeAgainstBestOffset'): order.competeAgainstBestOffset = orderProto.competeAgainstBestOffset
|
|
244
|
+
if orderProto.HasField('midOffsetAtWhole'): order.midOffsetAtWhole = orderProto.midOffsetAtWhole
|
|
245
|
+
if orderProto.HasField('midOffsetAtHalf'): order.midOffsetAtHalf = orderProto.midOffsetAtHalf
|
|
246
|
+
if orderProto.HasField('customerAccount'): order.customerAccount = orderProto.customerAccount
|
|
247
|
+
if orderProto.HasField('professionalCustomer'): order.professionalCustomer = orderProto.professionalCustomer
|
|
248
|
+
if orderProto.HasField('bondAccruedInterest'): order.bondAccruedInterest = orderProto.bondAccruedInterest
|
|
249
|
+
if orderProto.HasField('includeOvernight'): order.includeOvernight = orderProto.includeOvernight
|
|
250
|
+
if orderProto.HasField('extOperator'): order.extOperator = orderProto.extOperator
|
|
251
|
+
if orderProto.HasField('manualOrderIndicator'): order.manualOrderIndicator = orderProto.manualOrderIndicator
|
|
252
|
+
if orderProto.HasField('submitter'): order.submitter = orderProto.submitter
|
|
253
|
+
if orderProto.HasField('imbalanceOnly'): order.imbalanceOnly = orderProto.imbalanceOnly
|
|
254
|
+
|
|
255
|
+
return order
|
|
256
|
+
|
|
257
|
+
def decodeConditions(orderProto: OrderProto) -> list[OrderCondition]:
|
|
258
|
+
orderConditions = []
|
|
259
|
+
orderConditionsProtoList = []
|
|
260
|
+
if orderProto.conditions is not None: orderConditionsProtoList = orderProto.conditions
|
|
261
|
+
|
|
262
|
+
if orderConditionsProtoList:
|
|
263
|
+
for orderConditionProto in orderConditionsProtoList:
|
|
264
|
+
conditionType = orderConditionProto.type if orderConditionProto.HasField('type') else 0
|
|
265
|
+
|
|
266
|
+
if OrderCondition.Price == conditionType:
|
|
267
|
+
condition = createPriceCondition(orderConditionProto)
|
|
268
|
+
elif OrderCondition.Time == conditionType:
|
|
269
|
+
condition = createTimeCondition(orderConditionProto)
|
|
270
|
+
elif OrderCondition.Margin == conditionType:
|
|
271
|
+
condition = createMarginCondition(orderConditionProto)
|
|
272
|
+
elif OrderCondition.Execution == conditionType:
|
|
273
|
+
condition = createExecutionCondition(orderConditionProto)
|
|
274
|
+
elif OrderCondition.Volume == conditionType:
|
|
275
|
+
condition = createVolumeCondition(orderConditionProto)
|
|
276
|
+
elif OrderCondition.PercentChange == conditionType:
|
|
277
|
+
condition = createPercentChangeCondition(orderConditionProto)
|
|
278
|
+
|
|
279
|
+
if condition is not None: orderConditions.append(condition)
|
|
280
|
+
|
|
281
|
+
return orderConditions
|
|
282
|
+
|
|
283
|
+
@staticmethod
|
|
284
|
+
def setConditionFields(orderConditionProto: OrderConditionProto, orderCondition: OrderCondition):
|
|
285
|
+
if orderConditionProto.HasField('isConjunctionConnection'): orderCondition.isConjunctionConnection = orderConditionProto.isConjunctionConnection
|
|
286
|
+
|
|
287
|
+
@staticmethod
|
|
288
|
+
def setOperatorConditionFields(orderConditionProto: OrderConditionProto, operatorCondition: OperatorCondition):
|
|
289
|
+
setConditionFields(orderConditionProto, operatorCondition)
|
|
290
|
+
if orderConditionProto.HasField('isMore'): operatorCondition.isMore = orderConditionProto.isMore
|
|
291
|
+
|
|
292
|
+
@staticmethod
|
|
293
|
+
def setContractConditionFields(orderConditionProto: OrderConditionProto, contractCondition: ContractCondition):
|
|
294
|
+
setOperatorConditionFields(orderConditionProto, contractCondition)
|
|
295
|
+
if orderConditionProto.HasField('conId'): contractCondition.conId = orderConditionProto.conId
|
|
296
|
+
if orderConditionProto.HasField('exchange'): contractCondition.exchange = orderConditionProto.exchange
|
|
297
|
+
|
|
298
|
+
@staticmethod
|
|
299
|
+
def createPriceCondition(orderConditionProto: OrderConditionProto) -> PriceCondition:
|
|
300
|
+
priceCondition = PriceCondition()
|
|
301
|
+
setContractConditionFields(orderConditionProto, priceCondition)
|
|
302
|
+
if orderConditionProto.HasField('price'): priceCondition.price = orderConditionProto.price
|
|
303
|
+
if orderConditionProto.HasField('triggerMethod'): priceCondition.triggerMethod = orderConditionProto.triggerMethod
|
|
304
|
+
return priceCondition
|
|
305
|
+
|
|
306
|
+
@staticmethod
|
|
307
|
+
def createTimeCondition(orderConditionProto: OrderConditionProto) -> TimeCondition:
|
|
308
|
+
timeCondition = TimeCondition()
|
|
309
|
+
setOperatorConditionFields(orderConditionProto, timeCondition)
|
|
310
|
+
if orderConditionProto.HasField('time'): timeCondition.time = orderConditionProto.time
|
|
311
|
+
return timeCondition
|
|
312
|
+
|
|
313
|
+
@staticmethod
|
|
314
|
+
def createMarginCondition(orderConditionProto: OrderConditionProto) -> MarginCondition:
|
|
315
|
+
marginCondition = MarginCondition()
|
|
316
|
+
setOperatorConditionFields(orderConditionProto, marginCondition)
|
|
317
|
+
if orderConditionProto.HasField('percent'): marginCondition.percent = orderConditionProto.percent
|
|
318
|
+
return marginCondition
|
|
319
|
+
|
|
320
|
+
@staticmethod
|
|
321
|
+
def createExecutionCondition(orderConditionProto: OrderConditionProto) -> ExecutionCondition:
|
|
322
|
+
executionCondition = ExecutionCondition()
|
|
323
|
+
setConditionFields(orderConditionProto, executionCondition)
|
|
324
|
+
if orderConditionProto.HasField('secType'): executionCondition.secType = orderConditionProto.secType
|
|
325
|
+
if orderConditionProto.HasField('exchange'): executionCondition.exchange = orderConditionProto.exchange
|
|
326
|
+
if orderConditionProto.HasField('symbol'): executionCondition.symbol = orderConditionProto.symbol
|
|
327
|
+
return executionCondition
|
|
328
|
+
|
|
329
|
+
@staticmethod
|
|
330
|
+
def createVolumeCondition(orderConditionProto: OrderConditionProto) -> VolumeCondition:
|
|
331
|
+
volumeCondition = VolumeCondition()
|
|
332
|
+
setContractConditionFields(orderConditionProto, volumeCondition)
|
|
333
|
+
if orderConditionProto.HasField('volume'): volumeCondition.volume = orderConditionProto.volume
|
|
334
|
+
return volumeCondition
|
|
335
|
+
|
|
336
|
+
@staticmethod
|
|
337
|
+
def createPercentChangeCondition(orderConditionProto: OrderConditionProto) -> PercentChangeCondition:
|
|
338
|
+
percentChangeCondition = PercentChangeCondition()
|
|
339
|
+
setContractConditionFields(orderConditionProto, percentChangeCondition)
|
|
340
|
+
if orderConditionProto.HasField('changePercent'): percentChangeCondition.changePercent = orderConditionProto.changePercent
|
|
341
|
+
return percentChangeCondition
|
|
342
|
+
|
|
343
|
+
@staticmethod
|
|
344
|
+
def decodeSoftDollarTier(orderProto: OrderProto) -> SoftDollarTier:
|
|
345
|
+
name = ""
|
|
346
|
+
value = ""
|
|
347
|
+
displayName = ""
|
|
348
|
+
softDollarTierProto = SoftDollarTierProto()
|
|
349
|
+
if orderProto.softDollarTier is not None: softDollarTierProto = orderProto.softDollarTier
|
|
350
|
+
if softDollarTierProto.HasField('name'): name = softDollarTierProto.name
|
|
351
|
+
if softDollarTierProto.HasField('value'): value = softDollarTierProto.value
|
|
352
|
+
if softDollarTierProto.HasField('displayName'): displayName = softDollarTierProto.displayName
|
|
353
|
+
softDollarTier = SoftDollarTier(name, value, displayName)
|
|
354
|
+
|
|
355
|
+
return softDollarTier
|
|
356
|
+
|
|
357
|
+
@staticmethod
|
|
358
|
+
def decodeTagValueList(protoMap: dict[str, str]) -> list[TagValue]:
|
|
359
|
+
tagValueList = []
|
|
360
|
+
if protoMap is not None and protoMap:
|
|
361
|
+
for tag, value in protoMap.items():
|
|
362
|
+
tagValue = TagValue()
|
|
363
|
+
tagValue.tag = tag
|
|
364
|
+
tagValue.value = value
|
|
365
|
+
tagValueList.append(tagValue)
|
|
366
|
+
return tagValueList
|
|
367
|
+
|
|
368
|
+
@staticmethod
|
|
369
|
+
def decodeOrderState(orderStateProto: OrderStateProto) -> OrderState:
|
|
370
|
+
orderState = OrderState()
|
|
371
|
+
if orderStateProto.HasField('status'): orderState.status = orderStateProto.status
|
|
372
|
+
if orderStateProto.HasField('initMarginBefore'): orderState.initMarginBefore = orderStateProto.initMarginBefore
|
|
373
|
+
if orderStateProto.HasField('maintMarginBefore'): orderState.maintMarginBefore = decimalMaxString(orderStateProto.maintMarginBefore)
|
|
374
|
+
if orderStateProto.HasField('equityWithLoanBefore'): orderState.equityWithLoanBefore = decimalMaxString(orderStateProto.equityWithLoanBefore)
|
|
375
|
+
if orderStateProto.HasField('initMarginChange'): orderState.initMarginChange = decimalMaxString(orderStateProto.initMarginChange)
|
|
376
|
+
if orderStateProto.HasField('maintMarginChange'): orderState.maintMarginChange = decimalMaxString(orderStateProto.maintMarginChange)
|
|
377
|
+
if orderStateProto.HasField('equityWithLoanChange'): orderState.equityWithLoanChange = decimalMaxString(orderStateProto.equityWithLoanChange)
|
|
378
|
+
if orderStateProto.HasField('initMarginAfter'): orderState.initMarginAfter = decimalMaxString(orderStateProto.initMarginAfter)
|
|
379
|
+
if orderStateProto.HasField('maintMarginAfter'): orderState.maintMarginAfter = decimalMaxString(orderStateProto.maintMarginAfter)
|
|
380
|
+
if orderStateProto.HasField('equityWithLoanAfter'): orderState.equityWithLoanAfter = decimalMaxString(orderStateProto.equityWithLoanAfter)
|
|
381
|
+
if orderStateProto.HasField('commissionAndFees'): orderState.commissionAndFees = orderStateProto.commissionAndFees
|
|
382
|
+
if orderStateProto.HasField('minCommissionAndFees'): orderState.minCommissionAndFees = orderStateProto.minCommissionAndFees
|
|
383
|
+
if orderStateProto.HasField('maxCommissionAndFees'): orderState.maxCommissionAndFees = orderStateProto.maxCommissionAndFees
|
|
384
|
+
if orderStateProto.HasField('commissionAndFeesCurrency'): orderState.commissionAndFeesCurrency = orderStateProto.commissionAndFeesCurrency
|
|
385
|
+
if orderStateProto.HasField('warningText'): orderState.warningText = orderStateProto.warningText
|
|
386
|
+
if orderStateProto.HasField('marginCurrency'): orderState.marginCurrency = orderStateProto.marginCurrency
|
|
387
|
+
if orderStateProto.HasField('initMarginBeforeOutsideRTH'): orderState.initMarginBeforeOutsideRTH = orderStateProto.initMarginBeforeOutsideRTH
|
|
388
|
+
if orderStateProto.HasField('maintMarginBeforeOutsideRTH'): orderState.maintMarginBeforeOutsideRTH = orderStateProto.maintMarginBeforeOutsideRTH
|
|
389
|
+
if orderStateProto.HasField('equityWithLoanBeforeOutsideRTH'): orderState.equityWithLoanBeforeOutsideRTH = orderStateProto.equityWithLoanBeforeOutsideRTH
|
|
390
|
+
if orderStateProto.HasField('initMarginChangeOutsideRTH'): orderState.initMarginChangeOutsideRTH = orderStateProto.initMarginChangeOutsideRTH
|
|
391
|
+
if orderStateProto.HasField('maintMarginChangeOutsideRTH'): orderState.maintMarginChangeOutsideRTH = orderStateProto.maintMarginChangeOutsideRTH
|
|
392
|
+
if orderStateProto.HasField('equityWithLoanChangeOutsideRTH'): orderState.equityWithLoanChangeOutsideRTH = orderStateProto.equityWithLoanChangeOutsideRTH
|
|
393
|
+
if orderStateProto.HasField('initMarginAfterOutsideRTH'): orderState.initMarginAfterOutsideRTH = orderStateProto.initMarginAfterOutsideRTH
|
|
394
|
+
if orderStateProto.HasField('maintMarginAfterOutsideRTH'): orderState.maintMarginAfterOutsideRTH = orderStateProto.maintMarginAfterOutsideRTH
|
|
395
|
+
if orderStateProto.HasField('equityWithLoanAfterOutsideRTH'): orderState.equityWithLoanAfterOutsideRTH = orderStateProto.equityWithLoanAfterOutsideRTH
|
|
396
|
+
if orderStateProto.HasField('suggestedSize'): orderState.suggestedSize = Decimal(orderStateProto.suggestedSize)
|
|
397
|
+
if orderStateProto.HasField('rejectReason'): orderState.rejectReason = orderStateProto.rejectReason
|
|
398
|
+
|
|
399
|
+
orderAllocations = decodeOrderAllocations(orderStateProto)
|
|
400
|
+
if orderAllocations is not None and orderAllocations: orderState.orderAllocations = orderAllocations
|
|
401
|
+
|
|
402
|
+
return orderState
|
|
403
|
+
|
|
404
|
+
@staticmethod
|
|
405
|
+
def decodeOrderAllocations(orderStateProto: OrderStateProto) -> list[OrderAllocation]:
|
|
406
|
+
orderAllocations = []
|
|
407
|
+
orderAllocationProtoList = []
|
|
408
|
+
if orderStateProto.orderAllocations is not None: orderAllocationProtoList = orderStateProto.orderAllocations
|
|
409
|
+
if orderAllocationProtoList:
|
|
410
|
+
for orderAllocationProto in orderAllocationProtoList:
|
|
411
|
+
orderAllocation = OrderAllocation()
|
|
412
|
+
if orderAllocationProto.HasField('account'): orderAllocation.account = orderAllocationProto.account
|
|
413
|
+
if orderAllocationProto.HasField('position'): orderAllocation.position = Decimal(orderAllocationProto.position)
|
|
414
|
+
if orderAllocationProto.HasField('positionDesired'): orderAllocation.positionDesired = Decimal(orderAllocationProto.positionDesired)
|
|
415
|
+
if orderAllocationProto.HasField('positionAfter'): orderAllocation.positionAfter = Decimal(orderAllocationProto.positionAfter)
|
|
416
|
+
if orderAllocationProto.HasField('desiredAllocQty'): orderAllocation.desiredAllocQty = Decimal(orderAllocationProto.desiredAllocQty)
|
|
417
|
+
if orderAllocationProto.HasField('allowedAllocQty'): orderAllocation.allowedAllocQty = Decimal(orderAllocationProto.allowedAllocQty)
|
|
418
|
+
if orderAllocationProto.HasField('isMonetary'): orderAllocation.isMonetary = orderAllocationProto.isMonetary
|
|
419
|
+
orderAllocations.append(orderAllocation)
|
|
420
|
+
return orderAllocations
|
ibapi/enum_implem.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2019 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
|
|
3
|
+
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
Simple enum implementation
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Enum:
|
|
13
|
+
def __init__(self, *args):
|
|
14
|
+
self.idx2name = {}
|
|
15
|
+
for idx, name in enumerate(args):
|
|
16
|
+
setattr(self, name, idx)
|
|
17
|
+
self.idx2name[idx] = name
|
|
18
|
+
|
|
19
|
+
def toStr(self, idx):
|
|
20
|
+
return self.idx2name.get(idx, "NOTFOUND")
|
ibapi/errors.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2023 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
|
|
3
|
+
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
|
|
4
|
+
|
|
5
|
+
This is the interface that will need to be overloaded by the customer so
|
|
6
|
+
that his/her code can receive info from the TWS/IBGW.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CodeMsgPair:
|
|
11
|
+
def __init__(self, code, msg):
|
|
12
|
+
self.errorCode = code
|
|
13
|
+
self.errorMsg = msg
|
|
14
|
+
|
|
15
|
+
def code(self):
|
|
16
|
+
return self.errorCode
|
|
17
|
+
|
|
18
|
+
def msg(self):
|
|
19
|
+
return self.errorMsg
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
ALREADY_CONNECTED = CodeMsgPair(501, "Already connected.")
|
|
23
|
+
CONNECT_FAIL = CodeMsgPair(
|
|
24
|
+
502,
|
|
25
|
+
"""Couldn't connect to TWS. Confirm that \"Enable ActiveX and Socket EClients\"
|
|
26
|
+
is enabled and connection port is the same as \"Socket Port\" on the
|
|
27
|
+
TWS \"Edit->Global Configuration...->API->Settings\" menu. Live Trading ports:
|
|
28
|
+
TWS: 7496; IB Gateway: 4001. Simulated Trading ports for new installations
|
|
29
|
+
of version 954.1 or newer: TWS: 7497; IB Gateway: 4002""",
|
|
30
|
+
)
|
|
31
|
+
UPDATE_TWS = CodeMsgPair(503, "The TWS is out of date and must be upgraded.")
|
|
32
|
+
NOT_CONNECTED = CodeMsgPair(504, "Not connected")
|
|
33
|
+
UNKNOWN_ID = CodeMsgPair(505, "Fatal Error: Unknown message id.")
|
|
34
|
+
UNSUPPORTED_VERSION = CodeMsgPair(506, "Unsupported version")
|
|
35
|
+
BAD_LENGTH = CodeMsgPair(507, "Bad message length")
|
|
36
|
+
BAD_MESSAGE = CodeMsgPair(508, "Bad message")
|
|
37
|
+
SOCKET_EXCEPTION = CodeMsgPair(509, "Exception caught while reading socket - ")
|
|
38
|
+
FAIL_CREATE_SOCK = CodeMsgPair(520, "Failed to create socket")
|
|
39
|
+
SSL_FAIL = CodeMsgPair(530, "SSL specific error: ")
|
|
40
|
+
INVALID_SYMBOL = CodeMsgPair(579, "Invalid symbol in string - ")
|
|
41
|
+
FA_PROFILE_NOT_SUPPORTED = CodeMsgPair(
|
|
42
|
+
585, "FA Profile is not supported anymore, use FA Group instead - "
|
|
43
|
+
)
|
ibapi/execution.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2025 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
|
|
3
|
+
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from ibapi.object_implem import Object
|
|
8
|
+
from ibapi.const import UNSET_DECIMAL
|
|
9
|
+
from ibapi.const import UNSET_INTEGER
|
|
10
|
+
from ibapi.utils import decimalMaxString
|
|
11
|
+
from ibapi.utils import intMaxString
|
|
12
|
+
from ibapi.utils import floatMaxString
|
|
13
|
+
from ibapi.utils import longMaxString
|
|
14
|
+
from ibapi.utils import getEnumTypeName
|
|
15
|
+
from enum import Enum
|
|
16
|
+
|
|
17
|
+
class Execution(Object):
|
|
18
|
+
def __init__(self):
|
|
19
|
+
self.execId = ""
|
|
20
|
+
self.time = ""
|
|
21
|
+
self.acctNumber = ""
|
|
22
|
+
self.exchange = ""
|
|
23
|
+
self.side = ""
|
|
24
|
+
self.shares = UNSET_DECIMAL
|
|
25
|
+
self.price = 0.0
|
|
26
|
+
self.permId = 0
|
|
27
|
+
self.clientId = 0
|
|
28
|
+
self.orderId = 0
|
|
29
|
+
self.liquidation = 0
|
|
30
|
+
self.cumQty = UNSET_DECIMAL
|
|
31
|
+
self.avgPrice = 0.0
|
|
32
|
+
self.orderRef = ""
|
|
33
|
+
self.evRule = ""
|
|
34
|
+
self.evMultiplier = 0.0
|
|
35
|
+
self.modelCode = ""
|
|
36
|
+
self.lastLiquidity = 0
|
|
37
|
+
self.pendingPriceRevision = False
|
|
38
|
+
self.submitter = ""
|
|
39
|
+
self.optExerciseOrLapseType = OptionExerciseType.NoneItem
|
|
40
|
+
|
|
41
|
+
def __str__(self):
|
|
42
|
+
return (
|
|
43
|
+
"ExecId: %s, Time: %s, Account: %s, Exchange: %s, Side: %s, Shares: %s, Price: %s, PermId: %s, "
|
|
44
|
+
"ClientId: %s, OrderId: %s, Liquidation: %s, CumQty: %s, AvgPrice: %s, OrderRef: %s, EvRule: %s, "
|
|
45
|
+
"EvMultiplier: %s, ModelCode: %s, LastLiquidity: %s, PendingPriceRevision: %s, Submitter: %s, OptExerciseOrLapseType: %s"
|
|
46
|
+
% (
|
|
47
|
+
self.execId,
|
|
48
|
+
self.time,
|
|
49
|
+
self.acctNumber,
|
|
50
|
+
self.exchange,
|
|
51
|
+
self.side,
|
|
52
|
+
decimalMaxString(self.shares),
|
|
53
|
+
floatMaxString(self.price),
|
|
54
|
+
longMaxString(self.permId),
|
|
55
|
+
intMaxString(self.clientId),
|
|
56
|
+
intMaxString(self.orderId),
|
|
57
|
+
intMaxString(self.liquidation),
|
|
58
|
+
decimalMaxString(self.cumQty),
|
|
59
|
+
floatMaxString(self.avgPrice),
|
|
60
|
+
self.orderRef,
|
|
61
|
+
self.evRule,
|
|
62
|
+
floatMaxString(self.evMultiplier),
|
|
63
|
+
self.modelCode,
|
|
64
|
+
intMaxString(self.lastLiquidity),
|
|
65
|
+
self.pendingPriceRevision,
|
|
66
|
+
self.submitter,
|
|
67
|
+
getEnumTypeName(OptionExerciseType, self.optExerciseOrLapseType),
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class ExecutionFilter(Object):
|
|
73
|
+
# Filter fields
|
|
74
|
+
def __init__(self):
|
|
75
|
+
self.clientId = 0
|
|
76
|
+
self.acctCode = ""
|
|
77
|
+
self.time = ""
|
|
78
|
+
self.symbol = ""
|
|
79
|
+
self.secType = ""
|
|
80
|
+
self.exchange = ""
|
|
81
|
+
self.side = ""
|
|
82
|
+
self.lastNDays = UNSET_INTEGER
|
|
83
|
+
self.specificDates = None
|
|
84
|
+
|
|
85
|
+
class OptionExerciseType(Enum):
|
|
86
|
+
NoneItem = (-1, "None")
|
|
87
|
+
Exercise = (1, "Exercise")
|
|
88
|
+
Lapse = (2, "Lapse")
|
|
89
|
+
DoNothing = (3, "DoNothing")
|
|
90
|
+
Assigned = (100, "Assigned ")
|
|
91
|
+
AutoexerciseClearing = (101, "AutoexerciseClearing")
|
|
92
|
+
Expired = (102, "Expired")
|
|
93
|
+
Netting = (103, "Netting")
|
|
94
|
+
AutoexerciseTrading = (200, "AutoexerciseTrading")
|
|
95
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (C) 2024 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
|
|
3
|
+
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
Simple class for ineligibility reason
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from ibapi.object_implem import Object
|
|
11
|
+
|
|
12
|
+
class IneligibilityReason(Object):
|
|
13
|
+
def __init__(self, id_: str = None, description: str = None):
|
|
14
|
+
self.id_ = str(id_)
|
|
15
|
+
self.description = str(description)
|
|
16
|
+
|
|
17
|
+
def __str__(self):
|
|
18
|
+
return f"[id: {self.id_}, description: {self.description}];"
|