Files
aiomql/docs/lib/trader.md
T
Ichinga Samuel f56d0c85b3 v4
2024-11-10 12:25:50 +01:00

7.7 KiB

Trader

Trader class module. Handles the creation of an order and the placing of trades

Table of Contents

Trader

class Trader()

Base class for creating a Trader object. Handles the creation of an order and the placing of trades

Attributes:

Name Type Description Default
ram RAM Risk Assessment Management System. None
config Config Config instance. None
order Order Order instance. None
symbol Symbol The Financial Instrument None
parameters dict A dictionary of parameters associated with the trade. None

__init__

def __init__(*, symbol: Symbol, ram: RAM = None)

Parameters:

Name Type Description Default
symbol Symbol The Financial instrument
ram RAM Risk Assessment and Management instance None

set_trade_stop_levels_pips

async def set_trade_stop_levels_pips(*, pips: float, risk_to_reward: float = None):

Sets the stop loss and take profit for the order. This method uses pips as defined for forex instruments.

Parameters:

Name Type Description Default
pips float Target pips
risk_to_reward float Optional risk to reward ratio None

set_trade_stop_levels_points

async def set_trade_stop_levels_points(*, points: float, risk_to_reward: float = None):

Sets the stop loss and take profit for the order. This method uses points as defined for forex instruments.

Parameters:

Name Type Description Default
points float Target points
risk_to_reward float Optional risk to reward ratio None

create_order_no_stops

async def create_order_no_stops(*, order_type: OrderType, volume: float = None)

Create an order without setting stop loss and take profit. Using minimum lot size.

Parameters:

Name Type Description Default
order_type OrderType The order type
volume float The volume to trade None

create_order_with_stops

async def create_order_with_stops(*, order_type: OrderType, sl: float, tp: float, amount_to_risk: float = None)

Create an order with stop loss and take profit levels. Use the amount to risk per trade to calculate the volume.

Parameters:

Name Type Description Default
order_type OrderType The order type
sl float The stop loss`
tp float The take profit`
amount_to_risk float The amount to risk None

create_order_with_sl

async def create_order_with_sl(*, order_type: OrderType, sl: float, amount_to_risk: float = None, risk_to_reward: float = None)

Create an order with a given stop_loss level. Use the amount to risk per trade to calculate the volume.

Parameters:

Name Type Description Default
order_type OrderType The order type
sl float The stop loss`
risk_to_reward float Risk to reward ratio. Optional parameter None
amount_to_risk float The amount to risk None

create_order_with_points

async def create_order_with_points(*, order_type: OrderType, points: float, amount_to_risk: float = None, risk_to_reward: float = None)

Create an order with specific points to risk. Use the amount to risk per trade to calculate the volume.

Parameters:

Name Type Description Default
order_type OrderType The order type
points float Points to risk
risk_to_reward float Risk to reward ratio. Optional parameter None
amount_to_risk float The amount to risk None

send_order

async def send_order() -> OrderSendResult

Sends the order to the broker for execution.

Returns:

Type Description
OrderSendResult The OrderSendResult object

check_order

async def check_order() -> OrderCheckResult

Checks the status of the order before placing the trade.

Returns:

Type Description
OrderCheckResult The OrderCheckResult object

record_trade

async def record_trade(*, result: OrderSendResult, parameters: dict = None, name: str = '')

Records the trade and the order details if Config.record_trades is true. Trades are recorded as either json or csv.

Parameters:

Name Type Description Default
result OrderSendResult The result of the placed order
parameters dict parameters to saved instead of the ones in self.parameters None
name str Name for the csv or json file ''

place_trade

@abstractmethod
async def place_trade(self, *args, **kwargs)

Places a trade. All traders must implement this method.