mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-08 01:37:45 +00:00
config
This commit is contained in:
@@ -6,10 +6,10 @@ import numpy as np
|
||||
import pandas as pd
|
||||
from pandas import DataFrame
|
||||
from MetaTrader5 import (Tick, SymbolInfo, AccountInfo, TradeOrder, TradePosition, TradeDeal,
|
||||
ORDER_TYPE_BUY, ORDER_TYPE_SELL)
|
||||
ORDER_TYPE_BUY, ORDER_TYPE_SELL, TradeRequest)
|
||||
import MetaTrader5 as mt5
|
||||
from ..meta_trader import MetaTrader
|
||||
|
||||
from ..constants import TimeFrame, CopyTicks
|
||||
from ..constants import TimeFrame, CopyTicks, OrderType
|
||||
from .get_data import Data, GetData
|
||||
from ...utils import round_down, round_up
|
||||
|
||||
@@ -35,7 +35,6 @@ class TestData:
|
||||
self.positions: dict[str, dict[int, TradePosition]] = {}
|
||||
self.open_positions: dict[int, TradePosition] = {}
|
||||
self.mt = MetaTrader()
|
||||
self.mt5 = MetaTrader5
|
||||
|
||||
def __next__(self):
|
||||
self.cursor = next(self.iter)
|
||||
@@ -107,12 +106,22 @@ class TestData:
|
||||
end = ticks[ticks.index >= end].iloc[-1].index
|
||||
return ticks.loc[start:end].to_numpy()
|
||||
|
||||
async def order_calc_margin(self, action: Literal[0, 1], symbol: str, volume: float, price: float, use_terminal=False):
|
||||
if use_terminal
|
||||
async def order_calc_margin(self, action: Literal[OrderType.BUY, OrderType.SELL], symbol: str, volume: float,
|
||||
price: float, use_terminal=False):
|
||||
if use_terminal or self.mt.config.use_terminal:
|
||||
return await self.mt.order_calc_margin(OrderType(action), symbol, volume, price)
|
||||
sym = self.symbols[symbol]
|
||||
margin = (volume * sym.trade_contract_size * price) / (self.account.leverage / (sym.margin_initial or 1))
|
||||
return margin
|
||||
|
||||
async def order_calc_profit(self, action: Literal[OrderType.BUY, OrderType.SELL], symbol: str, volume: float,
|
||||
price_open: float, price_close: float, use_terminal=False):
|
||||
if use_terminal or self.mt.config.use_terminal:
|
||||
return await self.mt.order_calc_profit(action, symbol, volume, price_open, price_close)
|
||||
sym = self.symbols[symbol]
|
||||
profit = volume * sym.trade_contract_size * (price_close - price_open)
|
||||
return profit
|
||||
|
||||
def order_send(self, request: dict) -> dict:
|
||||
...
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@ class Config:
|
||||
task_queue: TaskQueue = TaskQueue()
|
||||
bot: Bot = None
|
||||
_instance: 'Config'
|
||||
mode: Literal['backtest', 'live'] = 'live'
|
||||
test_data_dir: str = 'test_data'
|
||||
use_terminal: bool = False
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if not hasattr(cls, "_instance"):
|
||||
@@ -108,7 +111,7 @@ class Config:
|
||||
project unless an absolute path is provided.
|
||||
|
||||
Keyword Args:
|
||||
records_dir (str|Path): The directory to save trade records. Default is 'records'
|
||||
records_dir (str|Path): The directory to save trade records. Default is 'trade_records'
|
||||
"""
|
||||
try:
|
||||
if isinstance(records_dir, str):
|
||||
|
||||
@@ -59,7 +59,7 @@ class MetaTrader(metaclass=BaseMeta):
|
||||
|
||||
def __init__(self):
|
||||
self.config = Config()
|
||||
self.error: Error = Error(-4, description='no history')
|
||||
self.error: Error = Error(1)
|
||||
|
||||
async def __aenter__(self) -> 'MetaTrader':
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user