Positions

Fetching Positions

Retrieve a list of positions with optional filters using the get_positions() method:

positions = client.get_positions(
    instrument_id=instrument_id,
    instrument_name=instrument_name,
    instrument_type=instrument_type,
    strike_price=strike_price,
    expiration_timestamp=expiration_timestamp,
    option_type=option_type,
    limit=limit,
    offset=offset
)

Parameters:

Same as get_trades() method.

The returned list contains Position objects with the following attributes:

  • instrument: The instrument associated with the position, as an Instrument object
  • position: The position, as a float
  • average_entry_price: The average entry price of the position, as a float
  • created_at: The timestamp when the position was created, as a string

Closing a Position

Close a position by providing either the instrument ID or the instrument name using the close_position() method:

close_status = client.close_position(instrument_id=instrument_id, instrument_name=instrument_name)

Parameters:

  • instrument_id (Optional[int]): The ID of the instrument to close the position for (default is None)
  • instrument_name (Optional[str]): The name of the instrument to close the position for (default is None)

Note: Either instrument_id or instrument_name must be provided, but not both.

The returned status is a dictionary containing a status code and a message confirming the position closure:

  • status: The status code of the position closure, as an int
  • message: The message confirming the position closure, as a string