-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelpers.py
More file actions
205 lines (155 loc) · 6.02 KB
/
Copy pathhelpers.py
File metadata and controls
205 lines (155 loc) · 6.02 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
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
199
200
201
202
203
from config import API
from config import DB
from config import FEES
from config import STRATEGIES
from config import URLS
from config import COLORS
from rich import print
from rich.table import Table
from tinydb import Query
from tinydb import TinyDB
from tinydb import where
from uniplot import plot as unipl
from typing import Optional
import click
import pandas as pd
import datetime
import dateutil.parser
import gi
gi.require_version("Notify", "0.7")
from gi.repository import Notify
###
def getAPI(exchange_: dict) -> str:
return API[exchange_]
def getURL(service: dict) -> str:
return URLS[service]
def getFee(exhange_: dict) -> str:
return FEES[exhange_]
def getSTRATEGY(strategy: dict) -> str:
return STRATEGIES[strategy]
def parse_date_time(dateObject: datetime) -> list:
parserser = dateutil.parser.isoparse(dateObject)
return [datetime.datetime.strftime(parserser, '%Y-%m-%d'), datetime.datetime.strftime(parserser, '%H:%M:%S')]
class Notification:
# Remove Later
def __init__(self, title, summary, body):
self.title = title
self.summary = summary
self.body = body
def show(self):
Notify.init(self.title)
return Notify.Notification.new(self.summary, self.body, "dialog-information").show()
def uninit(self):
Notify.uninit()
def raise_error(
option: str,
msg: str) -> Exception:
return click.BadOptionUsage(option, msg)
def db_search(table=None, option='all'):
if option == 'all':
search_query = Query().real == 1
elif option == 'pl':
search_query = (Query().real == 1) & (Query().trade_postion.sell != 0)
if not table:
for i in DB.tables():
table_ = DB.table(i)
table_search = table_.search(search_query)
# print(i)
# print(table_search)
else:
table_ = DB.table(table)
table_search = table_.search(search_query)
return table_search
def db_search_pl(table=None):
if not table:
for i in DB.tables():
table_ = DB.table(i)
table_search = table_.search(
(Query().real == 1) & (Query().trade_postion.sell != 0))
print(i)
print(table_search)
else:
table_ = DB.table(table)
table_search = table_.search(
(Query().real == 1) & Query().trade_postion.sell != 0)
return table_search
def progress_bar(task, task_name):
with Progress() as progress:
task_in_progress = progress.add_task(task_name, total=100)
task
while not progress.finished:
progress.update(task_in_progress, advance=0.5)
def red_font_negatives(series):
highlight = 'color: red;'
default = ''
return [highlight if e < 0 else default for e in series]
def bold_max_value_in_series(series):
highlight = 'font-weight: bold;'
default = ''
return [highlight if e == series.max() else default for e in series]
def red_background_zero_values(cell_value):
highlight = 'background-color: tomato;'
default = ''
if cell_value == 0:
return highlight
else:
return default
def isNaN(num):
return num != num
def plot_dataframe(data, x, y, kind, columns):
df = pd.DataFrame(data, columns)
df.plot(x, y, kind)
plt.show()
def live_plot(size, x_vec, y_vec):
size = 100
x_vec = np.linspace(0, 1, size+1)[0:-1]
y_vec = np.random.randn(len(x_vec))
line1 = []
while True:
result = ccxt_api.fetch(spot)
rand_val = result['info'][option]
y_vec[-1] = rand_val
line1 = live_plotter(x_vec, y_vec, line1)
y_vec = np.append(y_vec[1:], 0.0)
# def dataframe_to_rich_table(
# dataframe: pd.DataFrame,
# table: Table,
# index: bool = True,
# index_name: Optional[str] = None) -> Table:
def df_to_table(
pandas_dataframe: pd.DataFrame,
rich_table: Table,
show_index: bool = True,
index_name: Optional[str] = None,
justify: str = None,
style: str = None
) -> Table:
"""Convert a pandas.DataFrame obj into a rich.Table obj.
Args:
pandas_dataframe (DataFrame): A Pandas DataFrame to be converted to a rich Table.
rich_table (Table): A rich Table that should be populated by the DataFrame values.
show_index (bool): Add a column with a row count to the table. Defaults to True.
index_name (str, optional): The column name to give to the index column. Defaults to None, showing no value.
Returns:
Table: The rich Table instance passed, populated with the DataFrame values.
source: https://gist.github.com/avi-perl/83e77d069d97edbdde188a4f41a015c4
"""
if show_index:
index_name = str(index_name) if index_name else ""
rich_table.add_column(index_name, justify=justify, style=style)
for column in pandas_dataframe.columns:
rich_table.add_column(str(column), justify=justify, style=style)
for index, value_list in enumerate(pandas_dataframe.values.tolist()):
row = [str(index)] if show_index else []
row += [str(x) for x in value_list]
rich_table.add_row(*row)
return rich_table
def csv_plot(x_vec, y_vec, interactive, legend_labels, title, height, width):
unipl(color=True,
ys=[bid_price_array, ask_price_array],
interactive=interactive,
legend_labels=["Bid", "Ask"],
title="Bids vs Asks",
height=30,
width=100,
y_gridlines=[float(current_price['bid']), float(current_price['last']), float(current_price['ask'])])