mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-07 17:27:45 +00:00
testdata
This commit is contained in:
@@ -9,6 +9,7 @@ __pycache__/
|
||||
.Python
|
||||
env/
|
||||
venv/
|
||||
.venv/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
from collections import namedtuple
|
||||
class ITR:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.span = iter(range(0, 10))
|
||||
self.start = 0
|
||||
|
||||
def __next__(self):
|
||||
self.start = next(self.span)
|
||||
return self.start
|
||||
|
||||
|
||||
Gender = namedtuple('Gender', ['man', 'woman'])
|
||||
gen = Gender(man='Manny', woman='Babe')
|
||||
gend = gen._asdict()
|
||||
genz = Gender(gend)
|
||||
print(gen, genz)
|
||||
# b = ITR()
|
||||
# print(next(b))
|
||||
# print(next(b))
|
||||
# print(next(b))
|
||||
@@ -26,26 +26,24 @@ class Data(TypedDict):
|
||||
prices: DataFrame
|
||||
ticks: DataFrame
|
||||
rates: DataFrame
|
||||
span: range
|
||||
interval: range
|
||||
|
||||
|
||||
class GetData:
|
||||
config: Config = Config()
|
||||
|
||||
def __init__(self, *, start: datetime, end: datetime, timeframes: set[TimeFrame], symbols: set[str],
|
||||
interval: int = 60, name: str = '', tz: str = 'Etc/UTC'):
|
||||
name: str = '', tz: str = 'Etc/UTC'):
|
||||
""""""
|
||||
super().__init__()
|
||||
self.tz = pytz.timezone(tz)
|
||||
self.start = start.replace(tzinfo=self.tz)
|
||||
self.end = end.replace(tzinfo=self.tz)
|
||||
self.interval = interval
|
||||
self.symbols = symbols
|
||||
self.timeframes = timeframes
|
||||
self.counter = 0
|
||||
self.name = name or f"{start:%d-%m-%y}_{end:%d-%m-%y}"
|
||||
diff = int((self.end - self.start).total_seconds())
|
||||
self.span = range(start := int(self.start.timestamp()), diff + start)
|
||||
self.interval = range(start := int(self.start.timestamp()), diff + start)
|
||||
self.mt5 = MetaTrader()
|
||||
|
||||
async def get_data(self) -> Data:
|
||||
@@ -60,7 +58,7 @@ class GetData:
|
||||
data['prices'] = prices
|
||||
data['symbols'] = symbols
|
||||
data['account'] = account
|
||||
data['range'] = self.span
|
||||
data['range'] = self.interval
|
||||
|
||||
return Data(**data)
|
||||
|
||||
@@ -149,7 +147,7 @@ class GetData:
|
||||
res = pd.DataFrame(res)
|
||||
res.drop_duplicates(subset=['time'], keep='last', inplace=True)
|
||||
res.set_index('time', inplace=True, drop=False)
|
||||
res = res.reindex(self.span, method='nearest')
|
||||
res = res.reindex(self.interval, method='nearest')
|
||||
return symbol, res
|
||||
|
||||
@backoff_decorator(max_retries=5)
|
||||
|
||||
@@ -15,19 +15,27 @@ from ...core.errors import Error
|
||||
from ...core.constants import TimeFrame, CopyTicks, OrderType
|
||||
from ...core.models import (AccountInfo, SymbolInfo, BookInfo, TradeOrder, OrderCheckResult, OrderSendResult,
|
||||
TradePosition, TradeDeal)
|
||||
|
||||
from ...utils import backoff_decorator
|
||||
from .test_data import TestData
|
||||
from .get_data import GetData
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
|
||||
class MetaTester(MetaTrader):
|
||||
"""A class for testing trading strategies in the MetaTrader 5 terminal. A subclass of MetaTrader."""
|
||||
data: TestData
|
||||
|
||||
def __init__(self, data: TestData):
|
||||
def __init__(self, data: TestData = None):
|
||||
super().__init__()
|
||||
self.error = None
|
||||
self.data = data
|
||||
|
||||
|
||||
async def initialize(self, path: str = "", login: int = 0, password: str = "", server: str = "",
|
||||
timeout: int | None = None, portable=False, compressed: bool = False) -> bool:
|
||||
self.data = await GetData.load_data(name=path, compressed=compressed)
|
||||
return True
|
||||
|
||||
async def account_info(self) -> AccountInfo:
|
||||
""""""
|
||||
res = self.data.account
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from ...core.models import AccountInfo, SymbolInfo
|
||||
from ...core.models import AccountInfo, SymbolInfo, TickInfo
|
||||
from .get_data import Data, GetData
|
||||
|
||||
from MetaTrader5 import Tick, SymbolInfo
|
||||
|
||||
class TestData:
|
||||
def __init__(self, data: Data):
|
||||
@@ -10,5 +10,35 @@ class TestData:
|
||||
self.prices = data['prices']
|
||||
self.ticks = data['ticks']
|
||||
self.rates = data['rates']
|
||||
self.span = data['span']
|
||||
self.interval = data['interval']
|
||||
self.cursor = 0
|
||||
self.iter = iter(self.interval)
|
||||
|
||||
def __next__(self):
|
||||
self.cursor = next(self.iter)
|
||||
return self.cursor
|
||||
|
||||
def reset(self):
|
||||
self.iter = iter(self.interval)
|
||||
return self.iter
|
||||
|
||||
def get_symbol_info_tick(self, symbol: str) -> Tick:
|
||||
tick = self.prices[symbol].iloc[self.cursor]
|
||||
return Tick(**tick)
|
||||
|
||||
def get_symbol_info(self, symbol: str) -> SymbolInfo:
|
||||
symbol = self.symbols[symbol]
|
||||
symbol |= {'bid': tick.bid, 'bidhigh': tick.bid, 'bidlow': tick.bid, 'bid': tick.bid, 'bidhigh': tick.bid, 'bidlow': tick.bid}
|
||||
symbol = SymbolInfo(**symbol)
|
||||
tick = self.get_symbol_info_tick(symbol)
|
||||
symbol.bid = tick.bid
|
||||
symbol.bidhigh = 120.506
|
||||
symbol.bidlow = tick.
|
||||
ask=120.041
|
||||
askhigh=120.526
|
||||
asklow=118.828
|
||||
symbol.update()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user