Skip to content

Commit

Permalink
Improved doc and removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Aug 24, 2024
1 parent 0211c0c commit c3e9743
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 44 deletions.
2 changes: 1 addition & 1 deletion roboquant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions roboquant/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
33 changes: 0 additions & 33 deletions roboquant/brokers/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions roboquant/brokers/ibkr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions roboquant/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down

0 comments on commit c3e9743

Please sign in to comment.