diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/create-graphs.py b/examples/create-graphs.py index 5fd7f3ad..fcc04ecc 100644 --- a/examples/create-graphs.py +++ b/examples/create-graphs.py @@ -1,10 +1,13 @@ -from models.PyCryptoBot import PyCryptoBot -from models.Trading import TechnicalAnalysis -from views.TradingGraphs import TradingGraphs +import sys +sys.path.insert(0, ".") -#app = PyCryptoBot() +from controllers.PyCryptoBot import PyCryptoBot # noqa: E402 +from models.Trading import TechnicalAnalysis # noqa: E402 +from views.TradingGraphs import TradingGraphs # noqa: E402 + +# app = PyCryptoBot() app = PyCryptoBot('binance') -trading_data = self.get_historical_data(app.market, self.granularity) +trading_data = app.get_historical_data(app.market, app.granularity, None) technicalAnalysis = TechnicalAnalysis(trading_data) technicalAnalysis.add_all() @@ -13,4 +16,4 @@ tradinggraphs.renderFibonacciRetracement(True) tradinggraphs.renderSupportResistance(True) tradinggraphs.renderCandlesticks(30, True) -tradinggraphs.renderArima_model_prediction(1, True) \ No newline at end of file +tradinggraphs.renderArima_model_prediction(1, True) diff --git a/gui.py b/gui.py deleted file mode 100644 index e91d70fe..00000000 --- a/gui.py +++ /dev/null @@ -1,183 +0,0 @@ -""" Pycrypto GUI """ - -import json -import os -import argparse - -from time import sleep -from guizero import App, Text, TextBox, MenuBar, info - -# Setting initial values for color variables -bgvalue = "" -txvalue = "" -posvalue = "" -txtbox_pos = "#38BC38" -txtbox_neg = "#BC3838" -# Menu bar for display options### - - -def about(): - self.info("info", "Pycryptobot GUI by Mark H. & Jared S.") - - -def main_bg(): - bgvalue = self.question("Background", "Enter Hex Color Value.") - if bgvalue is not None: - self.bg = bgvalue - - -def text_clr(): - txvalue = self.question("Text", "Enter Hex Color Value.") - if txvalue is not None: - self.text_color = txvalue - - -class GuiSetup: - def __init__(self) -> None: - self.datafolder = "" - - parser = argparse.ArgumentParser(description="PyCryptoBot Telegram Bot") - parser.add_argument( - "--config", - type=str, - dest="config_file", - help="pycryptobot config file", - default="config.json", - ) - parser.add_argument( - "--datafolder", - type=str, - help="Use the datafolder at the given location, useful for multi bots running in different folders", - default="", - ) - - args = parser.parse_args() - - self.config_file = args.config_file - - with open(os.path.join(self.config_file), "r", encoding="utf8") as json_file: - self.config = json.load(json_file) - - if "datafolder" in self.config["telegram"]: - self.datafolder = self.config["telegram"]["datafolder"] - - if not args.datafolder == "": - self.datafolder = args.datafolder - - # json reading - def read_file(self, file): - read = False - while read is False: - try: - with open( - os.path.join(self.datafolder, "telegram_data", file), - "r", - encoding="utf8", - ) as message: - data = json.load(message) - read = True - except Exception: - read = False - - return data - - # Reads data.json and adds the correct amount of display boxes - def add_pairs(self): - - jsonfiles = os.listdir(os.path.join(self.datafolder, "telegram_data")) - while len(jsonfiles) <= 1: - sleep(300) - row = 2 - for file in jsonfiles: - if "data.json" not in file: - data = self.read_file(file) - - tpair = TextBox(app, grid=[0, row], width=15, align="top") - exchange = TextBox(app, grid=[1, row], width=15) - lastaction = TextBox(app, grid=[2, row], width=15) - curprice = TextBox(app, grid=[3, row], width=15) - margin = TextBox(app, grid=[4, row], width=15) - delta = TextBox(app, grid=[5, row], width=15) - ERI = TextBox(app, grid=[6, row]) - BULL = TextBox(app, grid=[7, row]) - EMA = TextBox(app, grid=[8, row]) - MACD = TextBox(app, grid=[9, row]) - OBV = TextBox(app, grid=[10, row]) - - tpair.value = file.replace(".json", "") - exchange.value = data["exchange"] if "exchange" in data else "waiting to buy" - - margin.repeat(5100, self.update_textbox, args=[margin, file, "margin"]) - delta.repeat(5100, self.update_textbox, args=[delta, file, "delta"]) - curprice.repeat(5100, self.update_textbox, args=[curprice, file, "price"]) - lastaction.repeat(5100, self.update_lastaction, args=[lastaction, file]) - ERI.repeat(5100, self.update_indicator, args=[ERI, file, "ERI"]) - BULL.repeat(5100, self.update_indicator, args=[BULL, file, "BULL"]) - EMA.repeat(5100, self.update_indicator, args=[EMA, file, "EMA"]) - MACD.repeat(5100, self.update_indicator, args=[MACD, file, "MACD"]) - OBV.repeat(5100, self.update_indicator, args=[OBV, file, "EMA"]) - - row += 1 - - # updates the margin and delta boxes - - def update_textbox(self, txtbox, file, key) -> None: - data = self.read_file(file) - - last_price = txtbox.value if txtbox.value != "" else data[key] - - txtbox.value = data[key] if not data[key] == " " else "N/A" - # this line causes the self.price tickers to flash instead of stay a constant state - # originally added to turn the margin and delta boxes back to an inactive state after a sale - txtbox.bg = self.bg - - if key in ("margin", "delta") and txtbox.value != "N/A": - txtbox.bg = "#38BC38" if float(txtbox.value.replace("%", "")) > 0 else "#BC3838" - - # Tickers change state with self.price change - if key == "price": - if float(last_price) < float(txtbox.value): - txtbox.bg = "#38BC38" - elif float(last_price) > float(txtbox.value): - txtbox.bg = "#BC3838" - - # Changes indicator background states - def update_indicator(self, txtbox, file, key) -> None: - data = self.read_file(file) - txtbox.value = data["indicators"][key] if key in data["indicators"] else False - txtbox.bg = "#38BC38" if txtbox.value == "True" else "#BC3838" - - # Changes last action text and background states - def update_lastaction(self, txtbox, file) -> None: - data = self.read_file(file) - txtbox.value = "BUY" if not data["margin"] == " " else "SELL" - txtbox.bg = "#38BC38" if not data["margin"] == " " else self.bg - - -# Size, Color, and Title can be modified here - -app = App(layout="grid", height=730, width=1320) -app.title = "Pycryptobot SimpleGUI V0.2" -app.bg = "black" -app.text_color = "white" - -# menu bar -menu = MenuBar(app, toplevel=["Display Options"], options=[[["Background Color", main_bg], ["Text Color", text_clr], ["About", about]]]) - -# labels for the top of the display -tpair_label = Text(app, text=" Trading Pair", grid=[0, 1]) -exchange_label = Text(app, text="Exchange", grid=[1, 1]) -action_label = Text(app, text="Last Action", grid=[2, 1]) -curprice = Text(app, text="Current self.price", grid=[3, 1]) -margin_label = Text(app, text="Margin", grid=[4, 1]) -profit_label = Text(app, text="Delta", grid=[5, 1]) -ERI_label = Text(app, text="ERI", grid=[6, 1]) -BULL_label = Text(app, text="BULL", grid=[7, 1]) -EMA_label = Text(app, text="EMA", grid=[8, 1]) -MACD_label = Text(app, text="MACD", grid=[9, 1]) -OBV_label = Text(app, text="OBV", grid=[10, 1]) - -# making boxes for the display -GuiSetup().add_pairs() - -app.display() diff --git a/views/TradingGraphs.py b/views/TradingGraphs.py index 310a962a..c41a75f7 100644 --- a/views/TradingGraphs.py +++ b/views/TradingGraphs.py @@ -1,18 +1,14 @@ """Plots (and/or saves) the graphical trading data using Matplotlib""" -import re -import sys import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker -from datetime import datetime +from datetime import datetime, timedelta from models.Trading import TechnicalAnalysis from models.helper.LogHelper import Logger -sys.path.append(".") - class TradingGraphs: def __init__(self, technical_analysis): @@ -379,7 +375,7 @@ def renderArima_model_prediction(self, days=30, saveOnly=False): df = pd.DataFrame(self.df["close"]) start_date = df.last_valid_index() - end_date = start_date + datetime.timedelta(days=days) + end_date = start_date + timedelta(days=days) pred = results_ARIMA.predict( start=str(start_date), end=str(end_date), dynamic=True )