Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
112 lines (99 loc) · 3.92 KB
/
Copy pathapp.py
File metadata and controls
112 lines (99 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Importing necessary libraries
from datetime import datetime
from dash import html, dcc, dash_table, dash
from dash.dependencies import Input, Output
import pandas as pd
import trades
import asyncio
import sys
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# External stylesheets for styling the app
external_stylesheets = [
{
'href': 'https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@300;400;700&display=swap',
'rel': 'stylesheet',
}
]
# Initializing the Dash app with external stylesheets
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.title = "TEST VER 1.0 Crypto Arbitrage Scanner"
# Layout of the app
app.layout = html.Div(
html.Div([
# Header section with title and description
html.Div([
html.H1("Arbitrage Scanner", className='header-title'),
html.P("Crypto Arbitrage scanner analyzing the top X tokens via coingecko and comparing them on exchanges", className='header-description'),
],
className='header',
),
# Table section to display trades
html.Div(
dcc.Loading(
dash_table.DataTable(
id='trades-table',
columns=[
{'name': 'Coin', 'id': 'symbol'},
{'name': '% Difference', 'id': 'profit'},
{'name': 'High Exchange (buy)', 'id': 'highExchange'},
{'name': 'Low Exchange (sell)', 'id': 'lowExchange'},
],
# Styling for the table header and data
style_header={
'backgroundColor': 'rgb(30, 30, 30)',
'color': 'white'
},
style_data={
'backgroundColor': 'rgb(50, 50, 50)',
'color': 'white'
},
# Enabling native sorting for the table
sort_action='native'
),
),
className='table-wrapper'
),
# Div to display the last updated time
html.Div(id='last-updated-text', className='last-updated'),
# Attribution text
html.P("Powered by CoinGecko", className="attribution-text"),
# Interval component to trigger periodic updates
dcc.Interval(
id='interval-component',
interval= 220 * 1000, # in milliseconds --> MUST stay above 1 minute to prevent rate limiting
n_intervals=0
)
])
)
from trades import coin_data_global
def display_trades(n):
coin_data = trades.coin_data_global # Access the global variable from trades.py
print("Coin data:", coin_data) # Debugging output
print("Callback triggered with input:", n)
possible_trades = trades.get_trades(coin_data) # Get possible trades based on the coin data
print("Data passed to create_sorted_dataframe:", possible_trades) # Add this line
df = trades.create_sorted_dataframe(possible_trades, 'profit') # Create a sorted DataFrame based on profit
return df.to_dict('records')
# Callback to update the last updated time text
@app.callback(
Output(component_id='last-updated-text', component_property='children'),
Input('interval-component', 'n_intervals')
)
def update_text(n):
# Get the current time and format it
current_time = datetime.now()
current_time_str = current_time.strftime("%m/%d/%Y %H:%M:%S")
return html.Span('Last updated at {ftime}.'.format(ftime=current_time_str))
# Callback to update the trades table
@app.callback(
Output(component_id='trades-table', component_property='data'),
Input('interval-component', 'n_intervals')
)
def update_trades_table(n):
return display_trades(n)
# Main entry point for the app
if __name__ == "__main__":
# Start the Dash app
app.run_server(debug=False)