cefi.handler.metatrader.MetatraderHandler#
- class cefi.handler.metatrader.MetatraderHandler(**kwargs)[source]#
Bases:
CexClientlibrary: lucas-campagna/mt5linux leveraging metatrader python integration: https://www.mql5.com/en/docs/integration/python_metatrader5/
You can use MT5 via the docker image gmag11/metatrader5_vnc which include the python integration if your metatrader container is named metatrader5 and the python port is 8001 it will connect
- Args:
None
- Returns:
None
Initialize the client
Methods
calculate_pnl(from_date, to_date)Calculate the PnL for a given start date.
execute_order(order_params)Execute order
return account balance
return account balance
get_account_pnl([period, from_date, to_date])Return account pnl.
Return account position.
get_bid(instrument)Asynchronously retrieves the bid for the specified instrument.
get_instrument_decimals(instrument)Get the number of decimal places for the token.
get_offer(symbol)Asynchronously fetches a ask/offer quote for the specified instrument.
get_order_amount(quantity, instrument[, ...])Calculate the order amount based on the risk percentage or money amount.
get_quote(instrument)Return a quote for a instrument
get_trade_confirmation(trade, instrument, action)Asynchronously retrieves the trade confirmation for a given trade, instrument, and action.
modify_position(order_params)Modify opened position
pre_order_checks(order_params)replace_instrument(instrument)Replace instrument by an alternative instrument, if the instrument is not in the mapping, it will be ignored.
shutdown()- async get_account_position()[source]#
Return account position. of a given exchange
- Parameters:
None
- Returns:
position
- async get_quote(instrument)[source]#
Return a quote for a instrument
- Parameters:
cex
instrument
- Returns:
quote
- async execute_order(order_params)[source]#
Execute order
- Parameters:
order_params (dict) – action(str) instrument(str) quantity(int)
- Returns:
trade_confirmation(dict)
- async calculate_pnl(from_date, to_date)[source]#
Calculate the PnL for a given start date.
- Parameters:
from_date – The start date for which to calculate PnL.
to_date – The end date for which to calculate PnL.
- Returns:
The calculated PnL value.
- Return type:
pnl
- async get_account_pnl(period=None, from_date=None, to_date=None)#
Return account pnl.
- Parameters:
None
- Returns:
pnl
- async get_bid(instrument)#
Asynchronously retrieves the bid for the specified instrument.
- Parameters:
instrument – The instrument for which
retrieved. (the bid is to be)
- Returns:
The bid for the specified instrument.
- async get_instrument_decimals(instrument)#
Get the number of decimal places for the token.
- Returns:
The number of decimal places for the token.
- Return type:
int
- async get_offer(symbol)#
Asynchronously fetches a ask/offer quote for the specified instrument.
- Parameters:
instrument – The instrument for which the quote is to be fetched.
- Returns:
The fetched quote.
- async get_order_amount(quantity, instrument, is_percentage=True)#
Calculate the order amount based on the risk percentage or money amount.
- Parameters:
quantity – The quantity of the order.
instrument – The instrument of the asset.
is_percentage – True if quantity is a risk percentage,
amount. (False if it is a money)
- Returns:
The calculated order amount.
- async get_trade_confirmation(trade, instrument, action)#
Asynchronously retrieves the trade confirmation for a given trade, instrument, and action.
- Parameters:
self – The object instance
trade – The trade object
instrument – The instrument for the trade
action – The action for the trade
- Returns:
A string containing the trade confirmation, or None if an error occurs.
- async modify_position(order_params)#
Modify opened position
- Parameters:
order_params (dict)
- Returns:
trade_confirmation(dict)
- async pre_order_checks(order_params)#
- async replace_instrument(instrument)#
Replace instrument by an alternative instrument, if the instrument is not in the mapping, it will be ignored.
- Parameters:
order (dict)
- Returns:
dict