diff --git a/roboquant/__init__.py b/roboquant/__init__.py index 39881b9..0aeb441 100644 --- a/roboquant/__init__.py +++ b/roboquant/__init__.py @@ -2,7 +2,7 @@ The `roboquant` package contains the `run` method and shared classes like `Account`, `Asset` and `Event`. """ -__version__ = "0.9.3" +__version__ = "0.9.4" import logging diff --git a/roboquant/account.py b/roboquant/account.py index 80ff63c..b6d9adf 100644 --- a/roboquant/account.py +++ b/roboquant/account.py @@ -83,7 +83,7 @@ def long_positions(self) -> dict[Asset, Position]: return {symbol: position for (symbol, position) in self.positions.items() if position.is_long} def contract_value(self, asset: Asset, size: Decimal, price: float) -> float: - """Contract value denoted in the base currency of hte account""" + """Contract value denoted in the base currency of the account""" return asset.contract_amount(size, price).convert_to(self.base_currency, self.last_update) def equity(self) -> Wallet: @@ -110,11 +110,11 @@ def unrealized_pnl(self) -> Wallet: def required_buying_power(self, order: Order) -> Amount: """Return the amount of buying power required for a certain order. The underlying logic takes into - account that a reduction is position size doesn't require buying power. + account that a reduction in position size doesn't require buying power. """ pos_size = self.get_position_size(order.asset) - # only additional required if remaining order size would increase position size + # only buying power required if the remaining order size increases the position size if abs(pos_size + order.remaining) > abs(pos_size): return order.asset.contract_amount(abs(order.remaining), order.limit) diff --git a/roboquant/brokers/broker.py b/roboquant/brokers/broker.py index 4cab6d1..ab52c78 100644 --- a/roboquant/brokers/broker.py +++ b/roboquant/brokers/broker.py @@ -39,39 +39,6 @@ def sync(self, event: Event | None = None) -> Account: ... -class BaseBroker(Broker): - """A broker accepts orders and communicates its state through the account object""" - - @abstractmethod - def place_orders(self, orders: list[Order]): - """ - Place zero or more orders at this broker. - - The following logic applies: - - - If the order doesn't yet have an `id`, it is considered to be a new order and will get assigned a new id. - - If the order has an `id` and its `size` is zero, it is a cancellation order of an existing order with the same id. - - If the order has an `id` and its `size` is non-zero, it is an update order of an existing order with the same id. - - Args: - orders: The orders to be placed. - """ - ... - - @abstractmethod - def sync(self, event: Event | None = None) -> Account: - """Sync the state, and return an updated account to reflect the latest state. - - Args: - event: optional the latest event. - - Returns: - The latest account object. - - """ - ... - - def _update_account(account: Account, event: Event | None, price_type: str = "DEFAULT"): if not event: diff --git a/roboquant/brokers/ibkr.py b/roboquant/brokers/ibkr.py index 2d13c9b..89611b4 100644 --- a/roboquant/brokers/ibkr.py +++ b/roboquant/brokers/ibkr.py @@ -114,8 +114,8 @@ class IBKRBroker(LiveBroker): port By default, TWS uses socket port 7496 for live sessions and 7497 for paper sessions. - IB Gateway by contrast uses 4001 for live sessions and 4002 for paper sessions. - However these are just defaults, and can be modified as desired. + IB Gateway, by contrast, uses 4001 for live sessions and 4002 for paper sessions. + However, these are just defaults, and can be modified as desired. client_id The client id to use to connect to TWS or IB Gateway. @@ -143,7 +143,7 @@ def use_tws(cls, client_id=123): return cls("127.0.0.1", 7497, client_id) @classmethod - def use_ibgateway(cls, client_id=123): + def use_gateway(cls, client_id=123): """Return a broker connected to a IB Gateway papertrade instance with its default port (4002) settings""" return cls("127.0.0.1", 4002, client_id) @@ -212,7 +212,7 @@ def __update_ibkr_object(obj, update): logger.warning("unknown field name=%s value=%s", name, value) def _get_contract(self, order: Order) -> Contract: - """Map an order to a IBKR contract.""" + """Map an order to an IBKR contract.""" c = self.contract_mapping.get(order.asset) @@ -229,7 +229,7 @@ def _get_contract(self, order: Order) -> Contract: return c def _get_order(self, order: Order) -> IBKROrder: - """Map an order to a IBKR order.""" + """Map an order to an IBKR order.""" o = IBKROrder() o.action = "BUY" if order.is_buy else "SELL" o.totalQuantity = abs(order.size) diff --git a/roboquant/event.py b/roboquant/event.py index 262c802..e315271 100644 --- a/roboquant/event.py +++ b/roboquant/event.py @@ -131,8 +131,9 @@ def volume(self, volume_type: str = "DEFAULT") -> float: class Event: """ An event represents zero of items of information happening at a certain moment in time. - An item can contain any type of information, but the most common use-case are price-items like quotes, trades or bars. - Time is always a datetime object with the timezone set at UTC. + + - `Event.time` is a datetime object with the timezone set at UTC. + - An item can be any type of object. But the most common use-case are price-items like quotes, trades or bars. """ def __init__(self, dt: datetime, items: list[Any]):