-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBybitlite.py
More file actions
43 lines (33 loc) · 1.08 KB
/
Copy pathBybitlite.py
File metadata and controls
43 lines (33 loc) · 1.08 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
import logging
import requests
from requests import ConnectionError
import os
ENDPOINT = 'https://api.bybit.com'
#if the API id data is stored as enviroment variable (recommended method)
APIid = {'key': os.environ.get('BYBIT_KEY'),
'secret': os.environ.get('BYBIT_SECRET')}
# if you want to hard code the API data directly (not recommended)
# APIid = {'key': "YOUR_API_KEY_HERE",
# 'secret': "YOUR_API_SECRET_HERE"}
# this module makes public calls to the Bybit REST API
def request(method, path, params=None):
try:
resp = requests.request(method, ENDPOINT + path, params=params)
data = resp.json()
if data["ret_msg"] != 'OK':
logging.error(data['ret_msg'])
return None
else:
return data['result']
except ConnectionError as e:
logging.error(e)
def tickers(symbol=''):
"""
symbol: the currency symbol if left empty returns ticker of all symbols
"""
path = '/v2/public/tickers'
params = {
'symbol': symbol,
}
data = request('GET', path, params)
return data