Skip to content

Commit 88c48d8

Browse files
committed
Refactor minor style formatting in places
okay, also sneaks in a missing global object for importing elsewhere, but it's a minor feature nobody is using yet.
1 parent e88ffd0 commit 88c48d8

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

ib_async/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
OrderComboLeg,
9494
OrderCondition,
9595
OrderState,
96+
OrderStateNumeric,
9697
OrderStatus,
9798
PercentChangeCondition,
9899
PriceCondition,

ib_async/contract.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,13 @@ def __hash__(self) -> int:
180180

181181
def __repr__(self):
182182
attrs = util.dataclassNonDefaults(self)
183+
183184
if self.__class__ is not Contract:
184185
attrs.pop("secType", "")
186+
185187
clsName = self.__class__.__qualname__
186188
kwargs = ", ".join(f"{k}={v!r}" for k, v in attrs.items())
189+
187190
return f"{clsName}({kwargs})"
188191

189192
__str__ = __repr__

ib_async/ib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
LimitOrder,
4949
Order,
5050
OrderState,
51+
OrderStateNumeric,
5152
OrderStatus,
5253
StopOrder,
5354
Trade,
@@ -1458,9 +1459,11 @@ def reqTickByTickData(
14581459
"""
14591460
reqId = self.client.getReqId()
14601461
ticker = self.wrapper.startTicker(reqId, contract, tickType)
1462+
14611463
self.client.reqTickByTickData(
14621464
reqId, contract, tickType, numberOfTicks, ignoreSize
14631465
)
1466+
14641467
return ticker
14651468

14661469
def cancelTickByTickData(self, contract: Contract, tickType: str) -> bool:

ib_async/order.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import dataclasses
6+
67
from dataclasses import dataclass, field
78
from decimal import Decimal
89
from typing import ClassVar, NamedTuple
@@ -418,6 +419,7 @@ class Trade:
418419
log: list[TradeLogEntry] = field(default_factory=list)
419420
advancedError: str = ""
420421

422+
# TODO: replace these with an enum?
421423
events: ClassVar = (
422424
"statusEvent",
423425
"modifyEvent",

ib_async/wrapper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def connectionClosed(self):
327327
for future in self._futures.values():
328328
if not future.done():
329329
future.set_exception(error)
330+
330331
globalErrorEvent.emit(error)
331332
self.reset()
332333

@@ -338,8 +339,10 @@ def startReq(self, key, contract=None, container=None):
338339
future: asyncio.Future = asyncio.Future()
339340
self._futures[key] = future
340341
self._results[key] = container if container is not None else []
342+
341343
if contract:
342344
self._reqId2Contract[key] = contract
345+
343346
return future
344347

345348
def _endReq(self, key, result=None, success=True):
@@ -352,6 +355,7 @@ def _endReq(self, key, result=None, success=True):
352355
if future:
353356
if result is None:
354357
result = self._results.pop(key, [])
358+
355359
if not future.done():
356360
if success:
357361
future.set_result(result)
@@ -517,9 +521,11 @@ def position(
517521
position = Position(account, contract, posSize, avgCost)
518522
positions = self.positions[account]
519523

524+
# if this updates position to 0 quantity, remove the position
520525
if posSize == 0:
521526
positions.pop(contract.conId, None)
522527
else:
528+
# else, add or replace the position in-place
523529
positions[contract.conId] = position
524530

525531
self._logger.info(f"position: {position}")
@@ -1093,6 +1099,7 @@ def tickByTickBidAsk(
10931099
tick = TickByTickBidAsk(
10941100
self.lastTime, bidPrice, askPrice, bidSize, askSize, tickAttribBidAsk
10951101
)
1102+
10961103
ticker.tickByTicks.append(tick)
10971104
self.pendingTickers.add(ticker)
10981105

0 commit comments

Comments
 (0)