forked from justmike1/CryptoTradingTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deribit_data_template.py
47 lines (35 loc) · 1.75 KB
/
deribit_data_template.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
import requests as rq
import sys
import json
with open(sys.argv[1], 'r') as f:
data = json.load(f)
class DeribitCALC:
def __init__(self):
self.deribit_url = "https://www.deribit.com/api/v2"
self.pub_auth_endpoint = "/public/auth"
self.private_endpoint = "/private/get_account_summary" # Change endpoint to your liking docs.deribit.com/?shell
self.currency = data['asset']
self.client_id = data['client_id']
self.client_secret = data['client_secret']
self.grant_type = "client_credentials"
self.pub_params = {
'client_id': self.client_id, 'client_secret': self.client_secret, 'grant_type': self.grant_type
}
self.public_auth = rq.get(url=self.deribit_url + self.pub_auth_endpoint, params=self.pub_params)
self.data_auth = self.public_auth.json()
self.pub_params['scope'] = str(self.data_auth['result']['scope']).split()[5] # Scope has 8 values
self.access_token = self.data_auth['result']['access_token']
self.pri_params = {"currency": "BTC", "extended": "true"}
self.private_data = rq.get(
url=self.deribit_url + self.private_endpoint,
headers={"Authorization": "Bearer " + self.access_token, "Content-Type": "application/json"},
params=self.pri_params)
self.data_private = self.private_data.json()
def desired_data(self):
print(json.dumps(self.data_private, sort_keys=True, indent=5))
def testing(self): # USE FOR TESTING SCOPE (ADD DeribitCALC().testing() to main)
print(f"{self.pub_params}\n{self.access_token}")
print(self.data_private["result"]["equity"])
if __name__ == '__main__':
DeribitCALC().desired_data()
# DeribitCALC().testing()