Skip to main content
Version: latest

Model

The model subpackage defines a rich trading domain model.

The domain model is agnostic of any system design, seeking to represent the logic and state transitions of trading in a generic way. Many system implementations could be built around this domain model.

class AccountBalance

Bases: object

AccountBalance(Money total, Money locked, Money free) -> None Represents an account balance denominated in a particular currency.

  • Parameters:
    • total (Money) – The total account balance.
    • locked (Money) – The account balance locked (assigned to pending orders).
    • free (Money) – The account balance free for trading.
  • Raises:
    • ValueError – If money currencies are not equal.
    • ValueError – If any money is negative (< 0).
    • ValueError – If total - locked != free.

currency

The currency of the account.

  • Returns: Currency

free

The account balance free for trading.

  • Returns: Money

static from_dict(dict values) → AccountBalance

Return an account balance from the given dict values.

  • Parameters: values (dict *[*str , object ]) – The values for initialization.
  • Return type: AccountBalance

locked

The account balance locked (assigned to pending orders).

  • Returns: Money

to_dict(self) → dict

Return a dictionary representation of this object.

  • Return type: dict[str, object]

total

The total account balance.

  • Returns: Money

class AccountId

Bases: Identifier

AccountId(str value) -> None Represents a valid account ID.

Must be correctly formatted with two valid strings either side of a hyphen. It is expected an account ID is the name of the issuer with an account number separated by a hyphen.

Example: “IB-D02851908”.

  • Parameters: value (str) – The account ID value.
  • Raises: ValueError – If value is not a valid string containing a hyphen.

WARNING

The issuer and number ID combination must be unique at the firm level.

get_id(self) → str

Return the account ID without issuer name.

  • Return type: str

get_issuer(self) → str

Return the account issuer for this ID.

  • Return type: str

class Bar

Bases: Data

Bar(BarType bar_type, Price open, Price high, Price low, Price close, Quantity volume, uint64_t ts_event, uint64_t ts_init, bool is_revision=False) -> None Represents an aggregated bar.

  • Parameters:
    • bar_type (BarType) – The bar type for this bar.
    • open (Price) – The bars open price.
    • high (Price) – The bars high price.
    • low (Price) – The bars low price.
    • close (Price) – The bars close price.
    • volume (Quantity) – The bars volume.
    • ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the data event occurred.
    • ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the data object was initialized.
    • is_revision (bool , default False) – If this bar is a revision of a previous bar with the same ts_event.
  • Raises:
    • ValueError – If high is not >= low.
    • ValueError – If high is not >= close.
    • ValueError – If low is not <= close.

bar_type

BarType Return the bar type of bar.

  • Return type: BarType
  • Type: Bar.bar_type

close

Price Return the close price of the bar.

  • Return type: Price
  • Type: Bar.close

static from_dict(dict values) → Bar

Return a bar parsed from the given values.

  • Parameters: values (dict *[*str , object ])