π― MT5Sugar API ReferenceΒΆ
Documentation Status
Auto-generated from source code (src/pymt5/mt5_sugar.py) and enhanced for readability.
Complete API reference with enhanced navigation. Single-page format for easy browsing.
π OverviewΒΆ
MT5Sugar represents a high-level convenience API for MT5 trading using Python best practices. It sits at the top of the architecture stack, providing maximum simplicity with properties for instant access, context managers, enums instead of magic numbers, unified methods with smart defaults, and comprehensive type hints. This is the recommended layer for most trading applications.
Key Features
- β
Python properties for instant access (
await sugar.balance,await sugar.equity) - β
Context managers for automatic connection handling (
async with MT5Sugar.connect(...)) - β Enums instead of magic numbers (Period.TODAY, OrderType.BUY)
- β Smart defaults and unified method signatures
- β 62 async methods + 7 properties covering all trading scenarios
- β Built-in risk management and position sizing calculators
- β Comprehensive type hints for IDE autocomplete
Detailed Guide Available
π MT5Sugar Master Overview - Complete high-level API guide with examples, best practices, and usage patterns for all 62 methods
π Table of ContentsΒΆ
π€ Account InformationΒΆ
- get_balance β Get account balance
- get_equity β Get current equity
- get_margin β Get used margin
- get_free_margin β Get available margin
- get_margin_level β Get margin level %
- get_floating_profit β Get floating profit/loss
- get_account_info β Complete account info
π Account Properties (async)ΒΆ
- balance β Property: Account balance
- equity β Property: Current equity
- margin β Property: Used margin
- free_margin β Property: Free margin
- margin_level β Property: Margin level %
- profit β Property: Total floating profit/loss
πΉ Prices & QuotesΒΆ
- get_bid β Get BID price
- get_ask β Get ASK price
- get_spread β Get spread in points
- get_price_info β Complete price info
- wait_for_price β Wait for valid price
π Simple Trading (Market & Pending)ΒΆ
- buy_market β Open BUY at market
- sell_market β Open SELL at market
- buy_limit β Place BUY LIMIT
- sell_limit β Place SELL LIMIT
- buy_stop β Place BUY STOP
- sell_stop β Place SELL STOP
π― Trading with SL/TPΒΆ
- buy_market_with_sltp β BUY with stop loss/take profit
- sell_market_with_sltp β SELL with stop loss/take profit
- buy_limit_with_sltp β BUY LIMIT with SL/TP
- sell_limit_with_sltp β SELL LIMIT with SL/TP
- buy_market_with_pips β BUY with SL/TP in pips
- sell_market_with_pips β SELL with SL/TP in pips
- calculate_sltp β Convert pips to prices
π Position ManagementΒΆ
- close_position β Close position by ticket
- close_position_partial β Partial close
- close_all_positions β Close all positions
- modify_position_sltp β Modify SL/TP
- modify_position_sl β Modify stop loss only
- modify_position_tp β Modify take profit only
- get_open_positions β Get all open positions
- get_position_by_ticket β Get position by ticket
- get_positions_by_symbol β Get positions for symbol
- has_open_position β Check if positions exist
- count_open_positions β Count open positions
- get_total_profit β Total P&L across positions
- get_profit_by_symbol β P&L for symbol
π History & StatisticsΒΆ
- get_deals β Get deals for period
- get_profit β Get profit for period
- get_deals_today β Today's deals
- get_deals_yesterday β Yesterday's deals
- get_deals_this_week β This week's deals
- get_deals_this_month β This month's deals
- get_deals_date_range β Deals in date range
- get_profit_today β Today's profit
- get_profit_this_week β This week's profit
- get_profit_this_month β This month's profit
- get_daily_stats β Daily trading statistics
π Symbol InformationΒΆ
- get_symbol_info β Complete symbol info
- get_all_symbols β List all symbols
- is_symbol_available β Check symbol availability
- get_min_stop_level β Minimum SL/TP distance
- get_symbol_digits β Decimal places
π‘οΈ Risk ManagementΒΆ
- calculate_position_size β Calculate lot size by risk
- can_open_position β Validate position opening
- get_max_lot_size β Maximum allowed lot size
- calculate_required_margin β Calculate required margin
ποΈ Class: MT5SugarΒΆ
Source: Line 225
High-level convenience API for MT5 trading using Python best practices.
MT5Sugar represents the highest-level API layer in the PyMT5 architecture, designed for maximum simplicity and developer productivity. It wraps MT5Service with intuitive Pythonic patterns including async properties (await sugar.balance), context managers (async with sugar.connect()), enums instead of magic numbers, smart method defaults, and comprehensive risk management tools. This is the recommended layer for building trading applications, bots, and analysis tools.
Architecture Position
- LOW MT5Account (protobuf Request/Data, direct gRPC)
- MID MT5Service (Python types, removes Data wrappers)
- HIGH MT5Sugar (business logic, ready-made patterns) β THIS CLASS
Constructor Requirements
- Requires MT5Service instance (mid-level wrapper)
- Optional
default_timeout(seconds for operations, default 10.0) - Optional
default_symbol(default trading symbol like "EURUSD") - Recommended: Use
MT5Sugar.connect()class method instead of direct construction
Usage Patterns
Pattern 1: Context Manager (Recommended)
async with MT5Sugar.connect("ICMarkets-Demo") as sugar:
balance = await sugar.balance
ticket = await sugar.buy_market("EURUSD", 0.1)
Pattern 2: Manual Connection
account = MT5Account.create(user=12345, password="pass", grpc_server="mt5.mrpc.pro:443")
await account.connect_by_server_name("ICMarkets-Demo", "EURUSD")
service = MT5Service(account)
sugar = MT5Sugar(service, default_symbol="EURUSD")
balance = await sugar.balance
ticket = await sugar.buy_market("EURUSD", 0.1)
Pattern 3: Properties for Quick Access
Key Advantages
- Pythonic API: Properties, context managers, enums, type hints
- Smart defaults: Default symbol, automatic price fetching, sensible timeouts
- Risk management: Position sizing by risk %, margin validation, lot size limits
- Convenience methods: Today's profit, this week's deals, close all positions
- Flexible SL/TP: Specify as absolute prices OR pips (auto-converted)
- Error handling: Clear RuntimeError messages on trading failures
π§ Constructor & ConnectionΒΆ
initΒΆ
Signature: def __init__(self, service, default_timeout, default_symbol)
Source: Line 245
Initialize MT5Sugar with a service instance.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
service |
MT5Service | - | Mid-level service instance |
default_timeout |
float | 10.0 | Default timeout for operations in seconds |
default_symbol |
str | None | Default trading symbol (e.g., "EURUSD") |
connectΒΆ
Signature: async def connect(cls, host, port, login, password) -> MT5Sugar
Source: Line 264
Create and connect MT5Sugar instance (use as context manager).
Recommended Usage
Use this method with async with for automatic cleanup:
serviceΒΆ
Signature: def service(self) -> MT5Service
Source: Line 280
Get underlying MT5Service for advanced operations.
Returns: MT5Service instance
is_connectedΒΆ
Signature: def is_connected(self) -> bool
Source: Line 291
Check if connection to MT5 server is active.
Returns: True if gRPC channel is ready or idle, False otherwise
Example
pingΒΆ
Signature: async def ping(self, timeout) -> bool
Source: Line 318
Ping MT5 server to check connection health.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
timeout |
float | - | Timeout in seconds for ping attempt |
Returns: True if server responds successfully, False otherwise
quick_connectΒΆ
Signature: async def quick_connect(self, cluster_name, base_symbol) -> None
Source: Line 340
Quick connect (or reconnect) to MT5 cluster by name.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
cluster_name |
str | - | MT5 cluster identifier (e.g., "ICMarkets-Demo", "FxPro-Live01") |
base_symbol |
str | "EURUSD" | Base chart symbol for connection |
Raises
RuntimeError: If credentials are not accessible in MT5AccountException: If connection to cluster fails
π€ Account Information MethodsΒΆ
get_balanceΒΆ
Signature: async def get_balance(self) -> float
Source: Line 386
Get account balance (realized profit only).
Returns: Account balance as float
get_equityΒΆ
Signature: async def get_equity(self) -> float
Source: Line 396
Get current equity (balance + floating P/L).
Returns: Current equity as float
get_marginΒΆ
Signature: async def get_margin(self) -> float
Source: Line 406
Get used margin.
Returns: Used margin as float
get_free_marginΒΆ
Signature: async def get_free_margin(self) -> float
Source: Line 417
Get available margin for new positions.
Returns: Free margin as float
get_margin_levelΒΆ
Signature: async def get_margin_level(self) -> float
Source: Line 428
Get margin level % (Equity/Margin Γ 100).
Returns: Margin level percentage
Important
Brokers trigger margin call/stop out when level drops below threshold (typically 100%/50%).
get_floating_profitΒΆ
Signature: async def get_floating_profit(self) -> float
Source: Line 439
Get total floating profit/loss from open positions.
Returns: Total floating P&L
π Account Properties (async)ΒΆ
balanceΒΆ
Signature: async def balance(self) -> float
Source: Line 452
Property: Account balance
equityΒΆ
Signature: async def equity(self) -> float
Source: Line 457
Property: Current equity
marginΒΆ
Signature: async def margin(self) -> float
Source: Line 462
Property: Used margin
free_marginΒΆ
Signature: async def free_margin(self) -> float
Source: Line 467
Property: Free margin
margin_levelΒΆ
Signature: async def margin_level(self) -> float
Source: Line 472
Property: Margin level %
profitΒΆ
Signature: async def profit(self) -> float
Source: Line 477
Property: Total floating profit/loss
πΉ Prices & Quotes MethodsΒΆ
get_bidΒΆ
Signature: async def get_bid(self, symbol) -> float
Source: Line 488
Get current BID price.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
Returns: BID price
get_askΒΆ
Signature: async def get_ask(self, symbol) -> float
Source: Line 502
Get current ASK price.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
Returns: ASK price
get_spreadΒΆ
Signature: async def get_spread(self, symbol) -> float
Source: Line 516
Get current spread in points.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
Returns: Spread in points
get_price_infoΒΆ
Signature: async def get_price_info(self, symbol) -> PriceInfo
Source: Line 530
Get complete price information.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
Returns: PriceInfo dataclass with bid, ask, spread, time
wait_for_priceΒΆ
Signature: async def wait_for_price(self, symbol, timeout) -> PriceInfo
Source: Line 545
Wait for valid price update with timeout.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
timeout |
float | 10.0 | Timeout in seconds |
Returns: PriceInfo when price updates
π Simple Trading MethodsΒΆ
buy_marketΒΆ
Signature: async def buy_market(self, symbol, volume, comment, magic) -> int
Source: Line 568
Open BUY position at market price.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
volume |
float | - | Volume in lots |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Position ticket number
sell_marketΒΆ
Signature: async def sell_market(self, symbol, volume, comment, magic) -> int
Source: Line 613
Open SELL position at market price.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
volume |
float | - | Volume in lots |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Position ticket number
buy_limitΒΆ
Signature: async def buy_limit(self, symbol, volume, price, comment, magic) -> int
Source: Line 658
Place BUY LIMIT pending order (buy below current price).
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
volume |
float | - | Volume in lots |
price |
float | - | Limit price |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Order ticket number
sell_limitΒΆ
Signature: async def sell_limit(self, symbol, volume, price, comment, magic) -> int
Source: Line 698
Place SELL LIMIT pending order (sell above current price).
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
volume |
float | - | Volume in lots |
price |
float | - | Limit price |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Order ticket number
buy_stopΒΆ
Signature: async def buy_stop(self, symbol, volume, price, comment, magic) -> int
Source: Line 738
Place BUY STOP pending order (buy above current price).
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
volume |
float | - | Volume in lots |
price |
float | - | Stop price |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Order ticket number
sell_stopΒΆ
Signature: async def sell_stop(self, symbol, volume, price, comment, magic) -> int
Source: Line 778
Place SELL STOP pending order (sell below current price).
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name (uses default_symbol if None) |
volume |
float | - | Volume in lots |
price |
float | - | Stop price |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Order ticket number
π― Trading with SL/TP MethodsΒΆ
buy_market_with_sltpΒΆ
Signature: async def buy_market_with_sltp(self, symbol, volume, sl, tp, sl_pips, tp_pips, comment, magic) -> int
Source: Line 824
Open BUY position with Stop Loss and Take Profit.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name |
volume |
float | - | Volume in lots |
sl |
float | None | Stop Loss price (absolute) |
tp |
float | None | Take Profit price (absolute) |
sl_pips |
float | None | Stop Loss in pips (alternative to sl) |
tp_pips |
float | None | Take Profit in pips (alternative to tp) |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Position ticket number
Flexible SL/TP
You can specify SL/TP as either:
- Absolute prices: sl=1.0900, tp=1.1000
- Pips distance: sl_pips=50, tp_pips=100
Examples
sell_market_with_sltpΒΆ
Signature: async def sell_market_with_sltp(self, symbol, volume, sl, tp, sl_pips, tp_pips, comment, magic) -> int
Source: Line 903
Open SELL position with Stop Loss and Take Profit.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name |
volume |
float | - | Volume in lots |
sl |
float | None | Stop Loss price (absolute) |
tp |
float | None | Take Profit price (absolute) |
sl_pips |
float | None | Stop Loss in pips (alternative to sl) |
tp_pips |
float | None | Take Profit in pips (alternative to tp) |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Position ticket number
Examples
buy_limit_with_sltpΒΆ
Signature: async def buy_limit_with_sltp(self, symbol, volume, price, sl, tp, sl_pips, tp_pips, comment, magic) -> int
Source: Line 984
Place BUY LIMIT pending order with Stop Loss and Take Profit.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name |
volume |
float | - | Volume in lots |
price |
float | - | Limit order price |
sl |
float | None | Stop Loss price (absolute) |
tp |
float | None | Take Profit price (absolute) |
sl_pips |
float | None | Stop Loss in pips (alternative to sl) |
tp_pips |
float | None | Take Profit in pips (alternative to tp) |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Order ticket number
Example
sell_limit_with_sltpΒΆ
Signature: async def sell_limit_with_sltp(self, symbol, volume, price, sl, tp, sl_pips, tp_pips, comment, magic) -> int
Source: Line 1059
Place SELL LIMIT pending order with Stop Loss and Take Profit.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name |
volume |
float | - | Volume in lots |
price |
float | - | Limit order price |
sl |
float | None | Stop Loss price (absolute) |
tp |
float | None | Take Profit price (absolute) |
sl_pips |
float | None | Stop Loss in pips (alternative to sl) |
tp_pips |
float | None | Take Profit in pips (alternative to tp) |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Order ticket number
Example
buy_market_with_pipsΒΆ
Signature: async def buy_market_with_pips(self, symbol, volume, sl_pips, tp_pips, comment, magic) -> int
Source: Line 1948
Open BUY position at market with SL/TP specified in pips.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name |
volume |
float | - | Volume in lots |
sl_pips |
float | - | Stop Loss in pips |
tp_pips |
float | - | Take Profit in pips |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Position ticket number
Example
sell_market_with_pipsΒΆ
Signature: async def sell_market_with_pips(self, symbol, volume, sl_pips, tp_pips, comment, magic) -> int
Source: Line 1986
Open SELL position at market with SL/TP specified in pips.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Symbol name |
volume |
float | - | Volume in lots |
sl_pips |
float | - | Stop Loss in pips |
tp_pips |
float | - | Take Profit in pips |
comment |
str | "" | Order comment |
magic |
int | 0 | Magic number |
Returns: Position ticket number
Example
calculate_sltpΒΆ
Signature: async def calculate_sltp(self, symbol, is_buy, sl_pips, tp_pips)
Source: Line 1896
Convert SL/TP from pips to absolute prices.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | - | Symbol name |
is_buy |
bool | - | True for BUY, False for SELL |
sl_pips |
float | None | Stop Loss in pips |
tp_pips |
float | None | Take Profit in pips |
Returns: Tuple (sl_price, tp_price). Returns None for values not specified.
Examples
π Position Management MethodsΒΆ
close_positionΒΆ
Signature: async def close_position(self, ticket) -> bool
Source: Line 1141
Close position completely by ticket.
Parameters:
| Parameter | Type | Description |
|---|---|---|
ticket |
int | Position ticket number |
Returns: True if position closed successfully
close_position_partialΒΆ
Signature: async def close_position_partial(self, ticket, volume) -> bool
Source: Line 1241
Partially close position by specified volume.
Parameters:
| Parameter | Type | Description |
|---|---|---|
ticket |
int | Position ticket number |
volume |
float | Volume to close (must be less than position volume) |
Returns: True if partial close successful
Example
close_all_positionsΒΆ
Signature: async def close_all_positions(self, symbol) -> int
Source: Line 1165
Close all open positions.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | If specified, close only positions for this symbol |
Returns: Number of positions closed
modify_position_sltpΒΆ
Signature: async def modify_position_sltp(self, ticket, sl, tp) -> bool
Source: Line 1196
Modify position SL/TP.
Parameters:
| Parameter | Type | Description |
|---|---|---|
ticket |
int | Position ticket number |
sl |
float | New Stop Loss price (None to keep current) |
tp |
float | New Take Profit price (None to keep current) |
Returns: True if modification successful
modify_position_slΒΆ
Signature: async def modify_position_sl(self, ticket, sl) -> bool
Source: Line 1299
Modify position Stop Loss only.
Parameters:
| Parameter | Type | Description |
|---|---|---|
ticket |
int | Position ticket number |
sl |
float | New Stop Loss price |
Returns: True if modification successful
modify_position_tpΒΆ
Signature: async def modify_position_tp(self, ticket, tp) -> bool
Source: Line 1315
Modify position Take Profit only.
Parameters:
| Parameter | Type | Description |
|---|---|---|
ticket |
int | Position ticket number |
tp |
float | New Take Profit price |
Returns: True if modification successful
get_open_positionsΒΆ
Signature: async def get_open_positions(self)
Source: Line 1338
Get all open positions.
Returns: List of open positions
get_position_by_ticketΒΆ
Signature: async def get_position_by_ticket(self, ticket)
Source: Line 1343
Get position by ticket number.
Parameters:
| Parameter | Type | Description |
|---|---|---|
ticket |
int | Position ticket number |
Returns: Position info or None
get_positions_by_symbolΒΆ
Signature: async def get_positions_by_symbol(self, symbol)
Source: Line 1353
Get all positions for specified symbol.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
Returns: List of positions for symbol
has_open_positionΒΆ
Signature: async def has_open_position(self, symbol) -> bool
Source: Line 1359
Check if there are open positions (optionally filtered by symbol).
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Optional symbol filter |
Returns: True if positions exist
count_open_positionsΒΆ
Signature: async def count_open_positions(self, symbol) -> int
Source: Line 1368
Count open positions (optionally filtered by symbol).
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | None | Optional symbol filter |
Returns: Number of open positions
get_total_profitΒΆ
Signature: async def get_total_profit(self) -> float
Source: Line 1377
Get total profit/loss across all open positions.
Returns: Total floating P&L
get_profit_by_symbolΒΆ
Signature: async def get_profit_by_symbol(self, symbol) -> float
Source: Line 1383
Get total profit/loss for positions of specified symbol.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
Returns: Total P&L for symbol
π History & Statistics MethodsΒΆ
get_dealsΒΆ
Signature: async def get_deals(self, period, from_date, to_date) -> List
Source: Line 1437
Get deals for specified period.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
period |
Period | - | Predefined period (TODAY, YESTERDAY, THIS_WEEK, THIS_MONTH, CUSTOM) |
from_date |
date | None | Custom start date (required if period=CUSTOM) |
to_date |
date | None | Custom end date (required if period=CUSTOM) |
Returns: List of orders (deals) for the specified period
get_profitΒΆ
Signature: async def get_profit(self, period, from_date, to_date) -> float
Source: Line 1473
Get total profit for specified period.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
period |
Period | - | Predefined period (TODAY, YESTERDAY, THIS_WEEK, THIS_MONTH, CUSTOM) |
from_date |
date | None | Custom start date (required if period=CUSTOM) |
to_date |
date | None | Custom end date (required if period=CUSTOM) |
Returns: Total profit for the period
get_deals_todayΒΆ
Signature: async def get_deals_today(self) -> List
Source: Line 1497
Get all deals made today.
Returns: List of today's orders
get_deals_yesterdayΒΆ
Signature: async def get_deals_yesterday(self) -> List
Source: Line 1510
Get all deals made yesterday.
Returns: List of yesterday's orders
get_deals_this_weekΒΆ
Signature: async def get_deals_this_week(self) -> List
Source: Line 1522
Get all deals made this week (from Monday to today).
Returns: List of this week's orders
get_deals_this_monthΒΆ
Signature: async def get_deals_this_month(self) -> List
Source: Line 1535
Get all deals made this month.
Returns: List of this month's orders
get_deals_date_rangeΒΆ
Signature: async def get_deals_date_range(self, from_date, to_date) -> List
Source: Line 1548
Get all deals within a specific date range.
Parameters:
| Parameter | Type | Description |
|---|---|---|
from_date |
date | Start date (inclusive) |
to_date |
date | End date (inclusive) |
Returns: List of orders in the date range
Example
get_profit_todayΒΆ
Signature: async def get_profit_today(self) -> float
Source: Line 1568
Get total profit made today.
Returns: Today's profit/loss
get_profit_this_weekΒΆ
Signature: async def get_profit_this_week(self) -> float
Source: Line 1581
Get total profit made this week.
Returns: This week's profit/loss
get_profit_this_monthΒΆ
Signature: async def get_profit_this_month(self) -> float
Source: Line 1593
Get total profit made this month.
Returns: This month's profit/loss
Example
get_daily_statsΒΆ
Signature: async def get_daily_stats(self, target_date) -> DailyStats
Source: Line 2061
Get daily trading statistics.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
target_date |
date | None | Date to get stats for (default: today) |
Returns: DailyStats dataclass with trading statistics for the day
Examples
π Symbol Information MethodsΒΆ
get_symbol_infoΒΆ
Signature: async def get_symbol_info(self, symbol) -> SymbolInfo
Source: Line 1615
Get complete symbol information.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
Returns: SymbolInfo dataclass
get_all_symbolsΒΆ
Signature: async def get_all_symbols(self)
Source: Line 1642
Get list of all available symbols.
Returns: List of all symbols
is_symbol_availableΒΆ
Signature: async def is_symbol_available(self, symbol) -> bool
Source: Line 1672
Check if symbol exists and is tradable.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
Returns: True if available
get_min_stop_levelΒΆ
Signature: async def get_min_stop_level(self, symbol) -> int
Source: Line 1677
Get minimum stop level (minimum distance for SL/TP) in points.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
Returns: Minimum stop level in points
Example
get_symbol_digitsΒΆ
Signature: async def get_symbol_digits(self, symbol) -> int
Source: Line 1697
Get number of decimal places in symbol price.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
Returns: Number of digits after decimal point
Example
π‘οΈ Risk Management MethodsΒΆ
calculate_position_sizeΒΆ
Signature: async def calculate_position_size(self, symbol, risk_percent, sl_pips) -> float
Source: Line 1724
Calculate position size based on risk percentage.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
risk_percent |
float | Risk as percentage of balance (e.g., 2.0 for 2%) |
sl_pips |
float | Stop Loss distance in pips |
Returns: Optimal position size in lots
Risk Management Formula
Formula: volume = risk_amount / (sl_pips Γ pip_value)
Where:
- risk_amount = balance Γ (risk_percent / 100)
- pip_value = point Γ 10 Γ contract_size
Rounds to volume_step, clamps to volume_min/max.
Example
can_open_positionΒΆ
Signature: async def can_open_position(self, symbol, volume)
Source: Line 1774
Validate if position can be opened.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
volume |
float | Position volume in lots |
Returns: (can_open, reason) tuple
get_max_lot_sizeΒΆ
Signature: async def get_max_lot_size(self, symbol) -> float
Source: Line 1821
Get maximum lot size allowed for this symbol.
Parameters:
| Parameter | Type | Description |
|---|---|---|
symbol |
str | Symbol name |
Returns: Maximum volume in lots
calculate_required_marginΒΆ
Signature: async def calculate_required_margin(self, symbol, volume, order_type) -> float
Source: Line 1841
Calculate margin required to open a position.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
symbol |
str | - | Symbol name |
volume |
float | - | Position volume in lots |
order_type |
OrderType | BUY | Order type enum value |
Returns: Required margin in account currency
get_account_infoΒΆ
Signature: async def get_account_info(self) -> AccountInfo
Source: Line 2031
Get complete account information in a structured dataclass.
Returns: AccountInfo dataclass with all account details
Example
π Context Manager MethodsΒΆ
aenterΒΆ
Signature: async def __aenter__(self)
Source: Line 2128
Async context manager entry.
aexitΒΆ
Signature: async def __aexit__(self, exc_type, exc_val, exc_tb)
Source: Line 2132
Async context manager exit.