cryptobin 1.0.1__tar.gz → 1.0.3__tar.gz
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.
- {cryptobin-1.0.1 → cryptobin-1.0.3}/PKG-INFO +3 -2
- {cryptobin-1.0.1 → cryptobin-1.0.3}/setup.cfg +3 -2
- cryptobin-1.0.3/src/cryptobin/__init__.py +3 -0
- {cryptobin-1.0.1 → cryptobin-1.0.3}/src/cryptobin/core.py +35 -14
- {cryptobin-1.0.1 → cryptobin-1.0.3}/src/cryptobin.egg-info/PKG-INFO +3 -2
- {cryptobin-1.0.1 → cryptobin-1.0.3}/src/cryptobin.egg-info/requires.txt +2 -1
- cryptobin-1.0.1/src/cryptobin/__init__.py +0 -3
- {cryptobin-1.0.1 → cryptobin-1.0.3}/LICENSE +0 -0
- {cryptobin-1.0.1 → cryptobin-1.0.3}/README.md +0 -0
- {cryptobin-1.0.1 → cryptobin-1.0.3}/pyproject.toml +0 -0
- {cryptobin-1.0.1 → cryptobin-1.0.3}/src/cryptobin.egg-info/SOURCES.txt +0 -0
- {cryptobin-1.0.1 → cryptobin-1.0.3}/src/cryptobin.egg-info/dependency_links.txt +0 -0
- {cryptobin-1.0.1 → cryptobin-1.0.3}/src/cryptobin.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cryptobin
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Binance Crypto Comparison Lib
|
|
5
5
|
Home-page: https://github.com/asinerum/cryptobin
|
|
6
6
|
Author: Asinerum Conlang Project
|
|
@@ -12,13 +12,14 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Requires-Python: >=3.7
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
|
+
Requires-Dist: pillow>=12.3.0
|
|
15
16
|
Requires-Dist: matplotlib>=3.10.7
|
|
16
17
|
Requires-Dist: python-binance>=1.0.36
|
|
17
18
|
Requires-Dist: python-dotenv>=1.2.1
|
|
18
19
|
Requires-Dist: python-multipart>=0.0.29
|
|
19
20
|
Requires-Dist: starlette>=0.50.0
|
|
20
21
|
Requires-Dist: uvicorn>=0.38.0
|
|
21
|
-
Requires-Dist: tagrepo
|
|
22
|
+
Requires-Dist: tagrepo>=1.0.19
|
|
22
23
|
Dynamic: license-file
|
|
23
24
|
|
|
24
25
|
# Binance Crypto Comparison Lib
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = cryptobin
|
|
3
|
-
version = 1.0.
|
|
3
|
+
version = 1.0.3
|
|
4
4
|
author = Asinerum Conlang Project
|
|
5
5
|
author_email = asinerum.com@gmail.com
|
|
6
6
|
description = Binance Crypto Comparison Lib
|
|
@@ -19,13 +19,14 @@ package_dir =
|
|
|
19
19
|
packages = find:
|
|
20
20
|
python_requires = >=3.7
|
|
21
21
|
install_requires =
|
|
22
|
+
pillow >= 12.3.0
|
|
22
23
|
matplotlib >= 3.10.7
|
|
23
24
|
python-binance >= 1.0.36
|
|
24
25
|
python-dotenv >= 1.2.1
|
|
25
26
|
python-multipart >= 0.0.29
|
|
26
27
|
starlette >= 0.50.0
|
|
27
28
|
uvicorn >= 0.38.0
|
|
28
|
-
tagrepo
|
|
29
|
+
tagrepo >= 1.0.19
|
|
29
30
|
|
|
30
31
|
[options.packages.find]
|
|
31
32
|
where = src
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import io
|
|
3
|
+
import tempfile
|
|
3
4
|
import uvicorn ## for <uvia>
|
|
4
5
|
import matplotlib.pyplot as plt
|
|
5
6
|
import base64
|
|
7
|
+
|
|
6
8
|
from datetime import date, datetime
|
|
7
9
|
from dotenv import load_dotenv
|
|
8
10
|
from binance.client import Client
|
|
11
|
+
|
|
9
12
|
from starlette.applications import Starlette
|
|
10
13
|
from starlette.responses import HTMLResponse
|
|
11
14
|
from starlette.routing import Route
|
|
@@ -51,24 +54,31 @@ KLINE_VOLUME_INDEX = 7
|
|
|
51
54
|
|
|
52
55
|
client = Client(BINANCE_API_KEY, BINANCE_API_SECRET)
|
|
53
56
|
|
|
57
|
+
def binance_core_data(symbols: list, start: date, end: date, client: Client, proportions: list=[]):
|
|
58
|
+
if not proportions: proportions = [1 for _ in symbols]
|
|
59
|
+
data = {}
|
|
60
|
+
for i in range(len(symbols)):
|
|
61
|
+
symbol = symbols[i]
|
|
62
|
+
proportion = float(proportions[i])
|
|
63
|
+
klines = binance_get_klines(symbol, start=start, end=end, client=client)
|
|
64
|
+
if proportion == 0: proportion = float(klines[0][KLINE_RATE_INDEX]) #comet
|
|
65
|
+
dates = [datetime.fromtimestamp(k[KLINE_DATE_INDEX]/1000) for k in klines]
|
|
66
|
+
rates = [float(k[KLINE_RATE_INDEX])/proportion for k in klines]
|
|
67
|
+
volumes = [float(k[KLINE_VOLUME_INDEX]) for k in klines]
|
|
68
|
+
caps = [c*v for c,v in zip(rates, volumes)]
|
|
69
|
+
data[symbol] = {"dates": dates, "rates": rates, "volumes": volumes, "caps": caps}
|
|
70
|
+
return data
|
|
71
|
+
|
|
54
72
|
def binance_klines_plot(symbols: list, proportions: list, start: date, end: date, client: Client):
|
|
55
73
|
def plot(metric: str):
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
proportion = float(proportions[i])
|
|
59
|
-
klines = binance_get_klines(symbol, start=start, end=end, client=client)
|
|
60
|
-
if proportion == 0: proportion = float(klines[0][KLINE_RATE_INDEX]) #comet
|
|
61
|
-
dates = [datetime.fromtimestamp(k[KLINE_DATE_INDEX]/1000) for k in klines]
|
|
62
|
-
rates = [float(k[KLINE_RATE_INDEX])/proportion for k in klines]
|
|
63
|
-
volumes = [float(k[KLINE_VOLUME_INDEX]) for k in klines]
|
|
64
|
-
# Market cap approximation is [rate * volume]
|
|
65
|
-
caps = [c*v for c,v in zip(rates, volumes)]
|
|
74
|
+
data = binance_core_data(symbols=symbols, start=start, end=end, client=client, proportions=proportions)
|
|
75
|
+
for symbol, coindata in data.items():
|
|
66
76
|
if metric == METRIC_RATE:
|
|
67
|
-
plt.plot(dates, rates, label=symbol)
|
|
77
|
+
plt.plot(coindata["dates"], coindata["rates"], label=symbol)
|
|
68
78
|
elif metric == METRIC_VOL:
|
|
69
|
-
plt.plot(dates, volumes, label=symbol)
|
|
79
|
+
plt.plot(coindata["dates"], coindata["volumes"], label=symbol)
|
|
70
80
|
elif metric == METRIC_CAP:
|
|
71
|
-
plt.plot(dates, caps, label=symbol)
|
|
81
|
+
plt.plot(coindata["dates"], coindata["caps"], label=symbol)
|
|
72
82
|
return plot
|
|
73
83
|
|
|
74
84
|
def binance_get_klines(symbol: str, start: date, end: date, client: Client, interval=Client.KLINE_INTERVAL_1DAY):
|
|
@@ -76,19 +86,30 @@ def binance_get_klines(symbol: str, start: date, end: date, client: Client, inte
|
|
|
76
86
|
|
|
77
87
|
def html_metrics_plot(label: str, metrics: list, plot_func, response_func=HTMLResponse):
|
|
78
88
|
charts_html = ''
|
|
89
|
+
plot_files = []
|
|
79
90
|
for metric in metrics:
|
|
80
91
|
plt.figure(figsize=(8,5))
|
|
81
92
|
plot_func(metric)
|
|
82
93
|
plt.title(f'{metric} {label}'.title())
|
|
83
94
|
plt.legend()
|
|
84
95
|
plt.tight_layout()
|
|
96
|
+
if not response_func:
|
|
97
|
+
plot_file = plotter_save_temp(plt.savefig)
|
|
98
|
+
plot_files.append(plot_file)
|
|
99
|
+
plt.close()
|
|
100
|
+
continue
|
|
85
101
|
buf = io.BytesIO()
|
|
86
102
|
plt.savefig(buf, format='png')
|
|
87
103
|
buf.seek(0)
|
|
88
104
|
img_b64 = base64.b64encode(buf.read()).decode('utf-8')
|
|
89
105
|
charts_html += f'''<h3>{metric.capitalize()}</h3><img src="data:image/png;base64,{img_b64}"><br>'''
|
|
90
106
|
plt.close()
|
|
91
|
-
return response_func(f'<html><body>{charts_html}</body></html>')
|
|
107
|
+
return response_func(f'<html><body>{charts_html}</body></html>') if response_func else plot_files
|
|
108
|
+
|
|
109
|
+
def plotter_save_temp(savefig_instance) -> str:
|
|
110
|
+
tmp_file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
|
|
111
|
+
savefig_instance(tmp_file.name, format="png")
|
|
112
|
+
return tmp_file.name
|
|
92
113
|
|
|
93
114
|
def form_page():
|
|
94
115
|
return f'''
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cryptobin
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Binance Crypto Comparison Lib
|
|
5
5
|
Home-page: https://github.com/asinerum/cryptobin
|
|
6
6
|
Author: Asinerum Conlang Project
|
|
@@ -12,13 +12,14 @@ Classifier: Operating System :: OS Independent
|
|
|
12
12
|
Requires-Python: >=3.7
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
|
+
Requires-Dist: pillow>=12.3.0
|
|
15
16
|
Requires-Dist: matplotlib>=3.10.7
|
|
16
17
|
Requires-Dist: python-binance>=1.0.36
|
|
17
18
|
Requires-Dist: python-dotenv>=1.2.1
|
|
18
19
|
Requires-Dist: python-multipart>=0.0.29
|
|
19
20
|
Requires-Dist: starlette>=0.50.0
|
|
20
21
|
Requires-Dist: uvicorn>=0.38.0
|
|
21
|
-
Requires-Dist: tagrepo
|
|
22
|
+
Requires-Dist: tagrepo>=1.0.19
|
|
22
23
|
Dynamic: license-file
|
|
23
24
|
|
|
24
25
|
# Binance Crypto Comparison Lib
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|