Skip to content

Commit 3028409

Browse files
authored
Update Stable to 10.37.02
2 parents a1e8853 + 870c50b commit 3028409

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2834
-547
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ How the code is organized:
140140
* *Decoder*: knows how to take a low level message and decode into high level message
141141
* *Client*:
142142
+ knows to send requests
143-
+ has the message loop which takes low level messages from Queue and uses Decoder to tranform into high level message with which it then calls the corresponding Wrapper method
143+
+ has the message loop which takes low level messages from Queue and uses Decoder to transform into high level message with which it then calls the corresponding Wrapper method
144144
* *Wrapper*: class that needs to be subclassed by the user so that it can get the incoming messages
145145

146146

@@ -163,7 +163,7 @@ The info/data flow is:
163163

164164
Implementation notes:
165165

166-
* the *Decoder* has two ways of handling a message (esentially decoding the fields)
166+
* the *Decoder* has two ways of handling a message (essentially decoding the fields)
167167
+ some message very neatly map to a function call; meaning that the number of fields and order are the same as the method parameters. For example: Wrapper.tickSize(). In this case a simple mapping is made between the incoming msg id and the Wrapper method:
168168

169169
IN.TICK_SIZE: HandleInfo(wrap=Wrapper.tickSize),

ibapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
""" Package implementing the Python API for the TWS/IB Gateway """
77

8-
VERSION = {"major": 10, "minor": 30, "micro": 1}
8+
VERSION = {"major": 10, "minor": 37, "micro": 2}
99

1010

1111
def get_version_string():

ibapi/client.py

Lines changed: 607 additions & 356 deletions
Large diffs are not rendered by default.

ibapi/client_utils.py

Lines changed: 412 additions & 0 deletions
Large diffs are not rendered by default.

ibapi/comm.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (C) 2019 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
2+
Copyright (C) 2025 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
33
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
44
55
This module has tools for implementing the IB low level messaging.
@@ -16,10 +16,24 @@
1616

1717
logger = logging.getLogger(__name__)
1818

19+
def make_msg_proto(msgId: int, protobufData: bytes) -> bytes:
20+
"""adds the length prefix"""
21+
byteArray = msgId.to_bytes(4, 'big') + protobufData
22+
msg = struct.pack(f"!I{len(byteArray)}s", len(byteArray), byteArray)
23+
return msg
1924

20-
def make_msg(text) -> bytes:
25+
def make_msg(msgId:int, useRawIntMsgId: bool, text: str) -> bytes:
2126
"""adds the length prefix"""
27+
if useRawIntMsgId:
28+
text = msgId.to_bytes(4, 'big') + str.encode(text)
29+
else:
30+
text = str.encode(make_field(msgId) + text)
2231

32+
msg = struct.pack(f"!I{len(text)}s", len(text), text)
33+
return msg
34+
35+
def make_initial_msg(text: str) -> bytes:
36+
"""adds the length prefix"""
2337
msg = struct.pack(f"!I{len(text)}s", len(text), str.encode(text))
2438
return msg
2539

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
from ibapi.object_implem import Object
7+
from ibapi.utils import intMaxString
8+
from ibapi.utils import floatMaxString
9+
10+
11+
class CommissionAndFeesReport(Object):
12+
def __init__(self):
13+
self.execId = ""
14+
self.commissionAndFees = 0.0
15+
self.currency = ""
16+
self.realizedPNL = 0.0
17+
self.yield_ = 0.0
18+
self.yieldRedemptionDate = 0 # YYYYMMDD format
19+
20+
def __str__(self):
21+
return (
22+
"ExecId: %s, CommissionAndFees: %s, Currency: %s, RealizedPnL: %s, Yield: %s, YieldRedemptionDate: %s"
23+
% (
24+
self.execId,
25+
floatMaxString(self.commissionAndFees),
26+
self.currency,
27+
floatMaxString(self.realizedPNL),
28+
floatMaxString(self.yield_),
29+
intMaxString(self.yieldRedemptionDate),
30+
)
31+
)

ibapi/common.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (C) 2023 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
2+
Copyright (C) 2025 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
33
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
44
"""
55

@@ -8,6 +8,11 @@
88
from ibapi.enum_implem import Enum
99
from ibapi.object_implem import Object
1010
from ibapi.utils import floatMaxString, decimalMaxString, intMaxString
11+
from ibapi.message import OUT
12+
from ibapi.server_versions import (
13+
MIN_SERVER_VER_PROTOBUF,
14+
MIN_SERVER_VER_PROTOBUF_PLACE_ORDER
15+
)
1116

1217
TickerId = int
1318
OrderId = int
@@ -37,6 +42,13 @@
3742
ListOfHistoricalTickLast = list
3843
ListOfHistoricalSessions = list
3944

45+
PROTOBUF_MSG_ID = 200
46+
PROTOBUF_MSG_IDS = {
47+
OUT.REQ_EXECUTIONS : MIN_SERVER_VER_PROTOBUF,
48+
OUT.PLACE_ORDER : MIN_SERVER_VER_PROTOBUF_PLACE_ORDER,
49+
OUT.CANCEL_ORDER : MIN_SERVER_VER_PROTOBUF_PLACE_ORDER,
50+
OUT.REQ_GLOBAL_CANCEL : MIN_SERVER_VER_PROTOBUF_PLACE_ORDER
51+
}
4052

4153
class BarData(Object):
4254
def __init__(self):

ibapi/connection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (C) 2019 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
2+
Copyright (C) 2024 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
33
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
44
"""
55

