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.
Files changed (57) hide show
  1. ibapi/__init__.py +16 -0
  2. ibapi/account_summary_tags.py +70 -0
  3. ibapi/client.py +4891 -0
  4. ibapi/client_utils.py +412 -0
  5. ibapi/comm.py +100 -0
  6. ibapi/commission_and_fees_report.py +31 -0
  7. ibapi/common.py +315 -0
  8. ibapi/connection.py +126 -0
  9. ibapi/const.py +12 -0
  10. ibapi/contract.py +265 -0
  11. ibapi/decoder.py +1711 -0
  12. ibapi/decoder_utils.py +420 -0
  13. ibapi/enum_implem.py +20 -0
  14. ibapi/errors.py +43 -0
  15. ibapi/execution.py +95 -0
  16. ibapi/ineligibility_reason.py +18 -0
  17. ibapi/message.py +186 -0
  18. ibapi/news.py +13 -0
  19. ibapi/object_implem.py +12 -0
  20. ibapi/order.py +263 -0
  21. ibapi/order_cancel.py +21 -0
  22. ibapi/order_condition.py +289 -0
  23. ibapi/order_state.py +117 -0
  24. ibapi/orderdecoder.py +539 -0
  25. ibapi/protobuf/CancelOrderRequest_pb2.py +38 -0
  26. ibapi/protobuf/ComboLeg_pb2.py +37 -0
  27. ibapi/protobuf/Contract_pb2.py +39 -0
  28. ibapi/protobuf/DeltaNeutralContract_pb2.py +37 -0
  29. ibapi/protobuf/ErrorMessage_pb2.py +37 -0
  30. ibapi/protobuf/ExecutionDetailsEnd_pb2.py +37 -0
  31. ibapi/protobuf/ExecutionDetails_pb2.py +39 -0
  32. ibapi/protobuf/ExecutionFilter_pb2.py +37 -0
  33. ibapi/protobuf/ExecutionRequest_pb2.py +38 -0
  34. ibapi/protobuf/Execution_pb2.py +37 -0
  35. ibapi/protobuf/GlobalCancelRequest_pb2.py +38 -0
  36. ibapi/protobuf/OpenOrder_pb2.py +40 -0
  37. ibapi/protobuf/OpenOrdersEnd_pb2.py +37 -0
  38. ibapi/protobuf/OrderAllocation_pb2.py +37 -0
  39. ibapi/protobuf/OrderCancel_pb2.py +37 -0
  40. ibapi/protobuf/OrderCondition_pb2.py +37 -0
  41. ibapi/protobuf/OrderState_pb2.py +38 -0
  42. ibapi/protobuf/OrderStatus_pb2.py +37 -0
  43. ibapi/protobuf/Order_pb2.py +51 -0
  44. ibapi/protobuf/PlaceOrderRequest_pb2.py +39 -0
  45. ibapi/protobuf/SoftDollarTier_pb2.py +37 -0
  46. ibapi/reader.py +49 -0
  47. ibapi/scanner.py +77 -0
  48. ibapi/server_versions.py +159 -0
  49. ibapi/softdollartier.py +16 -0
  50. ibapi/tag_value.py +22 -0
  51. ibapi/ticktype.py +117 -0
  52. ibapi/utils.py +233 -0
  53. ibapi/wrapper.py +885 -0
  54. ibapi_stable-10.37.2.dist-info/METADATA +136 -0
  55. ibapi_stable-10.37.2.dist-info/RECORD +57 -0
  56. ibapi_stable-10.37.2.dist-info/WHEEL +5 -0
  57. ibapi_stable-10.37.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,289 @@
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
+ from ibapi import comm
7
+ from ibapi.const import UNSET_DOUBLE
8
+ from ibapi.object_implem import Object
9
+ from ibapi.enum_implem import Enum
10
+ from ibapi.utils import decode
11
+
12
+
13
+ # TODO: add support for Rebate, P/L, ShortableShares conditions
14
+
15
+
16
+ class OrderCondition(Object):
17
+ Price = 1
18
+ Time = 3
19
+ Margin = 4
20
+ Execution = 5
21
+ Volume = 6
22
+ PercentChange = 7
23
+
24
+ def __init__(self, condType):
25
+ self.condType = condType
26
+ self.isConjunctionConnection = True
27
+
28
+ def type(self):
29
+ return self.condType
30
+
31
+ def And(self):
32
+ self.isConjunctionConnection = True
33
+ return self
34
+
35
+ def Or(self):
36
+ self.isConjunctionConnection = False
37
+ return self
38
+
39
+ def decode(self, fields):
40
+ connector = decode(str, fields)
41
+ self.isConjunctionConnection = connector == "a"
42
+
43
+ def make_fields(self):
44
+ return [comm.make_field("a" if self.isConjunctionConnection else "o")]
45
+
46
+ def __str__(self):
47
+ return "<AND>" if self.isConjunctionConnection else "<OR>"
48
+
49
+
50
+ class ExecutionCondition(OrderCondition):
51
+ def __init__(self, secType=None, exch=None, symbol=None):
52
+ OrderCondition.__init__(self, OrderCondition.Execution)
53
+ self.secType = secType
54
+ self.exchange = exch
55
+ self.symbol = symbol
56
+
57
+ def decode(self, fields):
58
+ OrderCondition.decode(self, fields)
59
+ self.secType = decode(str, fields)
60
+ self.exchange = decode(str, fields)
61
+ self.symbol = decode(str, fields)
62
+
63
+ def make_fields(self):
64
+ flds = OrderCondition.make_fields(self) + [
65
+ comm.make_field(self.secType),
66
+ comm.make_field(self.exchange),
67
+ comm.make_field(self.symbol),
68
+ ]
69
+ return flds
70
+
71
+ def __str__(self):
72
+ return (
73
+ "trade occurs for "
74
+ + self.symbol
75
+ + " symbol on "
76
+ + self.exchange
77
+ + " exchange for "
78
+ + self.secType
79
+ + " security type"
80
+ )
81
+
82
+
83
+ class OperatorCondition(OrderCondition):
84
+ def __init__(self, condType=None, isMore=None):
85
+ OrderCondition.__init__(self, condType)
86
+ self.isMore = isMore
87
+
88
+ def valueToString(self) -> str:
89
+ raise NotImplementedError("abstractmethod!")
90
+
91
+ def setValueFromString(self, text: str) -> None:
92
+ raise NotImplementedError("abstractmethod!")
93
+
94
+ def decode(self, fields):
95
+ OrderCondition.decode(self, fields)
96
+ self.isMore = decode(bool, fields)
97
+ text = decode(str, fields)
98
+ self.setValueFromString(text)
99
+
100
+ def make_fields(self):
101
+ return OrderCondition.make_fields(self) + [
102
+ comm.make_field(self.isMore),
103
+ comm.make_field(self.valueToString()),
104
+ ]
105
+
106
+ def __str__(self):
107
+ sb = ">= " if self.isMore else "<= "
108
+ return f" {sb} {self.valueToString()}"
109
+
110
+
111
+ class MarginCondition(OperatorCondition):
112
+ def __init__(self, isMore=None, percent=None):
113
+ OperatorCondition.__init__(self, OrderCondition.Margin, isMore)
114
+ self.percent = percent
115
+
116
+ def decode(self, fields):
117
+ OperatorCondition.decode(self, fields)
118
+
119
+ def make_fields(self):
120
+ flds = OperatorCondition.make_fields(self)
121
+ return flds
122
+
123
+ def valueToString(self) -> str:
124
+ return str(self.percent)
125
+
126
+ def setValueFromString(self, text: str) -> None:
127
+ self.percent = float(text)
128
+
129
+ def __str__(self):
130
+ return f"the margin cushion percent {OperatorCondition.__str__(self)} "
131
+
132
+
133
+ class ContractCondition(OperatorCondition):
134
+ def __init__(self, condType=None, conId=None, exch=None, isMore=None):
135
+ OperatorCondition.__init__(self, condType, isMore)
136
+ self.conId = conId
137
+ self.exchange = exch
138
+
139
+ def decode(self, fields):
140
+ OperatorCondition.decode(self, fields)
141
+ self.conId = decode(int, fields)
142
+ self.exchange = decode(str, fields)
143
+
144
+ def make_fields(self):
145
+ return OperatorCondition.make_fields(self) + [
146
+ comm.make_field(self.conId),
147
+ comm.make_field(self.exchange),
148
+ ]
149
+
150
+ def valueToString(self) -> str:
151
+ # todo
152
+ pass
153
+
154
+ def setValueFromString(self, text: str) -> None:
155
+ # todo
156
+ pass
157
+
158
+ def __str__(self):
159
+ return f"{self.conId} on {self.exchange} is {OperatorCondition.__str__(self)} "
160
+
161
+
162
+ class TimeCondition(OperatorCondition):
163
+ def __init__(self, isMore=None, time=None):
164
+ OperatorCondition.__init__(self, OrderCondition.Time, isMore)
165
+ self.time = time
166
+
167
+ def decode(self, fields):
168
+ OperatorCondition.decode(self, fields)
169
+
170
+ def make_fields(self):
171
+ flds = OperatorCondition.make_fields(self)
172
+ return flds
173
+
174
+ def valueToString(self) -> str:
175
+ return self.time
176
+
177
+ def setValueFromString(self, text: str) -> None:
178
+ self.time = text
179
+
180
+ def __str__(self):
181
+ return f"time is {OperatorCondition.__str__(self)} "
182
+
183
+
184
+ class PriceCondition(ContractCondition):
185
+ TriggerMethodEnum = Enum(
186
+ "Default", # = 0,
187
+ "DoubleBidAsk", # = 1,
188
+ "Last", # = 2,
189
+ "DoubleLast", # = 3,
190
+ "BidAsk", # = 4,
191
+ "N/A1",
192
+ "N/A2",
193
+ "LastBidAsk", # = 7,
194
+ "MidPoint",
195
+ ) # = 8
196
+
197
+ def __init__(
198
+ self, triggerMethod=None, conId=None, exch=None, isMore=None, price=None
199
+ ):
200
+ ContractCondition.__init__(self, OrderCondition.Price, conId, exch, isMore)
201
+ self.price = price
202
+ self.triggerMethod = triggerMethod
203
+
204
+ def decode(self, fields):
205
+ ContractCondition.decode(self, fields)
206
+ self.triggerMethod = decode(int, fields)
207
+
208
+ def make_fields(self):
209
+ flds = ContractCondition.make_fields(self) + [
210
+ comm.make_field(self.triggerMethod),
211
+ ]
212
+ return flds
213
+
214
+ def valueToString(self) -> str:
215
+ return str(self.price)
216
+
217
+ def setValueFromString(self, text: str) -> None:
218
+ self.price = float(text)
219
+
220
+ def __str__(self):
221
+ return (
222
+ f"{PriceCondition.TriggerMethodEnum.toStr(self.triggerMethod)} "
223
+ f"price of {ContractCondition.__str__(self)} "
224
+ )
225
+
226
+
227
+ class PercentChangeCondition(ContractCondition):
228
+ def __init__(self, conId=None, exch=None, isMore=None, changePercent=UNSET_DOUBLE):
229
+ ContractCondition.__init__(
230
+ self, OrderCondition.PercentChange, conId, exch, isMore
231
+ )
232
+ self.changePercent = changePercent
233
+
234
+ def decode(self, fields):
235
+ ContractCondition.decode(self, fields)
236
+
237
+ def make_fields(self):
238
+ flds = ContractCondition.make_fields(self)
239
+ return flds
240
+
241
+ def valueToString(self) -> str:
242
+ return str(self.changePercent)
243
+
244
+ def setValueFromString(self, text: str) -> None:
245
+ self.changePercent = float(text)
246
+
247
+ def __str__(self):
248
+ return f"percent change of {ContractCondition.__str__(self)} "
249
+
250
+
251
+ class VolumeCondition(ContractCondition):
252
+ def __init__(self, conId=None, exch=None, isMore=None, volume=None):
253
+ ContractCondition.__init__(self, OrderCondition.Volume, conId, exch, isMore)
254
+ self.volume = volume
255
+
256
+ def decode(self, fields):
257
+ ContractCondition.decode(self, fields)
258
+
259
+ def make_fields(self):
260
+ flds = ContractCondition.make_fields(self)
261
+ return flds
262
+
263
+ def valueToString(self) -> str:
264
+ return str(self.volume)
265
+
266
+ def setValueFromString(self, text: str) -> None:
267
+ self.volume = int(text)
268
+
269
+ def __str__(self):
270
+ return f"volume of {ContractCondition.__str__(self)} "
271
+
272
+
273
+ def Create(condType):
274
+ cond = None
275
+
276
+ if OrderCondition.Execution == condType:
277
+ cond = ExecutionCondition()
278
+ elif OrderCondition.Margin == condType:
279
+ cond = MarginCondition()
280
+ elif OrderCondition.PercentChange == condType:
281
+ cond = PercentChangeCondition()
282
+ elif OrderCondition.Price == condType:
283
+ cond = PriceCondition()
284
+ elif OrderCondition.Time == condType:
285
+ cond = TimeCondition()
286
+ elif OrderCondition.Volume == condType:
287
+ cond = VolumeCondition()
288
+
289
+ return cond
ibapi/order_state.py ADDED
@@ -0,0 +1,117 @@
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
+ from ibapi.object_implem import Object
7
+ from ibapi.const import UNSET_DOUBLE, UNSET_DECIMAL
8
+ from ibapi.utils import decimalMaxString
9
+ from ibapi.utils import floatMaxString
10
+
11
+ class OrderAllocation(Object):
12
+ def __init__(self):
13
+ self.account = ""
14
+ self.position = UNSET_DECIMAL
15
+ self.positionDesired = UNSET_DECIMAL
16
+ self.positionAfter = UNSET_DECIMAL
17
+ self.desiredAllocQty = UNSET_DECIMAL
18
+ self.allowedAllocQty = UNSET_DECIMAL
19
+ self.isMonetary = False
20
+
21
+ def __str__(self):
22
+ s = ("Account: %s, Position: %s, PositionDesired: %s, PositionAfter: %s, "
23
+ "DesiredAllocQty: %s, AllowedAllocQty: %s, IsMonetary: %s") % (
24
+ str(self.account),
25
+ decimalMaxString(self.position),
26
+ decimalMaxString(self.positionDesired),
27
+ decimalMaxString(self.positionAfter),
28
+ decimalMaxString(self.desiredAllocQty),
29
+ decimalMaxString(self.allowedAllocQty),
30
+ str(self.isMonetary),
31
+ )
32
+ return s
33
+
34
+ class OrderState:
35
+ def __init__(self):
36
+ self.status = ""
37
+
38
+ self.initMarginBefore = ""
39
+ self.maintMarginBefore = ""
40
+ self.equityWithLoanBefore = ""
41
+ self.initMarginChange = ""
42
+ self.maintMarginChange = ""
43
+ self.equityWithLoanChange = ""
44
+ self.initMarginAfter = ""
45
+ self.maintMarginAfter = ""
46
+ self.equityWithLoanAfter = ""
47
+
48
+ self.commissionAndFees = UNSET_DOUBLE # type: float
49
+ self.minCommissionAndFees = UNSET_DOUBLE # type: float
50
+ self.maxCommissionAndFees = UNSET_DOUBLE # type: float
51
+ self.commissionAndFeesCurrency = ""
52
+ self.marginCurrency = ""
53
+ self.initMarginBeforeOutsideRTH = UNSET_DOUBLE # type: float
54
+ self.maintMarginBeforeOutsideRTH = UNSET_DOUBLE # type: float
55
+ self.equityWithLoanBeforeOutsideRTH = UNSET_DOUBLE # type: float
56
+ self.initMarginChangeOutsideRTH = UNSET_DOUBLE # type: float
57
+ self.maintMarginChangeOutsideRTH = UNSET_DOUBLE # type: float
58
+ self.equityWithLoanChangeOutsideRTH = UNSET_DOUBLE # type: float
59
+ self.initMarginAfterOutsideRTH = UNSET_DOUBLE # type: float
60
+ self.maintMarginAfterOutsideRTH = UNSET_DOUBLE # type: float
61
+ self.equityWithLoanAfterOutsideRTH = UNSET_DOUBLE # type: float
62
+ self.suggestedSize = UNSET_DECIMAL
63
+ self.rejectReason = ""
64
+ self.orderAllocations = None
65
+ self.warningText = ""
66
+ self.completedTime = ""
67
+ self.completedStatus = ""
68
+
69
+ def __str__(self):
70
+ s = ("Status: %s, InitMarginBefore: %s, MaintMarginBefore: %s, EquityWithLoanBefore: %s, "
71
+ "InitMarginChange: %s, MaintMarginChange: %s, EquityWithLoanChange: %s, "
72
+ "InitMarginAfter: %s, MaintMarginAfter: %s, EquityWithLoanAfter: %s, "
73
+ "CommissionAndFees: %s, MinCommissionAndFees: %s, MaxCommissionAndFees: %s, CommissionAndFeesCurrency: %s, MarginCurrency: %s, "
74
+ "InitMarginBeforeOutsideRTH: %s, MaintMarginBeforeOutsideRTH: %s, EquityWithLoanBeforeOutsideRTH: %s, "
75
+ "InitMarginChangeOutsideRTH: %s, MaintMarginChangeOutsideRTH: %s, equityWithLoanChangeOutsideRTH: %s, "
76
+ "InitMarginAfterOutsideRTH: %s, MaintMarginAfterOutsideRTH: %s, equityWithLoanAfterOutsideRTH: %s, "
77
+ "SuggestedSize: %s, RejectReason: %s, WarningText: %s, CompletedTime: %s, CompletedStatus: %s") % (
78
+ str(self.status),
79
+ str(self.initMarginBefore),
80
+ str(self.maintMarginBefore),
81
+ str(self.equityWithLoanBefore),
82
+ str(self.initMarginChange),
83
+ str(self.maintMarginChange),
84
+ str(self.equityWithLoanChange),
85
+ str(self.initMarginAfter),
86
+ str(self.maintMarginAfter),
87
+ str(self.equityWithLoanAfter),
88
+ floatMaxString(self.commissionAndFees),
89
+ floatMaxString(self.minCommissionAndFees),
90
+ floatMaxString(self.maxCommissionAndFees),
91
+ str(self.commissionAndFeesCurrency),
92
+ str(self.marginCurrency),
93
+ floatMaxString(self.initMarginBeforeOutsideRTH),
94
+ floatMaxString(self.maintMarginBeforeOutsideRTH),
95
+ floatMaxString(self.equityWithLoanBeforeOutsideRTH),
96
+ floatMaxString(self.initMarginChangeOutsideRTH),
97
+ floatMaxString(self.maintMarginChangeOutsideRTH),
98
+ floatMaxString(self.equityWithLoanChangeOutsideRTH),
99
+ floatMaxString(self.initMarginAfterOutsideRTH),
100
+ floatMaxString(self.maintMarginAfterOutsideRTH),
101
+ floatMaxString(self.equityWithLoanAfterOutsideRTH),
102
+ decimalMaxString(self.suggestedSize),
103
+ str(self.rejectReason),
104
+ str(self.warningText),
105
+ str(self.completedTime),
106
+ str(self.completedStatus),
107
+ )
108
+
109
+
110
+ if self.orderAllocations:
111
+ s += " OrderAllocations("
112
+ for orderAllocation in self.orderAllocations:
113
+ s += str(orderAllocation) + "; "
114
+ s += ")"
115
+
116
+ return s
117
+