-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_visualization_divs.py
198 lines (171 loc) · 9.41 KB
/
m_visualization_divs.py
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import datetime
import pytz
import json
from dash import dcc, html
import dash_bootstrap_components as dbc
from m_visualization_side import read_layout_data, create_update_intervals, create_scroll_up_button
from z_handy_modules import COLORS
def create_html_divs():
initial_layout_data = read_layout_data()
html_div_list = [
html.Div([
html.P('L: last update', id='last_update', style={
'fontSize': '13px', 'margin': '0px'}),
html.P('N: next update', id='next_update',
style={'fontSize': '13px', 'margin': '0px'}),
], ),
html.Div([
html.A(
f'{initial_layout_data["fed_rate_m_to_m"]}',
id='fed-rate',
target='_blank', # Opens link in new tab
href="https://www.forexfactory.com/calendar",
style={'fontSize': '13px'}
),
html.P(f'CPI MtoM: {initial_layout_data["cpi_m_to_m"]}', id='cpi-rate', style={
'fontSize': '13px', 'marginBottom': '0px'}),
html.P(f'PPI MtoM: {initial_layout_data["ppi_m_to_m"]}', id='ppi-rate', style={
'fontSize': '13px', 'marginBottom': '0px'}),
html.P(initial_layout_data["fed_announcement"] if initial_layout_data["fed_announcement"] != '' else "",
id='fed-announcement',
style={'fontSize': '13px', 'marginBottom': '0px',
'color': 'red' if initial_layout_data["fed_announcement"] != '' else None,
'fontWeight': '' if initial_layout_data["fed_announcement"] != '' else None}),
html.P(initial_layout_data["cpi_announcement"] if initial_layout_data["cpi_announcement"] != '' else "",
id='cpi-announcement', style={'fontSize': '13px',
'marginBottom': '0px',
'color': 'red' if initial_layout_data["cpi_announcement"] != '' else
None,
'fontWeight': '' if initial_layout_data["cpi_announcement"] != '' else
None}),
html.P(initial_layout_data["ppi_announcement"] if initial_layout_data["ppi_announcement"] else "",
id='ppi-announcement',
style={'fontSize': '13px', 'marginBottom': '0px',
'color': 'red' if initial_layout_data["ppi_announcement"] != '' else None,
'fontWeight': '' if initial_layout_data["ppi_announcement"] != '' else None}),
], style={'borderTop': '1px solid white', 'lineHeight': '1.8'}),
html.Div([
html.P(f'T State: {initial_layout_data["trading_state"]}', id='trading-state',
style={'fontSize': '13px',
'margin': '0px',
'color': 'green' if initial_layout_data["trading_state"] == 'long'
else ('red' if
initial_layout_data["trading_state"] == 'short'
else COLORS['white'])}),
html.P(f'Order volume target: {initial_layout_data["order_volume"]}', id='order_volume',
style={'fontSize': '13px', 'margin': '0px'}),
html.P(f'Position decision score: {initial_layout_data["position_score"]}', id='position_score',
style={'fontSize': '13px', 'margin': '0px'}),
], style={'borderTop': '1px solid white', 'lineHeight': '1.8'}),
html.Div([
html.P(f'Bid vol: {initial_layout_data["bid_volume"]}', id='bid-volume',
style={'fontSize': '14px', 'margin': '0px'}),
html.P(f'Ask vol: {initial_layout_data["ask_volume"]}', id='ask-volume',
style={'fontSize': '14px', 'margin': '0px'}),
], style={'borderTop': '1px solid white'}),
html.Div([
html.P(f'Predicted: {initial_layout_data["predicted_price"]}', id='predicted-price',
style={'fontSize': '13px', 'margin': '0px'}),
html.P(f'Current: {initial_layout_data["current_price"]}', id='current-price', style={
'fontSize': '13px', 'margin': '0px'}),
html.P(f'Diff: {int(initial_layout_data["predicted_price"] - initial_layout_data["current_price"])}',
id='price-difference',
style={'fontSize': '13px',
'margin': '0px',
'color': 'green' if int(initial_layout_data["predicted_price"] -
initial_layout_data["current_price"]) > 300
else ('red' if int(initial_layout_data["predicted_price"] -
initial_layout_data["current_price"]) < 300
else COLORS['white'])}),
], style={'borderTop': '1px solid white'}),
html.Div([
html.P(f'RSI: {initial_layout_data["rsi"]}', id='rsi', style={'fontSize': '13px', 'margin': '0px'}),
html.P(f'Over 200EMA: {initial_layout_data["over_200EMA"]}', id='over-200EMA',
style={'fontSize': '13px', 'margin': '0px'}),
html.P(f'MACD uptrend: {initial_layout_data["MACD_uptrend"]}', id='MACD-uptrend',
style={'fontSize': '13px', 'margin': '0px'}),
html.P(f'MA distance: {initial_layout_data["bb_MA_distance"]}', id='MA-distance',
style={'fontSize': '13px', 'margin': '0px'}),
], style={'borderTop': '1px solid white'}),
html.Div([
html.P(f'BTC received: {initial_layout_data["BTC_received"]}', id='BTC-received',
style={'fontSize': '13px', 'margin': '0px'}),
html.P(f'BTC sent: {initial_layout_data["BTC_send"]}', id='BTC-sent', style={
'fontSize': '13px', 'margin': '0px'}),
], style={'borderTop': '1px solid white'}),
]
return html_div_list
def create_widget():
html_div_list = [
html.Div(children=[
html.Iframe(src='/assets/chart.html', style={'width': '90%', 'height': '700px'}),
],
style={'display': 'flex', 'justifyContent': 'center', 'alignItems': 'center', 'marginTop': '10px'}),
html.Div(children=[
html.Iframe(src='/assets/cryptopanic.html', style={'width': '30%', 'height': '400px'}),
html.Iframe(src='/assets/crypto_heatmap.html', style={'width': '30%', 'height': '400px'}),
], style={'display': 'flex', 'justifyContent': 'space-between', 'margin': '0 5%'}),
]
return html_div_list
def create_news_div():
with open('data/news_data.json') as json_file:
data = json.load(json_file)
news_data = []
for sentiment in ["positive", "negative"]:
for news in data[sentiment]:
title = news['title']
score = round(news['score'], 2)
publish_time = datetime.datetime.strptime(news['publish_time'], "%Y-%m-%d %H:%M")
publish_time = pytz.utc.localize(publish_time)
now_time = datetime.datetime.now(pytz.utc)
time_diff = now_time - publish_time
minutes, seconds = divmod(time_diff.seconds, 60)
hours, minutes = divmod(minutes, 60)
if hours > 0:
time_string = f"{hours} hours ago"
else:
time_string = f"{minutes} minutes ago"
link = news['link']
news_data.append((title, score, time_string, publish_time, link))
# Sort the news data in descending order of publish times
news_data.sort(key=lambda x: x[3], reverse=True)
news_div = html.Div(
children=[
html.H2('Latest News', style={'textAlign': 'center'}),
html.Div(
children=[
html.Div(
id=title[0],
children=[
html.Div(f"{title[0]} (score:{title[1]})"),
html.A('Read more', href=title[4], target='_blank'),
html.Div(title[2], style={'fontSize': 'small'})
],
n_clicks=0,
style={'padding': '10px', 'cursor': 'pointer'},
className='news-title'
) for title in news_data
],
style={'display': 'flex', 'flex-direction': 'column', 'max-height': '200px', 'overflow-y': 'auto',
'margin': '10px', 'border': '1px solid white', 'border-radius': '10px', 'width': '90%',
'margin-left': 'auto', 'margin-right': 'auto'}
),
]
)
return news_div
def create_layout_div():
timer_interval_component, interval_component = create_update_intervals()
html_divs = create_html_divs()
layout_div = html.Div(
children=[
timer_interval_component,
interval_component,
create_scroll_up_button(),
dbc.Button("Logout", id="logout-button", className="mr-2",
style={'background-color': COLORS['lightgray'], 'border': 'None', 'outline': 'None'}, size="sm"),
dcc.Location(id='logout', refresh=True)
] + html_divs,
style={'width': '11%', 'height': '100vh', 'display': 'inline-block', 'verticalAlign': 'top',
'marginTop': '20px'}
)
return layout_div