Skip to content

Commit

Permalink
tz_local=False to utc or tz_local=True local tz
Browse files Browse the repository at this point in the history
  • Loading branch information
Emerson Pedroso committed Apr 30, 2021
1 parent 2d8adc4 commit 714080c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions ejtraderMT/api/mql.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ def chart_data_construct_and_send(self, **kwargs) -> dict:

class Metatrader:

def __init__(self, host=None, real_volume=None, localtime=True, dbtype=None,dbhost=None,dbport=None,dbpass=None,dbuser=None,dbname=None):
def __init__(self, host=None, real_volume=None, tz_local=True, dbtype=None,dbhost=None,dbport=None,dbpass=None,dbuser=None,dbname=None):
self.__api = Functions(host)
self.real_volume = real_volume or False
self.localtime = localtime
self.__tz_local = tz_local
self.__utc_timezone = timezone('UTC')
self.__my_timezone = get_localzone()
self.__utc_brocker_offset = self.___utc_brocker_offset()
Expand Down Expand Up @@ -499,9 +499,10 @@ def __timeframe_to_sec(self, timeframe):
}
return TIMECANDLE[timeframe]

def __setlocaltime_dataframe(self, df):
def __set_utc_or_localtime_tz_df(self, df):
df.index = df.index.tz_localize(self.__utc_brocker_offset)
df.index = df.index.tz_convert(self.__my_timezone)
if self.__tz_local:
df.index = df.index.tz_convert(self.__my_timezone)
df.index = df.index.tz_localize(None)
return df

Expand Down Expand Up @@ -690,9 +691,8 @@ def __historyThread_save(self,data):
start(self.__save_to_db,data=[df],repeat=1, max_threads=20)
else:
try:
if self.localtime:
self.__setlocaltime_dataframe(df)
self.__historyQ.put(df)
self.__set_utc_or_localtime_tz_df(df)
self.__historyQ.put(df)

except AttributeError:
pass
Expand All @@ -704,17 +704,15 @@ def __save_to_db(self,df):
if self.dbtype == 'SQLITE':
q = DictSQLite('history',multithreading=True)
try:
if self.localtime:
self.__setlocaltime_dataframe(df)
self.__set_utc_or_localtime_tz_df(df)

except AttributeError:
pass

q[f"{self.__active_name}"] = df
else:
try:
if self.localtime:
self.__setlocaltime_dataframe(df)
self.__set_utc_or_localtime_tz_df(df)
except AttributeError:
pass
if self.dbtype == "INFLUXDB":
Expand Down

0 comments on commit 714080c

Please sign in to comment.