import datetime
from tqz_extern.pandas_operator import pandas
from op_futures.op_objects.bar_data import BarData
class BarGenerate:
def __init__(self, csv_path: str):
self.__tick_df = pandas.read_csv(csv_path)
self.__bar_df = pandas.DataFrame(
columns=['date_time', 'open_price', 'high_price', 'low_price', 'close_price', 'volume', 'open_interest']
)
self.bars = []
@staticmethod
def timestamp_to_datetime(timestamp) -> str:
ret_dt = datetime.datetime.fromtimestamp(timestamp / 1000)
ret_dt = ret_dt - datetime.timedelta(hours=8)
return f'{ret_dt.date()} {ret_dt.time()}'
def make_bar_dataframe(self, interval_secs: int):
first_timestamp = self.__tick_df.iloc[0]['Timestamp']
last_timestamp = self.__tick_df.iloc[-1]['Timestamp']