-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfetch_from_binance.py
55 lines (43 loc) · 1.25 KB
/
fetch_from_binance.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
import sys
from dataclasses import dataclass
from candlestick_chart import Candle, Chart
@dataclass(frozen=True, slots=True)
class BinanceKlinesItem:
open_time: int
open: str
high: str
low: str
close: str
volume: str
close_time: int
quote_asset_volume: str
number_of_trades: int
taker_buy_base_asset_volume: str
taker_buy_quote_asset_volume: str
ignore: str
def main() -> int:
import requests
url = "https://api.binance.com/api/v1/klines?symbol=CHZUSDT&interval=1h"
with requests.get(url, timeout=60) as req:
klines = [BinanceKlinesItem(*item) for item in req.json()]
candles = [
Candle(
open=float(kline.open),
close=float(kline.close),
high=float(kline.high),
low=float(kline.low),
volume=float(kline.volume),
timestamp=float(kline.open_time),
)
for kline in klines
]
chart = Chart(candles, title="CHZ/USDT")
chart.set_bull_color(1, 205, 254)
chart.set_bear_color(255, 107, 153)
chart.set_volume_pane_height(4)
chart.set_volume_pane_enabled(True)
chart.set_highlight("0.2377", "93;45m")
chart.draw()
return 0
if __name__ == "__main__":
sys.exit(main())