Objects

Defines fundamental value objects for the trading domain.

class AccountBalance ( Money total , Money locked , Money free )

Bases: object

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.

Returns :

AccountBalance

locked

The account balance locked (assigned to pending orders).

Returns :

Money

to_dict ( self ) dict

Return a dictionary representation of this object.

Returns :

dict[str, object]

total

The total account balance.

Returns :

Money

class MarginBalance ( Money initial , Money maintenance , InstrumentId instrument_id=None )

Bases: object

Represents a margin balance optionally associated with a particular instrument.

Parameters :
  • initial ( Money ) – The initial (order) margin requirement for the instrument.

  • maintenance ( Money ) – The maintenance (position) margin requirement for the instrument.

  • instrument_id ( InstrumentId , optional ) – The instrument ID associated with the margin.

Raises :
  • ValueError – If margin_init currency does not equal currency .

  • ValueError – If margin_maint currency does not equal currency .

  • ValueError – If any margin is negative (< 0).

currency

The currency of the margin.

Returns :

Currency

static from_dict ( dict values ) MarginBalance

Return a margin balance from the given dict values.

Parameters :

values ( dict [ str , object ] ) – The values for initialization.

Returns :

MarginAccountBalance

initial

The initial margin requirement.

Returns :

Money

instrument_id

The instrument ID associated with the margin.

Returns :

InstrumentId or None

maintenance

The maintenance margin requirement.

Returns :

Money

to_dict ( self ) dict

Return a dictionary representation of this object.

Returns :

dict[str, object]

class Money ( value , Currency currency )

Bases: object

Represents an amount of money in a specified currency denomination.

  • MONEY_MAX = 9_223_372_036

  • MONEY_MIN = -9_223_372_036

Parameters :
  • value ( integer , float , string or Decimal ) – The amount of money in the currency denomination.

  • currency ( Currency ) – The currency of the money.

Raises :
  • ValueError – If value is greater than 9_223_372_036.

  • ValueError – If value is less than -9_223_372_036.

as_decimal ( self )

Return the value as a built-in Decimal .

Returns :

Decimal

as_double ( self ) double

Return the value as a double .

Returns :

double

static from_raw ( uint64_t raw , uint8_t precision )
static from_str ( unicode value ) Money

Return money parsed from the given string.

Must be correctly formatted with a value and currency separated by a whitespace delimiter.

Example: “1000000.00 USD”.

Parameters :

value ( str ) – The value to parse.

Returns :

Money

Raises :
  • ValueError – If inferred currency precision is greater than 9.

  • OverflowError – If inferred currency precision is negative (< 0).

to_str ( self ) unicode

Return the formatted string representation of the money.

Returns :

str

class Price ( double value , uint8_t precision )

Bases: object

Represents a price in a financial market.

The number of decimal places may vary. For certain asset classes, prices may have negative values. For example, prices for options instruments can be negative under certain conditions.

Handles up to 9 decimals of precision.

  • PRICE_MAX = 9_223_372_036

  • PRICE_MIN = -9_223_372_036

Parameters :
  • value ( integer , float , string or Decimal ) – The value of the price.

  • precision ( uint8 ) – The precision for the price. Use a precision of 0 for whole numbers (no fractional units).

Raises :
  • ValueError – If value is greater than 9_223_372_036.

  • ValueError – If value is less than -9_223_372_036.

  • ValueError – If precision is greater than 9.

  • OverflowError – If precision is negative (< 0).

References

https://www.onixs.biz/fix-dictionary/5.0.SP2/index.html#Price

as_decimal ( self )

Return the value as a built-in Decimal .

Returns :

Decimal

as_double ( self ) double

Return the value as a double .

Returns :

double

static from_int ( int value ) Price

Return a price from the given integer value.

A precision of zero will be inferred.

Parameters :

value ( int ) – The value for the price.

Returns :

Price

static from_raw ( int64_t raw , uint8_t precision )
static from_str ( unicode value ) Price

Return a price parsed from the given string.

Handles up to 9 decimals of precision.

Parameters :

value ( str ) – The value to parse.

Returns :

Price

Warning

The decimal precision will be inferred from the number of digits following the ‘.’ point (if no point then precision zero).

Raises :
  • ValueError – If inferred precision is greater than 9.

  • OverflowError – If inferred precision is negative (< 0).

precision

Return the precision for the price.

Returns :

uint8

static raw_to_f64 ( raw ) float
class Quantity ( double value , uint8_t precision )

Bases: object

Represents a quantity with a non-negative value.

Capable of storing either a whole number (no decimal places) of ‘contracts’ or ‘shares’ (instruments denominated in whole units) or a decimal value containing decimal places for instruments denominated in fractional units.

Handles up to 9 decimals of precision.

  • QUANTITY_MAX = 18_446_744_073

  • QUANTITY_MIN = 0

Parameters :
  • value ( integer , float , string , Decimal ) – The value of the quantity.

  • precision ( uint8 ) – The precision for the quantity. Use a precision of 0 for whole numbers (no fractional units).

Raises :
  • ValueError – If value is greater than 18_446_744_073.

  • ValueError – If value is negative (< 0).

  • ValueError – If precision is greater than 9.

  • OverflowError – If precision is negative (< 0).

References

https://www.onixs.biz/fix-dictionary/5.0.SP2/index.html#Qty

as_decimal ( self )

Return the value as a built-in Decimal .

Returns :

Decimal

as_double ( self ) double

Return the value as a double .

Returns :

double

static from_int ( int value ) Quantity

Return a quantity from the given integer value.

A precision of zero will be inferred.

Parameters :

value ( int ) – The value for the quantity.

Returns :

Quantity

static from_raw ( uint64_t raw , uint8_t precision )
static from_str ( unicode value ) Quantity

Return a quantity parsed from the given string.

Handles up to 9 decimals of precision.

Parameters :

value ( str ) – The value to parse.

Returns :

Quantity

Raises :
  • ValueError – If inferred precision is greater than 9.

  • OverflowError – If inferred precision is negative (< 0).

Warning

The decimal precision will be inferred from the number of digits following the ‘.’ point (if no point then precision zero).

precision

Return the precision for the quantity.

Returns :

uint8

static raw_to_f64 ( raw ) float
to_str ( self ) unicode

Return the formatted string representation of the quantity.

Returns :

str

static zero ( uint8_t precision=0 ) Quantity

Return a quantity with a value of zero.

precision uint8, default 0

The precision for the quantity.

Returns :

Quantity

Raises :
  • ValueError – If precision is greater than 9.

  • OverflowError – If precision is negative (< 0).

Warning

The default precision is zero.