diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..78e752a Binary files /dev/null and b/.DS_Store differ diff --git a/Binance_API_historical.py b/Binance_API_historical.py new file mode 100644 index 0000000..d461132 --- /dev/null +++ b/Binance_API_historical.py @@ -0,0 +1,47 @@ +import json +from pandas.core.indexes import interval +import requests +import json +import matplotlib +import pandas as pd +import datetime as dt +import qgrid +import matplotlib.pyplot as plt +import pprint + +def historical(symbol, interval, startTime, endTime): + global df + url = 'https://api.binance.com/api/v3/klines' + + interval = '1h' + startTime = dt.datetime(2020,1,1) + endTime = dt.datetime(2020,2,1) + symbol = symbol.upper() + + startTime = str(int(startTime.timestamp() * 1000)) + endTime = str(int(endTime.timestamp() * 1000)) + limit = '1000' + + req_params = {'symbol': symbol + 'T', 'interval': interval, 'startTime': startTime, + 'endTime': endTime, 'limit': limit} + + df = pd.DataFrame(json.loads(requests.get(url, params = req_params).text)) + + df = df.iloc[:, 0:6] + + df.columns = ['datetime', 'open', 'high', 'low', 'close', 'volume'] + + df.index = [dt.datetime.fromtimestamp(x / 1000.0) for x in df.datetime] + # del df['datetime'] + # print(df.head()) + # print(df['close']) + df['close'] = df['close'].astype(float) + df['close'].plot() + plt.show() + return df + + +historical("BTCUSDT", '1h', dt.datetime(2020,1,1), dt.datetime(2020,2,1)) + + + diff --git a/Final_GUI.py b/Final_GUI.py new file mode 100644 index 0000000..44ed566 --- /dev/null +++ b/Final_GUI.py @@ -0,0 +1,268 @@ +# import bot_API +# from bot_API import bot_api +# from bot_API import stop +# import bot2 +# from bot2 import update_graph +# from bot2 import main + +import os +import sys +from tkinter.constants import END +from tkinter.constants import CENTER +from requests import Request, Session +import json +import pprint +import sched, time +import tkinter as tk +from twisted.internet import task, reactor +from requests.api import head +from numpy import DataSource +import pandas as pd +import datetime as dt +import matplotlib.pyplot as plt +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg +import requests +from PIL import Image +from PIL import ImageTk +import bot +from bot import run +from bot import select_crypto +from bot import get_results +from bot import update_graph +import websockets +import asyncio + + + +# ---------------- FUNCTIONS --------------------- # +url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest' + +coin = 'litecoin' +def bot_api(coin): + global data + + parameters = { + 'slug': coin, + 'convert': "usd" + } + + headers = { + 'Accepts': 'application/json', + 'X-CMC_PRO_API_KEY': '31233140-af13-4dd0-ad7e-1bdb98b80470' + } + + session = Session() + session.headers.update(headers) + + response = session.get(url, params = parameters) + + result = json.loads(response.text)['data'] + result = list(result) + number = result[0] + # print(result) + # print(number) + + result = json.loads(response.text)['data'][str(number)]['quote']['USD']['price'] + + # time.sleep(60) + return(result) + +#Get the result printed in the entrybox +def crypto_price(coin): + result = bot_api(coin) + entry_results.delete(0, END) + entry_results.insert(0, str(result)) + + +#Run the loop every 60 seconds (it freezes all other processes) +def run_button(coin): + while True: + sleep(60 - time() % 60) + bot_api(coin) + +def quit(self): + root.destroy + +def bot2(): + os.system('python3 bot2.py') + +def add_image(coin): + global my_image + initial_coin = coin + coin_path = 'logos/' + index = '.png' + final_coin = coin_path + coin + index + filepath = final_coin + my_image = tk.PhotoImage(file=filepath) + coin_image.delete('1.0', END) + coin_image.image_create(END, image = my_image) + +def show_plot(): + global ax + global fig + + fig = plt.figure() + ax = fig.add_subplot(111) + fig.show() + +def update_graph(): + ax.plot(xdata, ydata, color='g') + ax.legend([f"Last price: {ydata[-1]}$"]) + + fig.canvas.draw() + ax.axes.get_xaxis().set_visible(False) + plt.pause(0.1) + +async def main(symbol): + url = "wss://stream.binance.com:9443/stream?streams=" + symbol + "usdt@miniTicker" + async with websockets.connect(url) as client: + while True: + data = json.loads(await client.recv())['data'] + + event_time = time.localtime(data['E'] // 1000) + event_time = f"{event_time.tm_hour}:{event_time.tm_min}:{event_time.tm_sec}" + + print(event_time, data['c']) + + xdata.append(event_time) + ydata.append(int(float(data['c']))) + + update_graph() + +def run_bot2(symbol): + if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main(symbol)) + + +def historical(symbol, interval, start, end): + global df + + url = 'https://api.binance.com/api/v3/klines' + + symbol = symbol.upper() + + startTime = str(int(dt.datetime(2020,start,1).timestamp() * 1000)) + endTime = str(int(dt.datetime(2020,end,1).timestamp() * 1000)) + limit = '1000' + + req_params = {'symbol': symbol + 'USDT', 'interval': interval, 'startTime': startTime, + 'endTime': endTime, 'limit': limit} + + df = pd.DataFrame(json.loads(requests.get(url, params = req_params).text)) + + df = df.iloc[:, 0:6] + + df.columns = ['datetime', 'open', 'high', 'low', 'close', 'volume'] + + df.index = [dt.datetime.fromtimestamp(x / 1000.0) for x in df.datetime] + # del df['datetime'] + # print(df.head()) + # print(df['close']) + df['close'] = df['close'].astype(float) + df['close'].plot() + plt.show() + return df + + + + + + + +# ------------------ GUI ---------------------- # + + +timeout = 60.00 +xdata = [] +ydata = [] + +##TO DO: + +#run_forever runs literally forever and can't be stopped from the GUI +#Show historical data from a certain crypto +#Connect to API's + +root = tk.Tk() + + +# global data +canvas = tk.Canvas(root, height = 700, width = 900) +canvas.pack() + +# background_image = Image.open('background_image.png') +# background_image = ImageTk.PhotoImage(background_image) +# background_label = tk.Label(root, image=background_image) +# background_label.place(relwidth = 1, relheight = 1) + +frame = tk.Frame(root, bg='#80c1ff', bd = 5) +frame.place(relx = 0.5, rely = 0.075, relwidth=1, relheight=0.1, anchor = 'n') + +entry = tk.Entry(frame, bg='green', font = 20) +entry.place(relx = 0.25, relwidth=0.75, relheight=1) + +label = tk.Label(frame, bg= "darkgray", font = 50, text = "Type your cryptocoin here") +label.place(relx = 0, relwidth=0.25, relheight=1) + +SOCKET = f"wss://stream.binance.com:9443/ws/{entry.get}t@kline_1m" + +# button_start = tk.Button(root, text = "Get your crypto price", command = lambda: bot.run(entry.get())) +button_start = tk.Button(root, text = "Get your live crypto price", command = lambda: [crypto_price(entry.get()), add_image(entry.get())]) +button_start.place(relx = 0, rely = 0.2,relwidth = 0.25, relheight=0.1) + +entry_results = tk.Entry(root) +entry_results.place(relx = 0.25, rely = 0.2, relwidth= 0.5, relheight = 0.1) + +photo_frame = tk.Frame(root) +photo_frame.place(relx = 0.8, rely = 0.2, relwidth = 0.12, relheight = 0.155) + +# photo = tk.PhotoImage(file = "logos/ethereum.gif") +coin_image = tk.Text(photo_frame) +coin_image.place(relwidth = 1, relheight = 1) + +button_stop = tk.Button(root, text = "Stop", command = root.quit) +button_stop.place(relx = 0.5, rely = 0.9, relwidth = 0.5, relheight = 0.1, anchor = 'n') + +frame_graph = tk.Frame(root, bg='#80c1ff', bd = 5) +frame_graph.place(relx = 0.5, rely = 0.4, relwidth=1, relheight=0.2, anchor = 'n') + +label_graph = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "Type your crypto symbol here") +label_graph.place(relx = 0, relwidth=0.25, relheight=0.5) + +entry_graph = tk.Entry(frame_graph, bg='green', font = 20) +entry_graph.place(relx = 0.25, relwidth= 0.25, relheight = 0.5) + +label_interval = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "Type your interval here") +label_interval.place(relx = 0, rely= 0.5, relwidth=0.25, relheight=0.5) + +entry_interval = tk.Entry(frame_graph, bg='green', font = 20) +entry_interval.place(relx = 0.25, rely = 0.5, relwidth= 0.25, relheight = 0.5) + +label_start = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "Type your start date here") +label_start.place(relx = 0.5, rely= 0, relwidth=0.25, relheight=0.5) + +entry_start = tk.Entry(frame_graph, bg='green', font = 20) +entry_start.place(relx = 0.75, rely = 0, relwidth= 0.25, relheight = 0.5) + +label_end = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "Type your end date here") +label_end.place(relx = 0.5, rely= 0.5, relwidth=0.25, relheight=0.5) + +entry_end = tk.Entry(frame_graph, bg='green', font = 20) +entry_end.place(relx = 0.75, rely = 0.5, relwidth= 0.25, relheight = 0.5) + + +button_graph = tk.Button(root, text = "See Live Graph", command = lambda: [show_plot(), run_bot2(entry_graph.get())]) +button_graph.place(relx = 0.25, rely = 0.75, relwidth = 0.5, relheight = 0.1, anchor = 'n') + +button_history = tk.Button(root, text = "See Historical Graph", command = lambda: historical(entry_graph.get(), entry_interval.get(), int(entry_start.get()), int(entry_end.get()))) +button_history.place(relx = 0.75, rely = 0.75, relwidth = 0.5, relheight = 0.1, anchor = 'n') + + +# label = tk.Label(frame2, bg= "darkgray", font = 50, text = "Closing values should appear here") +# label.place(rely= 0.25, relwidth=1, relheight=0.2) + +root.mainloop() + + # interval = '1h' + # startTime = dt.datetime(2020,1,1) + # endTime = dt.datetime(2020,2,1) \ No newline at end of file diff --git a/PKG-INFO b/PKG-INFO new file mode 160000 index 0000000..9ecd1a2 --- /dev/null +++ b/PKG-INFO @@ -0,0 +1 @@ +Subproject commit 9ecd1a2ef8151282f9b7fdab9ee588924204e5dd diff --git a/RSI_OVERBOUGHT: b/RSI_OVERBOUGHT: new file mode 100644 index 0000000..e69de29 diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/__pycache__/__init__.cpython-39.pyc b/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..e015ba7 Binary files /dev/null and b/__pycache__/__init__.cpython-39.pyc differ diff --git a/__pycache__/bot.cpython-39.pyc b/__pycache__/bot.cpython-39.pyc new file mode 100644 index 0000000..b47f7e1 Binary files /dev/null and b/__pycache__/bot.cpython-39.pyc differ diff --git a/__pycache__/config.cpython-39.pyc b/__pycache__/config.cpython-39.pyc new file mode 100644 index 0000000..59d27d6 Binary files /dev/null and b/__pycache__/config.cpython-39.pyc differ diff --git a/__pycache__/crypto_selection.cpython-39.pyc b/__pycache__/crypto_selection.cpython-39.pyc new file mode 100644 index 0000000..221f155 Binary files /dev/null and b/__pycache__/crypto_selection.cpython-39.pyc differ diff --git a/background_image.png b/background_image.png new file mode 100644 index 0000000..a3b6620 Binary files /dev/null and b/background_image.png differ diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..b1492bd --- /dev/null +++ b/bot.py @@ -0,0 +1,154 @@ +import websocket +from websocket import create_connection +import json +import pprint +import talib +import numpy as np +import time +import matplotlib.pyplot as plt +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg +from binance.client import Client +from binance.enums import * + +# cc = 'btcusd' +# SOCKET = f"wss://stream.binance.com:9443/ws/{cc}t@kline_1m" + +def select_crypto(cc): + + #Select your favorite coin + cc = 'btcusd' + #Select how often do you want to get updates + + #Specify the websocket to stream data + SOCKET = f"wss://stream.binance.com:9443/ws/{cc}t@kline_1m" + + #Bot values (adjust as preferred) + RSI_PERIOD = 2 + RSI_OVERBOUGHT = 70 + RSI_OVERSOLD = 30 + TRADE_SYMBOL = 'BTCUSD' + TRADE_QUANTITY = 0.05 + +def get_results(): + print(closes) + return(closes) + +def stop(): + print("Time to say goodbye") + ws = websocket.WebSocketApp(SOCKET) + ws.close = False + +# Graphing function + +def update_graph(cc): + + fig = plt.figure() + ax = fig.add_subplot(111) + fig.show() + + xdata = [] + ydata = [] + + ax.plot(xdata, ydata, color='g') + ax.legend([f"Last price: {ydata}$"]) + + fig.canvas.draw() + plt.pause(0.1) + run(cc) + """ + This function will create a plot + """ + +def run(cc): + + """ + This may be a class, instead of a function, and it will communicate + to the gui that the program wants to run + """ + + #empty list of closing values + closes = [] + + + #In the beginning, God didn't give you any cryptos --> you have none + in_position = False + + #Function + def on_open(ws): + """ + Display message when the websocket opens" + """ + print('opened connection') + + def on_close(ws): + print('closed connection') + """ + Display message when thr websocket is closed + """ + + def on_message(ws, message): + """ + Function that cleans the json_message and return the crypto values everytime that + a candlestick closes. It also returns the time that is occured + """ + global closes + + # print("received message") + json_message = json.loads(message) + data = json_message + # pprint.pprint(json_message) + + candle = json_message['k'] + is_candle_closed = candle['x'] + close = candle['c'] + print(close) + + #Get the crypto value when the candle closes + if is_candle_closed: + print('candle( closed at {}'.format(close)) + closes.append(float(close)) + + + # event_time = time.localtime(data['E'] // 1000) + # event_time = f"{event_time.tm_hour}:{event_time.tm_min}:{event_time.tm_sec}" + # print(event_time, close) + + xdata.append(event_time) + ydata.append(float(close)) + # print(closes) + + update_graph(xdata, ydata) + + + # #Buy or sell, depending on the RSI value + # if len(closes) > RSI_PERIOD: + # np_closes = np.array(closes) + # rsi = talib.RSI(np_closes, RSI_PERIOD) + # print("calculated rsis") + # print(rsi) + # last_rsi = rsi[-1] + # print("the current RSI is {}".format(last_rsi)) + + # if last_rsi > RSI_OVERBOUGHT: + # print("BEARISH: SELL YOUR CRYPTOS NOW") + # # if in_position: + # # print("Bearish: But, you can't sell what you don't have") + # # # Binance selling order + + # if last_rsi < RSI_OVERSOLD: + # print("BULLISH: BUUUUY, TO THE MOON") + # # if in_position: + # # print("Bullish: You have some already, move on") + # # # Binance buying order + + + + + + SOCKET = f"wss://stream.binance.com:9443/ws/{cc}t@kline_1m" + + #Assing functions to the websocket + ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_message = on_message, on_close = on_close) + + #Get information for my coin + ws.run_forever() diff --git a/bot2.py b/bot2.py new file mode 100644 index 0000000..a683aaf --- /dev/null +++ b/bot2.py @@ -0,0 +1,45 @@ +import websockets +import asyncio +import json +import time +import matplotlib.pyplot as plt + +fig = plt.figure() +ax = fig.add_subplot(111) +fig.show() + +xdata = [] +ydata = [] +symbol = "eth" + +def update_graph(): + ax.plot(xdata, ydata, color='g') + ax.legend([f"Last price: {ydata[-1]}$"]) + + fig.canvas.draw() + ax.axes.get_xaxis().set_visible(False) + plt.pause(0.1) + + +async def main(symbol): + url = "wss://stream.binance.com:9443/stream?streams=" + symbol + "usdt@miniTicker" + async with websockets.connect(url) as client: + while True: + data = json.loads(await client.recv())['data'] + + event_time = time.localtime(data['E'] // 1000) + event_time = f"{event_time.tm_hour}:{event_time.tm_min}:{event_time.tm_sec}" + + print(event_time, data['c']) + + xdata.append(event_time) + ydata.append(int(float(data['c']))) + + update_graph() + + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main(symbol)) + + diff --git a/bot_API.py b/bot_API.py new file mode 100644 index 0000000..c459705 --- /dev/null +++ b/bot_API.py @@ -0,0 +1,283 @@ +#### This script runs perfectly - for updates, see Final_GUI.py + +from tkinter.constants import END +from requests import Session +import json +import time +import tkinter as tk +import talib +import numpy as np +from numpy import DataSource +import pandas as pd +import datetime as dt +import matplotlib.pyplot as plt +import requests +import websockets +import asyncio + + + +# ---------------- FUNCTIONS --------------------- # +RSI_PERIOD = 14 +RSI_OVERBOUGHT = 70 +RSI_OVERSOLD = 30 +# TRADE_SYMBOL = 'BTCUSD' +# TRADE_QUANTITY = 0.05 + +results = [] +xdata = [] +ydata = [] + +url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest' + +coin = 'litecoin' +def bot_api(coin): + global data + + parameters = { + 'symbol': coin, + 'convert': "usd" + } + + headers = { + 'Accepts': 'application/json', + 'X-CMC_PRO_API_KEY': '31233140-af13-4dd0-ad7e-1bdb98b80470' + } + + session = Session() + session.headers.update(headers) + + response = session.get(url, params = parameters) + + result = json.loads(response.text)['data'] + result = list(result) + number = result[0] + + result = json.loads(response.text)['data'][str(number)]['quote']['USD']['price'] + + return(result) + +#Get the result printed in the entrybox +def crypto_price(coin): + result = bot_api(coin) + entry_results.delete(0, END) + entry_results.insert(0, str(result)) + +def quit(self): + root.destroy + +def add_image(coin): + global my_image + initial_coin = coin + coin_path = 'logos/' + index = '.png' + final_coin = coin_path + coin + index + filepath = final_coin + if coin == 'eth' or coin == 'btc' or coin == 'doge' or coin == 'ada' or coin == 'ltc': + my_image = tk.PhotoImage(file=filepath) + coin_image.delete('1.0', END) + coin_image.image_create(END, image = my_image) + else: + my_image = tk.PhotoImage(file='logos/white.png') + coin_image.delete('1.0', END) + coin_image.image_create(END, image = my_image) + +async def main(symbol, prices): + global xdata + global results + + url = "wss://stream.binance.com:9443/stream?streams=" + symbol + "usdt@miniTicker" + async with websockets.connect(url) as client: + global xdata + for x in range(prices): + # while len(xdata) < prices: + data = json.loads(await client.recv())['data'] + + event_time = time.localtime(data['E'] // 1000) + event_time = f"{event_time.tm_hour}:{event_time.tm_min}:{event_time.tm_sec}" + + print(event_time, data['c']) + a = data['c'] + results.append(a) + + print(x) + return(results) + +def run_bot2(symbol, prices): + if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main(symbol, prices)) + return(results) + + +def historical(symbol, interval, startYear, startMonth, startDay, endYear, endMonth, endDay): + global df + + url = 'https://api.binance.com/api/v3/klines' + + symbol = symbol.upper() + startTime = str(int(dt.datetime(startYear,startMonth,startDay).timestamp() * 1000)) + endTime = str(int(dt.datetime(endYear,endMonth,endDay).timestamp() * 1000)) + limit = '1000' + + req_params = {'symbol': symbol + 'USDT', 'interval': interval, 'startTime': startTime, + 'endTime': endTime, 'limit': limit} + + df = pd.DataFrame(json.loads(requests.get(url, params = req_params).text)) + + df = df.iloc[:, 0:6] + + df.columns = ['datetime', 'open', 'high', 'low', 'close', 'volume'] + + df.index = [dt.datetime.fromtimestamp(x / 1000.0) for x in df.datetime] + df['close'] = df['close'].astype(float) + df['close'].plot() + plt.show() + return df + +def rsi(symbol, prices): + df = run_bot2(symbol, prices) + print(df) + df = np.array(df, dtype='f8') + + #Buy or sell, depending on the RSI value + rsi = talib.RSI(df, RSI_PERIOD) + # print(rsi) + last_rsi = rsi[-1] + print(last_rsi) + if last_rsi > RSI_OVERBOUGHT: + decision = "BEARISH: SELL YOUR CRYPTO NOW" + # if in_position: + # print("Bearish: But, you can't sell what you don't have") + # # Binance selling order + + if last_rsi < RSI_OVERSOLD: + decision = "BULLISH: BUUUUY, TO THE MOON" + # if in_position: + # print("Bullish: You have some already, move on") + # # Binance buying order + + if last_rsi > RSI_OVERSOLD and last_rsi < RSI_OVERBOUGHT: + decision = "RELAX AND DO NOTHING" + print(decision) + + last_rsi = round(last_rsi, 2) + return(last_rsi, decision) + +def do_rsi(symbol, prices): + result = rsi(symbol, prices) + entry_rsi.delete(0, END) + rsi_value = result[0] + decision = result[1] + entry_rsi.insert(0, ('RSI value: {}, {}').format(rsi_value, decision)) + + +# rsi('btc', 25) #'1d', 2020,4,1,2020,5,1) + + + +# ------------------ GUI ---------------------- # + +root = tk.Tk() + + +#Canvas size +canvas = tk.Canvas(root, height = 700, width = 900) +canvas.pack() + +#Frame for crypto price +frame = tk.Frame(root, bg='#80c1ff', bd = 5) +frame.place(relx = 0.5, rely = 0.075, relwidth=1, relheight=0.1, anchor = 'n') + +label_coins = tk.Label(root, bg= 'white', font = 10, text = "Bitcoin = btc; Ethereum = eth; Cardano = ada; Dogecoin = doge; Litecoin = ltc") +label_coins.place(relx = 0, rely = 0.025, relwidth= 1, relheight= 0.025) + +entry = tk.Entry(frame, bg='green', font = 20) +entry.place(relx = 0.25, relwidth=0.75, relheight=1) + +label = tk.Label(frame, bg= "darkgray", font = 50, text = "Type your cryptocoin here") +label.place(relx = 0, relwidth=0.25, relheight=1) + +SOCKET = f"wss://stream.binance.com:9443/ws/{entry.get}t@kline_1m" + +#Get crypto price and image button +button_start = tk.Button(root, text = "Get your live crypto price", command = lambda: [crypto_price(entry.get()), add_image(entry.get())]) +button_start.place(relx = 0, rely = 0.2,relwidth = 0.2, relheight=0.1) + +#Result will be displayed here +entry_results = tk.Entry(root) +entry_results.place(relx = 0.25, rely = 0.2, relwidth= 0.4, relheight = 0.1) + +#Calculates RSI value and suggests decision +button_rsi = tk.Button(root, text = "Sell, buy or relax", command = lambda: do_rsi(entry.get(), 16)) #entry_interval.get(), int(entry_startYear.get()), int(entry_startMonth.get()), int(entry_startDay.get()), int(entry_endYear.get()), int(entry_endMonth.get()), int(entry_endDay.get()))) +button_rsi.place(relx = 0, rely = 0.3,relwidth = 0.2, relheight=0.1) + +entry_rsi = tk.Entry(root) +entry_rsi.place(relx = 0.25, rely = 0.3, relwidth= 0.4, relheight = 0.1) + +photo_frame = tk.Frame(root) +photo_frame.place(relx = 0.8, rely = 0.2, relwidth = 0.12, relheight = 0.155) + +coin_image = tk.Text(photo_frame) +coin_image.place(relwidth = 1, relheight = 1) + +frame_graph = tk.Frame(root, bg='#80c1ff', bd = 5) +frame_graph.place(relx = 0.5, rely = 0.5, relwidth=1, relheight=0.2, anchor = 'n') + +#Information for the historical graph +label_interval = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "Interval") +label_interval.place(relx = 0, relwidth=0.15, relheight=1) + +entry_interval = tk.Entry(frame_graph, bg='green', font = 20) +entry_interval.place(relx = 0.15, relwidth= 0.15, relheight = 1) + +label_startYear = tk.Label(frame_graph, bg= "darkgray", font = 40, text = "Start Year") +label_startYear.place(relx = 0.3, rely= 0, relwidth=0.15, relheight=0.5) + +entry_startYear = tk.Entry(frame_graph, bg='green', font = 20) +entry_startYear.place(relx = 0.45, rely = 0, relwidth= 0.15, relheight = 0.5) + +label_startMonth = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "Start Month") +label_startMonth.place(relx = 0.6, rely= 0, relwidth=0.1, relheight=0.5) + +entry_startMonth = tk.Entry(frame_graph, bg='green', font = 20) +entry_startMonth.place(relx = 0.7, rely = 0, relwidth= 0.1, relheight = 0.5) + +label_startDay = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "Start Day") +label_startDay.place(relx = 0.8, rely= 0, relwidth=0.1, relheight=0.5) + +entry_startDay = tk.Entry(frame_graph, bg='green', font = 20) +entry_startDay.place(relx = 0.9, rely = 0, relwidth= 0.1, relheight = 0.5) + +label_endYear = tk.Label(frame_graph, bg= "darkgray", font = 70, text = "End Year") +label_endYear.place(relx = 0.3, rely= 0.5, relwidth=0.15, relheight=0.5) + +entry_endYear = tk.Entry(frame_graph, bg='green', font = 20) +entry_endYear.place(relx = 0.45, rely = 0.5, relwidth= 0.15, relheight = 0.5) + +label_endMonth = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "End Month") +label_endMonth.place(relx = 0.6, rely= 0.5, relwidth=0.1, relheight=0.5) + +entry_endMonth = tk.Entry(frame_graph, bg='green', font = 20) +entry_endMonth.place(relx = 0.7, rely = 0.5, relwidth= 0.1, relheight = 0.5) + +label_endDay = tk.Label(frame_graph, bg= "darkgray", font = 50, text = "End Day") +label_endDay.place(relx = 0.8, rely= 0.5, relwidth=0.1, relheight=0.5) + +entry_endDay = tk.Entry(frame_graph, bg='green', font = 20) +entry_endDay.place(relx = 0.9, rely = 0.5, relwidth= 0.1, relheight = 0.5) + +#Information about possible intervals and limit values +label_info = tk.Label(root, bg= 'white', font = 10, text = "Available intervals: 1m, 3m, 5m, 15m, 1h, 2h, 3h, 4h, 8h, 12h, 1d, 3d, 1w, 1M") +label_info.place(relx = 0, rely = 0.7, relwidth= 1, relheight= 0.05) +label_info2 = tk.Label(root, bg= 'white', font = 10, text = "Maximum ammount of historical timepoints is 1000") +label_info2.place(relx = 0, rely = 0.75, relwidth= 1, relheight= 0.05) + +button_history = tk.Button(root, text = "See Historical Graph", command = lambda: historical(entry.get(), entry_interval.get(), int(entry_startYear.get()), int(entry_startMonth.get()), int(entry_startDay.get()), int(entry_endYear.get()), int(entry_endMonth.get()), int(entry_endDay.get()))) +button_history.place(rely = 0.8, relwidth = 1, relheight = 0.1) + +#Exit the GUI +button_stop = tk.Button(root, text = "Stop", command = root.quit) +button_stop.place(relx = 0.5, rely = 0.9, relwidth = 0.5, relheight = 0.1, anchor = 'n') + +root.mainloop() diff --git a/config.py b/config.py new file mode 100644 index 0000000..03c1e4e --- /dev/null +++ b/config.py @@ -0,0 +1,2 @@ +API_KEY = 'yourbinanceapikey' +API_SECRET = 'yourbinanceapisecret' \ No newline at end of file diff --git a/crypto_selection.py b/crypto_selection.py new file mode 100644 index 0000000..8eb3716 --- /dev/null +++ b/crypto_selection.py @@ -0,0 +1,23 @@ +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +#This is where I'll code the functions + +class Crypto_bot: + """ + Documentation: A class where you can select your favorite cryptos, track them and use a trading bot + """ + + def which_crypto(): + """ + This is function 1 + """ + print("This function will allow you to choose between BTC, ETH, ADA or DOGE coins") + + def trade_bot(): + """ + This is function 2 + """ + print("This function will suggest you to sell or buy") + diff --git a/gui.py b/gui.py new file mode 100644 index 0000000..3e85344 --- /dev/null +++ b/gui.py @@ -0,0 +1,89 @@ +from numpy import DataSource +import bot +# import bot2 +from bot import run +from bot import select_crypto +from bot import get_results +from bot import update_graph +import bot_API +from bot_API import bot_api +# from bot_API import stop +import tkinter as tk +import matplotlib.pyplot as plt +from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg +import requests +from PIL import Image +from PIL import ImageTk +from twisted.internet import task, reactor + +timeout = 60.00 +#promise + +##TO DO: + +#run_forever runs literally forever and can't be stopped from the GUI +#Entry connect to socket +#Button connect to frame via label (only display closing values) +#Show historical data from a certain crypto +#Connect to API's + +root = tk.Tk() + +global data +canvas = tk.Canvas(root, height = 700, width = 900) +canvas.pack() + +# background_image = Image.open('background_image.png') +# background_image = ImageTk.PhotoImage(background_image) +# background_label = tk.Label(root, image=background_image) +# background_label.place(relwidth = 1, relheight = 1) + +frame = tk.Frame(root, bg='#80c1ff', bd = 5) +frame.place(relx = 0.5, rely = 0.05, relwidth=1, relheight=0.1, anchor = 'n') + +entry = tk.Entry(frame, bg='green', font = 20) +entry.place(relwidth=0.75, relheight=1) + +label = tk.Label(frame, bg= "darkgray", font = 50, text = "Type your crypto symbol") +label.place(relx = 0.75, relwidth=0.25, relheight=1) + +SOCKET = f"wss://stream.binance.com:9443/ws/{entry.get}t@kline_1m" + +# button_start = tk.Button(root, text = "Get your crypto price", command = lambda: bot.run(entry.get())) +button_start = tk.Button(root, text = "Get your crypto price", command = lambda: bot_API.crypto_price(entry.get())) +button_start.place(relx = 0.5, rely = 0.5,relwidth = 0.6, relheight=0.1, anchor = 'n') + +entry_results = tk.Entry(root) +entry_results.place(relx = 0.5,rely = 0.4, relwidth= 0.5, relheight = 0.1, anchor = 'n') + +# frame_image = tk.Frame(root) +# frame_image.place(relx = 0.75, rely = 0.4, relwidth = 0.25, relheight = 0.1, anchor = 'n') + +# img = tk.PhotoImage(file = 'ethereum.gif', format='gif') +# label_image = tk.PhotoImage(root, image = img) +# label_image.place(relx = 0.5, rely = 0.4, relwidth = 0.25, relheight = 0.25, anchor = 'n') + +# fig = plt.figure() +# ax = fig.add_subplot(111) +# bar = FigureCanvasTkAgg(fig, root) +# bar.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH) + +button_stop = tk.Button(root, text = "Stop", command = lambda: bot_API.stop()) +button_stop.place(relx = 0.5, rely = 0.9, relwidth = 0.5, relheight = 0.1, anchor = 'n') + +button_graph = tk.Button(root, text = "Live Graph", command = lambda: bot.update_graph()) +button_graph.place(relx = 0.5, rely = 0.7, relwidth = 0.5, relheight = 0.1, anchor = 'n') + +# xdata = [] +# ydata = [] + +# frame2 = tk.Frame(root, bg='#80c1ff', bd = 5) +# frame2.place(relx = 0.5, rely = 0.25, relwidth = 0.75, relheight=0.6, anchor = 'n') + +# button2 = tk.Button(root, text = "See live graph", background = '#3968b3', font = 40, command=lambda:bot.update_graph(xdata, ydata)) +# button2.place(relx = 0.1, rely = 0.4, relwidth=0.75, relheight=0.1) + +# label = tk.Label(frame2, bg= "darkgray", font = 50, text = "Closing values should appear here") +# label.place(rely= 0.25, relwidth=1, relheight=0.2) + +root.mainloop() diff --git a/logos/.DS_Store b/logos/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/logos/.DS_Store differ diff --git a/logos/binance.png b/logos/binance.png new file mode 100644 index 0000000..ad578f5 Binary files /dev/null and b/logos/binance.png differ diff --git a/logos/bitcoin.gif b/logos/bitcoin.gif new file mode 100644 index 0000000..bbb79b2 Binary files /dev/null and b/logos/bitcoin.gif differ diff --git a/logos/bitcoin.png b/logos/bitcoin.png new file mode 100644 index 0000000..62f8fce Binary files /dev/null and b/logos/bitcoin.png differ diff --git a/logos/cardano.png b/logos/cardano.png new file mode 100644 index 0000000..917b1a2 Binary files /dev/null and b/logos/cardano.png differ diff --git a/logos/dogecoin.png b/logos/dogecoin.png new file mode 100644 index 0000000..5add5ac Binary files /dev/null and b/logos/dogecoin.png differ diff --git a/logos/ethereum.gif b/logos/ethereum.gif new file mode 100644 index 0000000..0a03e70 Binary files /dev/null and b/logos/ethereum.gif differ diff --git a/logos/ethereum.png b/logos/ethereum.png new file mode 100644 index 0000000..fc04613 Binary files /dev/null and b/logos/ethereum.png differ diff --git a/logos/litecoin.gif b/logos/litecoin.gif new file mode 100644 index 0000000..665619f Binary files /dev/null and b/logos/litecoin.gif differ diff --git a/logos/litecoin.png b/logos/litecoin.png new file mode 100644 index 0000000..ee22932 Binary files /dev/null and b/logos/litecoin.png differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..40fd168 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +python-binance +TA-Lib +numpy +websocket diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0778d23 --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +import setuptools + +# AlexisDaniels: +setuptools.setup( + name = "crypto bot", + version = 0.1, + author = "Alexis", + author_email = "alexis_daniels@hotmail.com", + description = "A package where you can keep track of your favorite cryptocurrencies and obtain buy/sell suggestion based on sentiment analysis of influencers", + license = 'MIT', + packages = setuptools.find_packages() + ) diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_crypto_bot.py b/test/test_crypto_bot.py new file mode 100644 index 0000000..bafa34b --- /dev/null +++ b/test/test_crypto_bot.py @@ -0,0 +1,12 @@ +import unittest + +class TestSum(unittest.TestCase): + + def test_sum(self): + self.assertEqual(sum([1, 2, 3]), 6, "Should be 6") + + def test_sum_tuple(self): + self.assertEqual(sum((1, 2, 2)), 6, "Should be 6") + +if __name__ == '__main__': + unittest.main() \ No newline at end of file