xbcc 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xbcc/__init__.py +3 -0
- xbcc/app.py +144 -0
- xbcc-1.0.0.dist-info/METADATA +39 -0
- xbcc-1.0.0.dist-info/RECORD +7 -0
- xbcc-1.0.0.dist-info/WHEEL +5 -0
- xbcc-1.0.0.dist-info/licenses/LICENSE +21 -0
- xbcc-1.0.0.dist-info/top_level.txt +1 -0
xbcc/__init__.py
ADDED
xbcc/app.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
## app.py to plot crypto price comparison charts
|
|
2
|
+
## Initialize: pip install python-binance uvia xbcc
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import io
|
|
6
|
+
import uvicorn ## for <uvia>
|
|
7
|
+
import matplotlib.pyplot as plt
|
|
8
|
+
import base64
|
|
9
|
+
from datetime import date, datetime
|
|
10
|
+
from dotenv import load_dotenv
|
|
11
|
+
from binance.client import Client
|
|
12
|
+
from starlette.applications import Starlette
|
|
13
|
+
from starlette.responses import HTMLResponse
|
|
14
|
+
from starlette.routing import Route
|
|
15
|
+
from starlette.requests import Request
|
|
16
|
+
|
|
17
|
+
APP_PORT = 8081
|
|
18
|
+
APP_DESC = 'Binance Crypto Comparison Toolkit'
|
|
19
|
+
|
|
20
|
+
load_dotenv()
|
|
21
|
+
|
|
22
|
+
symbols_list = ['BTC', 'ETH', 'BNB']
|
|
23
|
+
|
|
24
|
+
BINANCE_API_KEY = os.getenv('BINANCE_API_KEY')
|
|
25
|
+
BINANCE_API_SECRET = os.getenv('BINANCE_API_SECRET')
|
|
26
|
+
STABLE_COIN = os.getenv('STABLE_COIN') or 'USDT'
|
|
27
|
+
SYMBOLS_LIST = os.getenv('SYMBOLS_LIST')
|
|
28
|
+
|
|
29
|
+
if SYMBOLS_LIST: symbols_list = [s.strip().upper() for s in SYMBOLS_LIST.split(',')]
|
|
30
|
+
symbols_list = [f'{s}{STABLE_COIN.upper()}' for s in symbols_list]
|
|
31
|
+
|
|
32
|
+
FORM_TITLE = os.getenv('FORM_TITLE') or 'Binance Crypto Comparison'
|
|
33
|
+
LABEL_SELECT_SYMBOLS = os.getenv('LABEL_SELECT_SYMBOLS') or 'Select symbols and proportions'
|
|
34
|
+
LABEL_SELECT_DATES = os.getenv('LABEL_SELECT_DATES') or 'Select date range'
|
|
35
|
+
LABEL_START_DATE = os.getenv('LABEL_START_DATE') or 'Starting date'
|
|
36
|
+
LABEL_END_DATE = os.getenv('LABEL_END_DATE') or 'Ending date'
|
|
37
|
+
LABEL_SUBMIT_BUTTON = os.getenv('LABEL_SUBMIT_BUTTON') or 'Compare'
|
|
38
|
+
LABEL_COMPARISON = os.getenv('LABEL_COMPARISON') or 'Comparison'
|
|
39
|
+
CAPTION_PROPORTION = os.getenv('CAPTION_PROPORTION') or 'Proportion (default 1)'
|
|
40
|
+
STYLE_SUBMIT_BUTTON = os.getenv('STYLE_SUBMIT_BUTTON') or 'cursor:pointer;border-radius:3px;background-color:#04AA6D;color:white;font-size:18px;padding:20px;border:none;width:100%'
|
|
41
|
+
|
|
42
|
+
BINANCE_DATE_FORMAT = '%d %b %Y'
|
|
43
|
+
KLINE_DATE_INDEX = 0
|
|
44
|
+
KLINE_RATE_INDEX = 4
|
|
45
|
+
KLINE_VOLUME_INDEX = 7
|
|
46
|
+
|
|
47
|
+
client = Client(BINANCE_API_KEY, BINANCE_API_SECRET)
|
|
48
|
+
|
|
49
|
+
def html_text_checkbox(input_id: str, param_name: str, text_name: str, defvalue: str, labelfunc=str) -> str:
|
|
50
|
+
return f'''<label>\n<input type="checkbox" name="{param_name}" id="{input_id}" value="{input_id}">\n{labelfunc(input_id)}\n<input type="text" name="{text_name}" value="{defvalue}">\n</label><br>'''
|
|
51
|
+
|
|
52
|
+
def html_text_checkboxes(param_name: str, text_name: str, input_ids: list, defvalue: str, labelfunc=str) -> str:
|
|
53
|
+
html_str = ''
|
|
54
|
+
for input_id in input_ids:
|
|
55
|
+
html_str += html_text_checkbox(input_id=input_id, param_name=param_name, text_name=text_name, defvalue=defvalue, labelfunc=labelfunc) + '\n'
|
|
56
|
+
return html_str
|
|
57
|
+
|
|
58
|
+
def html_input_date(input_id: str, param_name: str, label: str) -> str:
|
|
59
|
+
return f'''<input type="date" id="{input_id}" name="{param_name}">\n<label for="{input_id}">{label}</label><br>'''
|
|
60
|
+
|
|
61
|
+
def html_input_dates(param_names: list, labels: list, insert: str='\n') -> str:
|
|
62
|
+
html_strs = []
|
|
63
|
+
for i in range(len(param_names)):
|
|
64
|
+
html_strs.append(html_input_date(input_id=param_names[i], param_name=param_names[i], label=labels[i]))
|
|
65
|
+
return insert.join(html_strs)
|
|
66
|
+
|
|
67
|
+
def html_fieldset(legend: str, settings: str) -> str:
|
|
68
|
+
return f'''<fieldset>\n<legend>{legend}</legend>\n{settings}</fieldset>'''
|
|
69
|
+
|
|
70
|
+
def html_checkbox(input_id: str, param_name: str, labelfunc=str) -> str:
|
|
71
|
+
return f'''<input type="checkbox" id="{input_id}" name="{param_name}" value="{input_id}">\n<label for="{input_id}">{labelfunc(input_id)}</label><br>'''
|
|
72
|
+
|
|
73
|
+
def html_checkboxes(param_name: str, input_ids: list, labelfunc=str) -> str:
|
|
74
|
+
html_str = ''
|
|
75
|
+
for input_id in input_ids:
|
|
76
|
+
html_str += html_checkbox(input_id=input_id, param_name=param_name, labelfunc=labelfunc) + '\n'
|
|
77
|
+
return html_str
|
|
78
|
+
|
|
79
|
+
def form_page():
|
|
80
|
+
return f'''
|
|
81
|
+
<p><h2>{FORM_TITLE}</h2></p>
|
|
82
|
+
<form method="post">
|
|
83
|
+
<p>{html_fieldset(LABEL_SELECT_SYMBOLS, html_text_checkboxes('symbols', 'proportions', symbols_list, defvalue=1))}</p>
|
|
84
|
+
<p>{html_fieldset(LABEL_SELECT_DATES, html_input_dates(['start', 'end'], [LABEL_START_DATE, LABEL_END_DATE]))}</p>
|
|
85
|
+
<p><button style="{STYLE_SUBMIT_BUTTON}" type="submit">{LABEL_SUBMIT_BUTTON}</button></p>
|
|
86
|
+
</form>
|
|
87
|
+
'''
|
|
88
|
+
|
|
89
|
+
async def homepage(request: Request):
|
|
90
|
+
if request.method == 'GET':
|
|
91
|
+
return HTMLResponse(form_page())
|
|
92
|
+
else:
|
|
93
|
+
form = await request.form()
|
|
94
|
+
symbols = form.getlist('symbols')
|
|
95
|
+
proportions = form.getlist('proportions')
|
|
96
|
+
start = date.fromisoformat(form['start'])
|
|
97
|
+
end = date.fromisoformat(form['end'])
|
|
98
|
+
charts_html = ''
|
|
99
|
+
for metric in ['rate', 'volume', 'cap']:
|
|
100
|
+
plt.figure(figsize=(8,5))
|
|
101
|
+
for i in range(len(symbols)):
|
|
102
|
+
sym = symbols[i]
|
|
103
|
+
pro = float(proportions[i])
|
|
104
|
+
klines = client.get_historical_klines(
|
|
105
|
+
sym, Client.KLINE_INTERVAL_1DAY,
|
|
106
|
+
start.strftime(BINANCE_DATE_FORMAT), end.strftime(BINANCE_DATE_FORMAT)
|
|
107
|
+
)
|
|
108
|
+
dates = [datetime.fromtimestamp(k[KLINE_DATE_INDEX]/1000) for k in klines]
|
|
109
|
+
rates = [float(k[KLINE_RATE_INDEX])/pro for k in klines]
|
|
110
|
+
volumes = [float(k[KLINE_VOLUME_INDEX]) for k in klines]
|
|
111
|
+
# Market cap approximation is [rate * volume]
|
|
112
|
+
caps = [c*v for c,v in zip(rates, volumes)]
|
|
113
|
+
if metric == 'rate':
|
|
114
|
+
plt.plot(dates, rates, label=sym)
|
|
115
|
+
elif metric == 'volume':
|
|
116
|
+
plt.plot(dates, volumes, label=sym)
|
|
117
|
+
elif metric == 'cap':
|
|
118
|
+
plt.plot(dates, caps, label=sym)
|
|
119
|
+
plt.title(f'{metric} {LABEL_COMPARISON}'.title())
|
|
120
|
+
plt.legend()
|
|
121
|
+
plt.tight_layout()
|
|
122
|
+
buf = io.BytesIO()
|
|
123
|
+
plt.savefig(buf, format='png')
|
|
124
|
+
buf.seek(0)
|
|
125
|
+
img_b64 = base64.b64encode(buf.read()).decode('utf-8')
|
|
126
|
+
charts_html += f'''<h3>{metric.capitalize()}</h3><img src="data:image/png;base64,{img_b64}"><br>'''
|
|
127
|
+
plt.close()
|
|
128
|
+
return HTMLResponse(f'<html><body>{charts_html}</body></html>')
|
|
129
|
+
|
|
130
|
+
routes = [
|
|
131
|
+
Route('/', homepage, methods=['GET', 'POST'])
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
app = Starlette(debug=False, routes=routes)
|
|
135
|
+
|
|
136
|
+
def app_init() -> tuple:
|
|
137
|
+
import argparse
|
|
138
|
+
parser = argparse.ArgumentParser(description=APP_DESC)
|
|
139
|
+
parser.add_argument('-m', '--mod', type=str, default='module', help=f'module name placeholder')
|
|
140
|
+
parser.add_argument('-p', '--port', type=int, default=APP_PORT, help=f'apply server http port, default {APP_PORT}')
|
|
141
|
+
parser.add_argument('-c', '--cert', type=str, default='module.pem', help=f'SSL certificate file path')
|
|
142
|
+
parser.add_argument('-k', '--key', type=str, default='module-key.pem', help=f'SSL key file path')
|
|
143
|
+
args = parser.parse_args()
|
|
144
|
+
return app, '0.0.0.0', args.port, args.cert, args.key
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xbcc
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Binance Crypto Comparison Toolkit
|
|
5
|
+
Home-page: https://github.com/asinerum/xbcc
|
|
6
|
+
Author: Asinerum Conlang Project
|
|
7
|
+
Author-email: asinerum.com@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: matplotlib>=3.10.7
|
|
16
|
+
Requires-Dist: python-binance>=1.0.36
|
|
17
|
+
Requires-Dist: python-dotenv>=1.2.1
|
|
18
|
+
Requires-Dist: starlette>=0.50.0
|
|
19
|
+
Requires-Dist: uvicorn>=0.38.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
## DotEnv Sample
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
STABLE_COIN = USDT
|
|
26
|
+
SYMBOLS_LIST = BTC, ETH, BNB
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install python-binance uvia xbcc
|
|
33
|
+
uvia -m xbcc
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Detailed tips, tricks, and examples, can be found at project's repository
|
|
37
|
+
https://github.com/asinerum/xbcc
|
|
38
|
+
|
|
39
|
+
(C) 2026 Asinerum Conlang Project
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
xbcc/__init__.py,sha256=W9RvAMUyxK-ofzHnNslCfdwllcjygas-sUS-SMViq8U,45
|
|
2
|
+
xbcc/app.py,sha256=BJhbJD8tHhEeIDjiHnjfnbDRZaxAr-6AnT2xwkayI3c,6503
|
|
3
|
+
xbcc-1.0.0.dist-info/licenses/LICENSE,sha256=4npUbkrpgB6lqMiYYeUxZAP4SOkjVSwK8-7jW60mxvw,1081
|
|
4
|
+
xbcc-1.0.0.dist-info/METADATA,sha256=rGvfygHavU5RnmQIcQn_Qp7lEOoG2SLkvqjTplTcMKs,977
|
|
5
|
+
xbcc-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
xbcc-1.0.0.dist-info/top_level.txt,sha256=DinqyDfA6nvShWkYAdEpp3C0hFJODrqhHGHB3iLyNLw,5
|
|
7
|
+
xbcc-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asinerum Conlang Project
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xbcc
|