Models
High-level Pythonic models for API requests and responses.
Request Models
Request for placing a new order.
NewOrderRequest
Bases: FrozenModel
Request to place a new order.
Attributes:
| Name | Type | Description |
|---|---|---|
symbol_id |
int
|
Symbol to trade. |
side |
OrderSide
|
Order direction (BUY/SELL). |
volume |
int
|
Volume in cents. Will yield lots = volume / symbol.lot_size |
order_type |
OrderType
|
Type of order. |
limit_price |
Decimal | None
|
Limit price for LIMIT/STOP_LIMIT orders. |
stop_price |
Decimal | None
|
Stop trigger price for STOP/STOP_LIMIT orders. |
stop_loss |
Decimal | None
|
Stop loss price. |
take_profit |
Decimal | None
|
Take profit price. |
time_in_force |
TimeInForce
|
Order duration type. |
expiration_timestamp |
datetime | None
|
Expiration for GTD orders. |
position_id |
int | None
|
Position ID to close (for closing orders). |
client_order_id |
str
|
User-defined order ID. |
label |
str
|
User-defined label (max 100 chars). |
comment |
str
|
User-defined comment (max 256 chars). |
base_slippage_price |
Decimal | None
|
Base price for slippage calculation. |
slippage_in_points |
int | None
|
Max allowed slippage. |
guaranteed_stop_loss |
bool
|
Enable guaranteed stop loss. |
relative_stop_loss |
Decimal | None
|
Stop loss distance in price units. |
relative_take_profit |
Decimal | None
|
Take profit distance in price units. |
trailing_stop_loss |
bool
|
Enable trailing stop loss. |
stop_trigger_method |
StopTriggerMethod | None
|
How to trigger stop orders. |
to_proto(account_id)
Convert to proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_id
|
int
|
The trading account ID. |
required |
Returns:
| Type | Description |
|---|---|
ProtoOANewOrderReq
|
Proto request message. |
Example:
from ctrader_api_client import NewOrderRequest, OrderSide, OrderType, TimeInForce
# Get symbol for volume conversion
symbol = await client.symbols.get_by_id(account_id, 270)
# Market order
market_order = NewOrderRequest(
symbol_id=270,
order_type=OrderType.MARKET,
side=OrderSide.BUY,
volume=symbol.lots_to_volume(0.01), # 0.01 lots
)
# Limit order with SL/TP
limit_order = NewOrderRequest(
symbol_id=270,
order_type=OrderType.LIMIT,
side=OrderSide.BUY,
volume=symbol.lots_to_volume(0.1),
limit_price=5000.0,
stop_loss=4950.0,
take_profit=5100.0,
time_in_force=TimeInForce.GOOD_TILL_CANCEL,
)
# Order with relative SL/TP (distance from entry price)
relative_order = NewOrderRequest(
symbol_id=270,
order_type=OrderType.MARKET,
side=OrderSide.BUY,
volume=symbol.lots_to_volume(0.1),
relative_stop_loss=50.0, # 50 price units below entry
relative_take_profit=100.0, # 100 price units above entry
)
# Stop order
stop_order = NewOrderRequest(
symbol_id=270,
order_type=OrderType.STOP,
side=OrderSide.SELL,
volume=symbol.lots_to_volume(0.1),
stop_price=4900.0,
)
AmendOrderRequest
Bases: FrozenModel
Request to modify a pending order.
Setting any field to None will unset that field (e.g. remove stop loss), while setting it to a value will update it.
To keep the existing value of a field, you must include the current value in the request.
Attributes:
| Name | Type | Description |
|---|---|---|
order_id |
int
|
The order to modify. |
volume |
int | None
|
New volume in cents. |
limit_price |
Decimal | None
|
New limit price. |
stop_price |
Decimal | None
|
New stop trigger price. |
stop_loss |
Decimal | None
|
New stop loss price. |
take_profit |
Decimal | None
|
New take profit price. |
expiration_timestamp |
datetime | None
|
New expiration time. |
slippage_in_points |
int | None
|
New max slippage. |
trailing_stop_loss |
bool | None
|
Enable/disable trailing stop. |
guaranteed_stop_loss |
bool | None
|
Enable/disable guaranteed stop. |
relative_stop_loss |
Decimal | None
|
New relative stop loss in price units. |
relative_take_profit |
Decimal | None
|
New relative take profit in price units. |
stop_trigger_method |
StopTriggerMethod | None
|
New trigger method. |
to_proto(account_id)
Convert to proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_id
|
int
|
The trading account ID. |
required |
Returns:
| Type | Description |
|---|---|
ProtoOAAmendOrderReq
|
Proto request message. |
ClosePositionRequest
Bases: FrozenModel
Request to close a position.
Attributes:
| Name | Type | Description |
|---|---|---|
position_id |
int
|
The position to close. |
volume |
int
|
Volume to close in cents. Use position's full volume |
to_proto(account_id)
Convert to proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_id
|
int
|
The trading account ID. |
required |
Returns:
| Type | Description |
|---|---|
ProtoOAClosePositionReq
|
Proto request message. |
Example:
from ctrader_api_client import ClosePositionRequest
# Get position to know its volume
positions = await client.trading.get_open_positions(account_id)
position = positions[0]
# Close entire position
close_all = ClosePositionRequest(
position_id=position.position_id,
volume=position.volume, # Must match position volume for full close
)
# Partial close - close half of the position
symbol = await client.symbols.get_by_id(account_id, position.symbol_id)
current_lots = symbol.volume_to_lots(position.volume)
partial_close = ClosePositionRequest(
position_id=position.position_id,
volume=symbol.lots_to_volume(current_lots / 2), # Close half
)
AmendPositionRequest
Bases: FrozenModel
Request to modify a position's stop loss and take profit.
Attributes:
| Name | Type | Description |
|---|---|---|
position_id |
int
|
The position to modify. |
stop_loss |
Decimal | None
|
New stop loss price, or None to remove. |
take_profit |
Decimal | None
|
New take profit price, or None to remove. |
trailing_stop_loss |
bool
|
Enable/disable trailing stop. |
guaranteed_stop_loss |
bool
|
Enable/disable guaranteed stop. |
stop_loss_trigger_method |
StopTriggerMethod | None
|
Trigger method for stop loss. |
to_proto(account_id)
Convert to proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
account_id
|
int
|
The trading account ID. |
required |
Returns:
| Type | Description |
|---|---|
ProtoOAAmendPositionSLTPReq
|
Proto request message. |
Response/Data Models
Position
Bases: FrozenModel
An open or closed trading position.
Represents a position with all trading details including entry price,
stop loss, take profit, and P&L information.
Attributes:
| Name | Type | Description |
|---|---|---|
position_id |
int
|
Unique position identifier. |
symbol_id |
int
|
The symbol being traded. |
side |
OrderSide
|
Position direction (BUY/SELL). |
volume |
int
|
Position volume in cents. |
entry_price |
Decimal
|
Entry price as Decimal from API. |
status |
PositionStatus
|
Current position status. |
open_timestamp |
datetime
|
When the position was opened. |
money_digits |
int
|
Decimal places for monetary values. |
stop_loss |
Decimal | None
|
Stop loss price as Decimal, or None if not set. |
take_profit |
Decimal | None
|
Take profit price as Decimal, or None if not set. |
trailing_stop_loss |
bool
|
Whether trailing stop is enabled. |
guaranteed_stop_loss |
bool
|
Whether guaranteed stop loss is enabled. |
stop_loss_trigger_method |
StopTriggerMethod
|
Method for triggering stop loss. |
swap |
Decimal
|
Accumulated swap (raw integer). |
commission |
Decimal
|
Total commission paid (raw integer). |
used_margin |
Decimal
|
Margin allocated to position (raw integer). |
margin_rate |
Decimal | None
|
Margin rate for the position. |
label |
str
|
User-defined label. |
comment |
str
|
User-defined comment. |
last_update_timestamp |
datetime | None
|
When the position was last updated. |
close_timestamp |
datetime | None
|
When the position was closed, if applicable. |
from_proto(proto)
Create Position from proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOAPosition
|
The proto message to convert. |
required |
Returns:
| Type | Description |
|---|---|
Position
|
A new Position instance. |
PositionUnrealizedPnL
Bases: FrozenModel
Unrealized P&L for a single open position.
Attributes:
| Name | Type | Description |
|---|---|---|
position_id |
int
|
Unique identifier for the position. |
gross_unrealized_pnl |
Decimal
|
Gross unrealized profit or loss. |
net_unrealized_pnl |
Decimal
|
Net unrealized profit or loss after fees and swap. |
Order
Bases: FrozenModel
A trading order (pending or historical).
Represents an order with all details including type, prices, volume,
and execution information.
Attributes:
| Name | Type | Description |
|---|---|---|
order_id |
int
|
Unique order identifier. |
symbol_id |
int
|
The symbol being traded. |
side |
OrderSide
|
Order direction (BUY/SELL). |
order_type |
OrderType
|
Type of order (MARKET, LIMIT, STOP, etc.). |
status |
OrderStatus
|
Current order status. |
volume |
int
|
Order volume in cents. |
time_in_force |
TimeInForce
|
Order duration type. |
open_timestamp |
datetime
|
When the order was created. |
limit_price |
Decimal | None
|
Limit price, or None. |
stop_price |
Decimal | None
|
Stop trigger price, or None. |
stop_loss |
Decimal | None
|
Stop loss price, or None. |
take_profit |
Decimal | None
|
Take profit price, or None. |
execution_price |
Decimal | None
|
Average fill price, or None. |
executed_volume |
int
|
Volume that has been filled, in cents. |
expiration_timestamp |
datetime | None
|
When the order expires, or None. |
position_id |
int | None
|
Associated position ID, or None. |
base_slippage_price |
Decimal | None
|
Base price for slippage calculation. |
slippage_in_points |
int | None
|
Max allowed slippage in points. |
relative_stop_loss |
int | None
|
Stop loss distance in points. |
relative_take_profit |
int | None
|
Take profit distance in points. |
is_closing_order |
bool
|
Whether this order closes a position. |
is_stop_out |
bool
|
Whether this order was triggered by stop-out. |
trailing_stop_loss |
bool
|
Whether trailing stop is enabled. |
guaranteed_stop_loss |
bool
|
Whether guaranteed stop loss is enabled. |
stop_trigger_method |
StopTriggerMethod
|
Method for triggering stop orders. |
client_order_id |
str
|
User-defined order ID. |
label |
str
|
User-defined label. |
comment |
str
|
User-defined comment. |
last_update_timestamp |
datetime | None
|
When the order was last modified. |
is_pending
Whether this is a pending order.
is_filled
Whether this order has been fully filled.
from_proto(proto)
Create Order from proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOAOrder
|
The proto message to convert. |
required |
Returns:
| Type | Description |
|---|---|
Order
|
A new Order instance. |
Deal
Bases: FrozenModel
A trade execution (deal).
Represents a single execution that fills an order. An order may have
multiple deals if it's filled in parts.
Attributes:
| Name | Type | Description |
|---|---|---|
deal_id |
int
|
Unique deal identifier. |
order_id |
int
|
The order that was executed. |
position_id |
int
|
The position affected by this deal. |
symbol_id |
int
|
The symbol traded. |
side |
OrderSide
|
Trade direction (BUY/SELL). |
volume |
int
|
Requested volume in cents. |
filled_volume |
int
|
Actually filled volume in cents. |
execution_price |
Decimal
|
Price at which the deal was executed. |
execution_timestamp |
datetime
|
When the deal was executed. |
status |
DealStatus
|
Deal status. |
commission |
Decimal
|
Commission charged. |
create_timestamp |
datetime | None
|
When the deal was created. |
last_update_timestamp |
datetime | None
|
When the deal was last updated. |
margin_rate |
Decimal | None
|
Margin rate for the deal. |
base_to_usd_rate |
Decimal | None
|
Conversion rate from base currency to USD. |
close_detail |
CloseDetail | None
|
Details if this deal closed a position, or None. |
is_closing_deal
Whether this deal closed (or partially closed) a position.
from_proto(proto)
Create Deal from proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOADeal
|
The proto message to convert. |
required |
Returns:
| Type | Description |
|---|---|
Deal
|
A new Deal instance. |
CloseDetail
Bases: FrozenModel
Details about position closure from a deal.
Present only when a deal results in closing (fully or partially)
a position.
Attributes:
| Name | Type | Description |
|---|---|---|
entry_price |
Decimal
|
Original entry price of the position. |
closed_volume |
int
|
Volume that was closed in cents. |
gross_profit |
Decimal
|
Gross profit/loss. |
swap |
Decimal
|
Swap charged. |
commission |
Decimal
|
Commission charged. |
balance |
Decimal
|
Account balance after close. |
pnl_conversion_fee |
Decimal
|
Fee for P&L currency conversion. |
quote_to_deposit_rate |
Decimal | None
|
Conversion rate from quote to deposit currency. |
balance_version |
int | None
|
Version number for balance updates. |
from_proto(proto)
Create CloseDetail from proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOAClosePositionDetail
|
The proto message to convert. |
required |
Returns:
| Type | Description |
|---|---|
CloseDetail
|
A new CloseDetail instance. |
Symbol
Bases: FrozenModel
Full symbol trading parameters.
Contains all information needed for trading calculations including
pip position, lot size, volume limits, commission and swap.
Attributes:
| Name | Type | Description |
|---|---|---|
symbol_id |
int
|
The unique symbol identifier. |
digits |
int
|
Price decimal places. |
pip_position |
int
|
Position of pip in price (e.g., 4 means 0.0001). |
lot_size |
int
|
Contract size in hundredths of a base unit. A forex lot of |
min_volume |
int
|
Minimum order volume in cents. |
max_volume |
int
|
Maximum order volume in cents. |
step_volume |
int
|
Volume step in cents. |
trading_mode |
TradingMode
|
Current trading mode. |
commission |
Commission
|
What the broker charges to trade the symbol. |
swap |
Swap
|
What the broker charges to hold a position overnight. |
max_exposure |
int | None
|
Maximum allowed exposure. |
leverage_id |
int | None
|
ID of dynamic leverage profile, if any. |
enable_short_selling |
bool
|
Whether short selling is allowed. |
guaranteed_stop_loss |
bool
|
Whether guaranteed stop loss is available. |
sl_distance |
int
|
Minimum stop loss distance. |
tp_distance |
int
|
Minimum take profit distance. |
schedule_timezone |
str
|
Timezone for trading schedule. |
measurement_units |
str
|
Measurement units (e.g., "oz" for gold). |
trading_hours |
TradingHours
|
Weekly schedule and holidays describing when the symbol is |
volume_to_lots(volume_cents)
Convert volume in cents to lots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume_cents
|
int
|
Volume in cents |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
Volume in lots. |
lots_to_volume(lots)
Convert lots to volume in cents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lots
|
Decimal
|
Volume in lots. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Volume in cents for API. |
quantize_price(price)
Quantize price to symbol's allowed decimal places
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
price
|
Decimal
|
The price to quantize. |
required |
Returns:
| Type | Description |
|---|---|
Decimal
|
Quantized price. |
from_proto(proto)
Create Symbol from proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOASymbol
|
The proto message to convert. |
required |
Returns:
| Type | Description |
|---|---|
Symbol
|
A new Symbol instance. |
SymbolInfo
Bases: FrozenModel
Basic symbol information from symbol list.
This is the lightweight representation returned when listing symbols.
Use Symbol for full trading parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
symbol_id |
int
|
The unique symbol identifier. |
name |
str
|
Symbol name (e.g., "EURUSD"). |
enabled |
bool
|
Whether the symbol is enabled for trading. |
base_asset_id |
int
|
Asset ID of the base currency. |
quote_asset_id |
int
|
Asset ID of the quote currency. |
category_id |
int | None
|
Symbol category ID. |
description |
str
|
Human-readable description. |
from_proto(proto)
Create SymbolInfo from proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOALightSymbol
|
The proto message to convert. |
required |
Returns:
| Type | Description |
|---|---|
SymbolInfo
|
A new SymbolInfo instance. |
Commission
Bases: FrozenModel
The commission a broker charges to trade one symbol.
A commission is charged per side, so a round turn costs twice rate unless
the broker states otherwise.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
CommissionType
|
What |
rate |
Decimal
|
The commission rate, in the unit its type names. A |
minimum |
Decimal
|
The smallest commission the broker charges for one trade, in the |
minimum_type |
MinCommissionType
|
The currency |
minimum_asset |
str
|
The currency |
Example
from ctrader_api_client import CommissionType
symbol = await client.symbols.get_by_id(account_id, 270)
commission = symbol.commission
if commission.type is CommissionType.USD_PER_MILLION_USD:
charge = commission.rate * notional_usd / 1_000_000
print(f"{max(charge, commission.minimum)} USD per side")
from_proto(proto)
Create a Commission from a symbol proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOASymbol
|
The proto message to read the commission fields from. |
required |
Returns:
| Type | Description |
|---|---|
Commission
|
A new Commission instance. |
Example:
A broker states a commission as a rate and a type. The type says what the rate counts, so
you must read the two together. The rate alone is meaningless: 2.5 is 2.50 USD per lot
under one type and 2.5% of the traded value under another.
from decimal import Decimal
from ctrader_api_client import CommissionType, Symbol
def commission_per_side(symbol: Symbol, lots: Decimal, price: Decimal) -> Decimal:
"""Commission for one side of a trade.
The result is in USD for the two USD types, and in the symbol's quote currency
for QUOTE_CCY_PER_LOT.
"""
# lot_size counts hundredths of a base unit, so 100 gives the contract size.
notional = lots * symbol.lot_size / 100 * price
match symbol.commission.type:
case CommissionType.USD_PER_MILLION_USD:
return symbol.commission.rate * notional / 1_000_000
case CommissionType.USD_PER_LOT | CommissionType.QUOTE_CCY_PER_LOT:
return symbol.commission.rate * lots
case CommissionType.PERCENTAGE_OF_VALUE:
return symbol.commission.rate / 100 * notional
# Symbol IDs belong to the broker's server, so look yours up with symbols.search().
gold = await client.symbols.get_by_id(account_id, 41)
# 0.0007 (PERCENTAGE_OF_VALUE), a lot of 100 ounces
print(gold.commission.rate, gold.commission.type.value)
# 3.07689900 USD for 1 lot at 4395.57, which the broker charges as 3.08
print(commission_per_side(gold, Decimal(1), Decimal("4395.57")))
These rates come from one live broker, and show how far the types differ:
| Symbol | Type | Rate | Charge per side, for one lot |
|---|---|---|---|
| EURUSD | USD_PER_LOT |
2.5 | 2.50 USD, at any price |
| XAUUSD | PERCENTAGE_OF_VALUE |
0.0007 | 3.08 USD, at a price of 4395.57 |
| BTCUSD | PERCENTAGE_OF_VALUE |
0.0325 | 20.89 USD, at a price of 64286.15 |
The broker charges the commission per side, so a round turn costs twice as much.
minimum is the smallest commission the broker charges for one trade. Apply it only when
its currency matches your charge: minimum_type tells you whether minimum is in the
symbol's quote currency, or in the currency that minimum_asset names. A minimum of 0
means the broker sets no minimum.
Swap
Bases: FrozenModel
The swap a broker charges to hold one symbol overnight.
Attributes:
| Name | Type | Description |
|---|---|---|
calculation_type |
SwapCalculationType
|
What |
long |
Decimal
|
The swap rate for a long position, in the unit its type names. |
short |
Decimal
|
The swap rate for a short position, in the unit its type names. |
triple_day |
DayOfWeek
|
The day of the week when the broker charges three times |
period_hours |
int | None
|
How often the broker charges the swap. 24 means once a |
charge_time |
time
|
The time of day, in UTC, when the broker charges the first |
skip_periods |
int
|
How many charge periods pass before the first swap is |
charged_at_weekends |
bool
|
Whether the broker charges the swap on Saturday |
Example
from_proto(proto)
Create a Swap from a symbol proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOASymbol
|
The proto message to read the swap fields from. |
required |
Returns:
| Type | Description |
|---|---|
Swap
|
A new Swap instance. |
TradingHours
Bases: FrozenModel
A symbol's weekly schedule together with the holidays that cut into it.
Attributes:
| Name | Type | Description |
|---|---|---|
timezone |
str
|
Timezone the weekly schedule is expressed in. |
intervals |
tuple[ScheduleInterval, ...]
|
The repeating weekly schedule. |
holidays |
tuple[Holiday, ...]
|
Closures that override the weekly schedule. |
Example
sessions_on(day)
Return the sessions a symbol is open for on a calendar date.
Sessions are clipped to the date and are never merged, so a schedule with a
daily maintenance break reports one session either side of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date
|
A date in the symbol's schedule timezone. |
required |
Returns:
| Type | Description |
|---|---|
tuple[TradingSession, ...]
|
The open sessions, ordered by start. |
holidays_on(day)
Return the holidays whose closures reach into a calendar date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date
|
A date in the symbol's schedule timezone. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Holiday, ...]
|
The holidays affecting that date, in the order the broker sent them. |
current_session(at=None)
Return the session in progress at an instant, if any.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
datetime | None
|
The instant to test, defaulting to now. Naive input is read as UTC. |
None
|
Returns:
| Type | Description |
|---|---|
TradingSession | None
|
The session containing that instant, or None if the symbol is closed. |
is_open(at=None)
Report whether the symbol is open at an instant.
This answers the calendar question only. A symbol can be closed to trading by
its trading_mode while its schedule says it is open.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
datetime | None
|
The instant to test, defaulting to now. Naive input is read as UTC. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the schedule has the symbol open. |
next_open(after=None)
Return when the symbol next opens.
Called while the symbol is open, this returns the start of the following
session rather than the current one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
after
|
datetime | None
|
The instant to search from, defaulting to now. Naive input is read |
None
|
Returns:
| Type | Description |
|---|---|
datetime | None
|
The next opening instant, or None if the symbol never opens again. |
next_close(after=None)
Return when the symbol next closes.
Called while the symbol is open, this returns the end of the current session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
after
|
datetime | None
|
The instant to search from, defaulting to now. Naive input is read |
None
|
Returns:
| Type | Description |
|---|---|
datetime | None
|
The next closing instant, or None if the symbol never opens again. |
from_proto(proto)
Create TradingHours from a symbol proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOASymbol
|
The proto message to read the schedule and holidays from. |
required |
Returns:
| Type | Description |
|---|---|
TradingHours
|
A new TradingHours instance. |
TradingSession
Bases: FrozenModel
A concrete window during which a symbol is open.
Attributes:
| Name | Type | Description |
|---|---|---|
start |
datetime
|
When the session opens, inclusive. |
end |
datetime
|
When the session closes, exclusive. |
duration
How much time actually elapses during the session.
A session spanning a daylight saving transition is shorter or longer than
its wall clock bounds suggest.
contains(moment)
Report whether an instant falls inside this session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moment
|
datetime
|
The instant to test. Naive input is read as UTC. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the symbol is open at that instant. |
ScheduleInterval
Bases: FrozenModel
One entry of a symbol's repeating weekly schedule.
Attributes:
| Name | Type | Description |
|---|---|---|
start_second |
int
|
Seconds from Sunday 00:00 in the symbol's timezone, inclusive. |
end_second |
int
|
Seconds from Sunday 00:00 in the symbol's timezone, exclusive. |
Holiday
Bases: FrozenModel
A broker-defined closure applying to a symbol.
The window described by start_second and end_second is the period the
holiday is in effect, meaning the symbol is closed for it. A window that is
empty or inverted means the whole day is closed, which is how brokers encode a
full-day holiday.
Attributes:
| Name | Type | Description |
|---|---|---|
holiday_id |
int
|
The unique holiday identifier. |
name |
str
|
Holiday name, e.g. "Juneteenth 19/6/2026 - 20:00 - Early Close". |
timezone |
str
|
Timezone the holiday's date and seconds are expressed in. This is |
holiday_date |
date
|
The calendar date the holiday falls on. |
description |
str
|
Human-readable description. |
is_recurring |
bool
|
Whether the holiday repeats on the same date each year. |
start_second |
int
|
Seconds from the holiday date's midnight when the closure |
end_second |
int
|
Seconds from the holiday date's midnight when the closure ends. |
occurs_on(day)
Report whether this holiday applies to a calendar date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date
|
A date in this holiday's own timezone. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the holiday falls on that date. |
closed_window(day)
Return the instants this holiday closes the symbol for on a date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date
|
A date this holiday applies to, in its own timezone. |
required |
Returns:
| Type | Description |
|---|---|
tuple[datetime, datetime]
|
The aware |
from_proto(proto, fallback_timezone='')
Create a Holiday from a proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOAHoliday
|
The proto message to convert. |
required |
fallback_timezone
|
str
|
Timezone to use when the holiday omits its own. |
''
|
Returns:
| Type | Description |
|---|---|
Holiday
|
A new Holiday instance. |
Account
Bases: FrozenModel
Full trading account details.
Retrieved after authorizing a specific account. Contains balance,
leverage, and other trading parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
account_id |
int
|
The cTID trader account ID. |
trader_login |
int
|
The trader's login number. |
balance |
Decimal
|
Account balance |
leverage_in_cents |
int
|
Account leverage in cents (e.g., 10000 = 1:100). |
account_type |
AccountType
|
Account type (HEDGED, NETTED, SPREAD_BETTING). |
access_rights |
AccessRights
|
Current access rights for the account. |
broker_name |
str
|
Name of the broker. |
deposit_asset_id |
int
|
Asset ID of the deposit currency. |
swap_free |
bool
|
Whether account is swap-free (Islamic Banking). |
is_limited_risk |
bool
|
Whether account has limited risk mode. |
registration_timestamp |
datetime | None
|
When the account was registered. |
max_leverage |
int | None
|
Maximum allowed leverage. |
balance_version |
int | None
|
Version number for balance updates. |
manager_bonus |
Decimal | None
|
Manager bonus amount |
ib_bonus |
Decimal | None
|
IB bonus amount |
non_withdrawable_bonus |
Decimal | None
|
Non-withdrawable bonus amount |
get_leverage()
Get leverage as human-readable string.
Returns:
| Type | Description |
|---|---|
str
|
Leverage string like "1:100". |
from_proto(proto)
Create Account from proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOATrader
|
The proto message to convert. |
required |
Returns:
| Type | Description |
|---|---|
Account
|
A new Account instance. |
AccountSummary
Bases: FrozenModel
Summary of a trading account from account list.
This is the lightweight representation returned when listing accounts
associated with an access token. Use Account for full details after
authorization.
Attributes:
| Name | Type | Description |
|---|---|---|
account_id |
int
|
The cTID trader account ID. |
is_live |
bool
|
True if this is a live account, False for demo. |
trader_login |
int
|
The trader's login number. |
broker_name |
str
|
Short name of the broker. |
last_closing_deal_timestamp |
datetime | None
|
Timestamp of last closing deal, or None. |
last_balance_update_timestamp |
datetime | None
|
Timestamp of last balance update, or None. |
from_proto(proto)
Create AccountSummary from proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOACtidTraderAccount
|
The proto message to convert. |
required |
Returns:
| Type | Description |
|---|---|
AccountSummary
|
A new AccountSummary instance. |
Trendbar
Bases: FrozenModel
Historical OHLC bar (candlestick).
Note: The raw proto stores prices as deltas from low. This model
exposes computed open/high/close values.
Attributes:
| Name | Type | Description |
|---|---|---|
timestamp |
datetime
|
Bar open time. |
period |
TrendbarPeriod
|
Bar period (M1, H1, D1, etc.). |
low |
Decimal
|
Low price |
open |
Decimal
|
Open price |
high |
Decimal
|
High price |
close |
Decimal
|
Close price |
volume |
int
|
Bar volume in ticks. |
from_proto(proto, bid_price=None, historical=False)
Create a Trendbar from a proto message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOATrendbar
|
Source proto message. |
required |
bid_price
|
Decimal | None
|
Bid price used as close when the API omits delta_close on live updates. |
None
|
historical
|
bool
|
If False, raises on delta_close == 0 instead of silently returning low == close. |
False
|
TickData
Bases: FrozenModel
Historical tick data point.
Represents a single price tick from tick history.
Attributes:
| Name | Type | Description |
|---|---|---|
timestamp |
datetime
|
Tick time. |
price |
Decimal
|
Tick price. |
from_proto(proto)
Create TickData from proto message.
Note that price needs to be converted from a raw integer to a Decimal by dividing by 100000.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proto
|
ProtoOATickData
|
The proto message. |
required |
Returns:
| Type | Description |
|---|---|
TickData
|
A new TickData instance. |
from_proto_list(protos)
Convert list of proto tick data to list of TickData.
Note that proto timestamps and prices are stored as deltas from the previous timestamp and price, with
the first data point being an absolute value.
This method converts them to absolute values.
Additionally, price needs to be converted from a raw integer to a Decimal by dividing by 100000.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protos
|
list[ProtoOATickData]
|
List of proto tick data messages. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[TickData]
|
List of TickData instances. |
Volume Conversion
Volumes in the cTrader API are expressed in cents relative to the symbol's lot_size:
- For standard forex (lot_size=100000):
100000= 1.0 lots,10000= 0.1 lots,1000= 0.01 lots - For other instruments, lot_size may vary
Use the Symbol model for conversions:
symbol = await client.symbols.get_by_id(account_id, 270)
# Convert lots to volume for orders
volume = symbol.lots_to_volume(0.1) # Returns volume in cents
# Convert volume to lots for display
lots = symbol.volume_to_lots(position.volume) # Returns lots as Decimal
Price Values
Prices in events and models (bid, ask, OHLC, execution prices, etc.) are returned as Decimals - no conversion needed:
@client.on(SpotEvent)
async def on_price(event: SpotEvent):
# bid and ask are already Decimals
spread = event.ask - event.bid
print(f"Spread: {spread}")
# Trendbar OHLC are Decimals
for bar in trendbars:
range_size = bar.high - bar.low
print(f"Range: {range_size}")
# Account balance is a Decimal
account = await client.accounts.get_trader(account_id)
print(f"Balance: {account.balance}")
# Position values are Decimals
for pos in positions:
print(f"Swap: {pos.swap}, Commission: {pos.commission}")