@@ -15,6 +15,7 @@
1515
from ibapi.errors import FAIL_CREATE_SOCK
1616
from ibapi.errors import CONNECT_FAIL
1717
from ibapi.const import NO_VALID_ID
18+
from ibapi.utils import currentTimeMillis
1819

1920
# TODO: support SSL !!
2021

@@ -36,14 +37,14 @@ def connect(self):
3637
except socket.error:
3738
if self.wrapper:
3839
self.wrapper.error(
39-
NO_VALID_ID, FAIL_CREATE_SOCK.code(), FAIL_CREATE_SOCK.msg()
40+
NO_VALID_ID, currentTimeMillis(), FAIL_CREATE_SOCK.code(), FAIL_CREATE_SOCK.msg()
4041
)
4142

4243
try:
4344
self.socket.connect((self.host, self.port))
4445
except socket.error:
4546
if self.wrapper:
46-
self.wrapper.error(NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg())
47+
self.wrapper.error(NO_VALID_ID, currentTimeMillis(), CONNECT_FAIL.code(), CONNECT_FAIL.msg())
4748

4849
self.socket.settimeout(1) # non-blocking
4950

ibapi/contract.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""
2-
Copyright (C) 2024 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
2+
Copyright (C) 2025 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
33
and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable.
44
"""
55

66
from ibapi.object_implem import Object
7-
from ibapi.const import UNSET_DECIMAL
7+
from ibapi.const import UNSET_DECIMAL, UNSET_DOUBLE
8+
89
from ibapi.utils import intMaxString
910
from ibapi.utils import floatMaxString
1011
from ibapi.utils import decimalMaxString
@@ -65,7 +66,7 @@ def __init__(self):
6566
self.secType = ""
6667
self.lastTradeDateOrContractMonth = ""
6768
self.lastTradeDate = ""
68-
self.strike = 0.0 # float !!
69+
self.strike = UNSET_DOUBLE # float !!
6970
self.right = ""
7071
self.multiplier = ""
7172
self.exchange = ""
@@ -88,13 +89,15 @@ def __init__(self):
8889
self.deltaNeutralContract = None
8990

9091
def __str__(self):
91-
s = ",".join(
92-
(
93-
str(self.conId),
92+
s = (
93+
"ConId: %s, Symbol: %s, SecType: %s, LastTradeDateOrContractMonth: %s, Strike: %s, Right: %s, Multiplier: %s, Exchange: %s, PrimaryExchange: %s, "
94+
"Currency: %s, LocalSymbol: %s, TradingClass: %s, IncludeExpired: %s, SecIdType: %s, SecId: %s, Description: %s, "
95+
"IssuerId: %s"
96+
% (
97+
intMaxString(self.conId),
9498
str(self.symbol),
9599
str(self.secType),
96100
str(self.lastTradeDateOrContractMonth),
97-
str(self.lastTradeDate),
98101
floatMaxString(self.strike),
99102
str(self.right),
100103
str(self.multiplier),
@@ -110,7 +113,7 @@ def __str__(self):
110113
str(self.issuerId),
111114
)
112115
)
113-
s += "combo:" + self.comboLegsDescrip
116+
s += "Combo:" + self.comboLegsDescrip
114117

115118
if self.comboLegs:
116119
for leg in self.comboLegs:
@@ -260,19 +263,3 @@ class FundDistributionPolicyIndicator(Enum):
260263
NoneItem = ("None", "None")
261264
AccumulationFund = ("N", "Accumulation Fund")
262265
IncomeFund = ("Y", "Income Fund")
263-
264-
def listOfValues(cls):
265-
return list(map(lambda c: c, cls))
266-
267-
def getEnumTypeFromString(cls, stringIn):
268-
for item in cls:
269-
if item.value[0] == stringIn:
270-
return item
271-
return listOfValues(cls)[0]
272-
273-
def getEnumTypeName(cls, valueIn):
274-
for item in cls:
275-
if item == valueIn:
276-
return item.value[1]
277-
return listOfValues(cls)[0].value[1]
278-

0 commit comments

Comments
 (0)