Skip to content

Commit

Permalink
#83 HTML rendering and key --html were implemented for reports crea…
Browse files Browse the repository at this point in the history
…ted by `--deals` key
  • Loading branch information
Tim55667757 committed Nov 21, 2022
1 parent cd355da commit 65a9234
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tksbrokerapi/TKSBrokerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def ShowInstrumentInfo(self, iJSON: dict, show: bool = True) -> str:
with open(htmlFilePath, "w", encoding="UTF-8") as fH:
fH.write(Template(text=MAIN_INFO_TEMPLATE).render(mainTitle=header, commonCSS=COMMON_CSS, markdown=infoText))

uLogger.info("Report was rendered to HTML-file also: [{}]".format(os.path.abspath(htmlFilePath)))
uLogger.info("The report has also been converted to an HTML file: [{}]".format(os.path.abspath(htmlFilePath)))

return infoText

Expand Down Expand Up @@ -1246,7 +1246,7 @@ def ShowInstrumentsInfo(self, show: bool = True) -> str:
with open(htmlFilePath, "w", encoding="UTF-8") as fH:
fH.write(Template(text=MAIN_INFO_TEMPLATE).render(mainTitle="List of instruments", commonCSS=COMMON_CSS, markdown=infoText))

uLogger.info("Report was rendered to HTML-file also: [{}]".format(os.path.abspath(htmlFilePath)))
uLogger.info("The report has also been converted to an HTML file: [{}]".format(os.path.abspath(htmlFilePath)))

return infoText

Expand Down Expand Up @@ -1328,13 +1328,13 @@ def SearchInstruments(self, pattern: str, show: bool = True) -> dict:

uLogger.info("Full search results were saved to file: [{}]".format(os.path.abspath(self.searchResultsFile)))

if self.searchResultsFile:
if self.useHTMLReports:
htmlFilePath = self.searchResultsFile.replace(".md", ".html") if self.searchResultsFile.endswith(".md") else self.searchResultsFile + ".html"
header = "Search results: {}".format(pattern)
with open(htmlFilePath, "w", encoding="UTF-8") as fH:
fH.write(Template(text=MAIN_INFO_TEMPLATE).render(mainTitle=header, commonCSS=COMMON_CSS, markdown=infoText))

uLogger.info("Report was rendered to HTML-file also: [{}]".format(os.path.abspath(htmlFilePath)))
uLogger.info("The report has also been converted to an HTML file: [{}]".format(os.path.abspath(htmlFilePath)))

return searchResults

Expand Down Expand Up @@ -1463,13 +1463,13 @@ def ShowListOfPrices(self, iList: list, show: bool = True) -> str:

uLogger.info("Price list for all instruments saved to file: [{}]".format(os.path.abspath(self.pricesFile)))

if self.pricesFile:
if self.useHTMLReports:
htmlFilePath = self.pricesFile.replace(".md", ".html") if self.pricesFile.endswith(".md") else self.pricesFile + ".html"
header = "Price for tickers: {}".format("[{}], ".join(tickers))
header = "Price for tickers: {}".format(", ".join(tickers))
with open(htmlFilePath, "w", encoding="UTF-8") as fH:
fH.write(Template(text=MAIN_INFO_TEMPLATE).render(mainTitle=header, commonCSS=COMMON_CSS, markdown=infoText))

uLogger.info("Report was rendered to HTML-file also: [{}]".format(os.path.abspath(htmlFilePath)))
uLogger.info("The report has also been converted to an HTML file: [{}]".format(os.path.abspath(htmlFilePath)))

return infoText

Expand Down Expand Up @@ -2581,8 +2581,6 @@ def _InfoStr(data1: dict, data2: dict, data3: dict, data4: dict, cur: str = "")
for key in comKeys:
info.append(_InfoStr(customStat["brokerCom"], customStat["serviceCom"], customStat["marginCom"], customStat["allTaxes"], key))

info.append(splitLine1)

info.extend([
"\n## All operations{}\n\n".format("" if showCancelled else " (without cancelled status)"),
"| Date and time | FIGI | Ticker | Asset | Value | Payment | Status | Operation type |\n",
Expand Down Expand Up @@ -2635,6 +2633,14 @@ def _InfoStr(data1: dict, data2: dict, data3: dict, data4: dict, cur: str = "")

uLogger.info("History of a client's operations are saved to file: [{}]".format(os.path.abspath(self.reportFile)))

if self.useHTMLReports:
htmlFilePath = self.reportFile.replace(".md", ".html") if self.reportFile.endswith(".md") else self.reportFile + ".html"
header = "Client's operations: from [{}] to [{}]".format(startDate.split("T")[0], endDate.split("T")[0])
with open(htmlFilePath, "w", encoding="UTF-8") as fH:
fH.write(Template(text=MAIN_INFO_TEMPLATE).render(mainTitle=header, commonCSS=COMMON_CSS, markdown=infoText))

uLogger.info("The report has also been converted to an HTML file: [{}]".format(os.path.abspath(htmlFilePath)))

return ops, customStat

def History(self, start: str = None, end: str = None, interval: str = "hour", onlyMissing: bool = False, csvSep: str = ",", show: bool = False) -> pd.DataFrame:
Expand Down

0 comments on commit 65a9234

Please sign in to comment.