Форум сайта python.su
xam1816
import pandas as pd
bars = [
{'time': 1632048000, ‘open’: 1.1701, ‘high’: 1.1725, ‘low’: 1.1698, ‘close’: 1.1715, ‘tick_volume’: 0, ‘spread’: 2, ‘real_volume’: 0},
{'time': 1632048060, ‘open’: 1.1716, ‘high’: 1.1722, ‘low’: 1.1714, ‘close’: 1.1717, ‘tick_volume’: 0, ‘spread’: 2, ‘real_volume’: 0},
{'time': 1632048120, ‘open’: 1.1716, ‘high’: 1.1719, ‘low’: 1.1711, ‘close’: 1.1712, ‘tick_volume’: 0, ‘spread’: 2, ‘real_volume’: 0}
]
df = pd.DataFrame(bars)
df = pd.to_datetime(df, unit='s')
last_bar_time = df.iloc
print(df)
print(last_bar_time)
print(df.iloc)
print(last_bar_time == df.iloc)
import MetaTrader5 as mt5 import pandas as pd import numpy as np import time import datetime as dt mt5.initialize() symbol_list = ['EURUSD','BTCUSDT.cfd'] timeframe = mt5.TIMEFRAME_M1 start_pos = 0 num_bars = 63 ema5_period = 5 esma13_period = 13 ema62_period = 62 check_bar = pd.DataFrame(columns = ['time', 'symbol'], index = range(0, len(symbol_list))) check_bar['time'] = pd.to_datetime(1900-1-1) check_bar['symbol'] = symbol_list while True: for symbol in symbol_list: bars = mt5.copy_rates_from_pos(symbol, timeframe, start_pos, num_bars) df = pd.DataFrame(bars)[['time', 'open', 'high', 'low', 'close']] df['symbol'] = symbol df['time'] = pd.to_datetime(df['time'], unit='s') df.dropna(inplace=True) print(df) for i in range(0, len(symbol_list)): last_bar = check_bar.loc[i, 'time'] if df.iloc[-1:]['time'] != last_bar: print(check_bar.loc[i,'symbol'], 'новый бар!') check_bar.loc[i, 'time'] = df.iloc[-1:]['time'] time.sleep(5)
Офлайн