Skip to content

Commit

Permalink
Update mql.py
Browse files Browse the repository at this point in the history
initialize df to an empty dataframe before the while loop.
  • Loading branch information
traderpedroso committed May 4, 2023
1 parent 3ed25cb commit 8f8ee81
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ejtraderMT/api/mql.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def _calendar(self,data):
symbol = self._symbol
fromDate = self._fromDate
toDate = self._toDate
df = pd.DataFrame()
# count data
if not isinstance(fromDate, int):
start_date = datetime.strptime(fromDate, "%d/%m/%Y")
Expand All @@ -282,20 +283,19 @@ def _calendar(self,data):
else:
end_date = datetime.strptime(toDate, "%d/%m/%Y")


delta = timedelta(days=1)
delta2 = timedelta(days=1)
diff_days = start_date - end_date
days_count = diff_days.days
pbar = tqdm(total=abs(days_count))
appended_data = []

while start_date <= end_date:
pbar.update(delta.days)
fromDate = start_date.strftime("%d/%m/%Y")
toDate = start_date
toDate += delta2
toDate = toDate.strftime("%d/%m/%Y")
toDate = toDate.strftime("%d/%m/%Y")

if fromDate and toDate:
try:
df = self.__api.Command(action="CALENDAR", actionType="DATA", symbol=symbol,
Expand Down Expand Up @@ -804,4 +804,4 @@ def __save_to_db(self,df):
except AttributeError:
pass
if self.dbtype == "INFLUXDB":
self.__client.write_points(df, f"{self.__active_name}", protocol=self.protocol)
self.__client.write_points(df, f"{self.__active_name}", protocol=self.protocol)

0 comments on commit 8f8ee81

Please sign in to comment.