-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnobitexexchange.py
76 lines (66 loc) · 2.54 KB
/
nobitexexchange.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
import requests
from exchange import Exchange
from models import Order
class NobitexExchange(Exchange):
def __init__(self) -> None:
super().__init__(name='nobitex', base_url='https://api.nobitex.ir')
self.src_currencies = [
'btc', 'ltc', 'bnb', 'eth', 'etc', 'doge',
'xlm', 'bch', 'xrp', 'trx', 'eos'
]
self.dst_currencies = ['usdt', 'rls']
if not self.token:
self.token = self.login(username="[email protected]", password="ZEmX7WHZxdVmmfY")
self.headers = {"Authorization": f"Token {self.token}", "content-type": "application/json"}
def call_api(self, path: str, data: dict=None, headers: dict=None):
url = f'{self.base_url}{path}'
response = requests.post(url, data=data, headers=headers)
result = response.json()
return result
def login(self, username: str, password: str):
data = {
"username": username,
"password": password,
"captcha": "api",
"remember": "yes"
}
response = self.call_api('/auth/login/', data)
token = ''
if response['status'] == 'success':
token = response['key']
return token
def add_order(self, order: Order):
data = {
"type": order.type,
"execution": "limit",
"srcCurrency": order.src_currency,
"dstCurrency": order.dst_currency,
"amount": str(order.amount),
"price": order.price
}
response = self.call_api('/market/orders/add', json.dumps(data), self.headers)
return response
def get_wallets(self):
response = self.call_api('/users/wallets/list', headers=self.headers)
wallets = response['wallets']
user_wallets = [wallet for wallet in wallets if wallet['rialBalance'] > 0]
return user_wallets
def get_current_prices(self, dst_currency: str='rls'):
srcCurrency = ','.join(self.src_currencies)
data = {
"srcCurrency": srcCurrency,
"dstCurrency": dst_currency
}
response = self.call_api('/market/stats', data)
return response['stats']
def get_orderbook(self, symbol):
url = f'{self.base_url}/v2/orderbook/{symbol}'
response = requests.get(url)
result = response.json()
return result
def get_trades(self, symbol):
url = f'{self.base_url}/v2/trades/{symbol}'
response = requests.get(url)
result = response.json()
return result