-
Notifications
You must be signed in to change notification settings - Fork 0
/
binance_cli.py
38 lines (31 loc) · 961 Bytes
/
binance_cli.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
#!/usr/bin/env python
# encoding: utf-8
import requests
import time
from enum import Enum
class KLineSymbol(Enum):
BtcUsdt = "BTCUSDT"
EthUsdt = "ETHUSDT"
class KLineInterval(Enum):
OneMinute = "1m"
ThreeMinute = "3m"
FiveMinute = "5m"
FifteenMinute = "15m"
ThirtyMinute = "30m"
OneHour = "1h"
TwoHour = "2h"
FourHour = "4h"
SixHour = "6h"
EightHour = "8h"
TwelveHour = "12h"
OneDay = "1d"
def fetch_klines(symbol: KLineSymbol, interval: KLineInterval,
endtime_ms: int = int(time.time()) * 1000,
limit: int = 1000, proxies: dict = None) -> str:
assert limit <= 1000
url = 'https://www.binance.com/api/v3/uiKlines?endTime={}&limit={}&symbol={}&interval={}' \
.format(endtime_ms, limit, symbol.value, interval.value)
session = requests.Session()
session.trust_env = False
resp = session.get(url=url, proxies=proxies)
return resp.text