-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhit_btc_api.py
71 lines (54 loc) · 2.75 KB
/
hit_btc_api.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
import time
import requests
from decimal import *
class Client_hit(object):
def __init__(self, url, public_key, secret):
self.url = url + "/api/2"
self.session = requests.session()
self.session.auth = (public_key, secret)
def get_symbol(self, symbol_code):
"""Get symbol."""
return self.session.get("%s/public/symbol/%s" % (self.url, symbol_code)).json()
def get_orderbook(self, symbol_code):
"""Get orderbook. """
return self.session.get("%s/public/orderbook/%s" % (self.url, symbol_code)).json()
def get_address(self, currency_code):
"""Get address for deposit."""
return self.session.get("%s/account/crypto/address/%s" % (self.url, currency_code)).json()
def get_account_balance(self):
"""Get main balance."""
return self.session.get("%s/account/balance" % self.url).json()
def get_trading_balance(self):
"""Get trading balance."""
return self.session.get("%s/trading/balance" % self.url).json()
def transfer(self, currency_code, amount, to_exchange):
return self.session.post("%s/account/transfer" % self.url, data={
'currency': currency_code, 'amount': amount,
'type': 'bankToExchange' if to_exchange else 'exchangeToBank'
}).json()
def new_order(self, client_order_id, symbol_code, side, quantity, type, price=None):
"""Place an order."""
data = {'symbol': symbol_code, 'side': side, 'quantity': quantity, 'type': type}
if price is not None:
data['price'] = price
return self.session.put("%s/order/%s" % (self.url, client_order_id), data=data).json()
def get_active_order(self, symbol):
"""Get order info."""
data = {'symbol': symbol}
return self.session.get("%s/order/" % (self.url), params=data).json()
def get_order(self, client_order_id, wait=None):
"""Get order info."""
data = {'wait': wait} if wait is not None else {}
return self.session.get("%s/order/%s" % (self.url, client_order_id), params=data).json()
def cancel_order(self, client_order_id):
"""Cancel order."""
return self.session.delete("%s/order/%s" % (self.url, client_order_id)).json()
def withdraw(self, currency_code, amount, address, network_fee=None):
"""Withdraw."""
data = {'currency': currency_code, 'amount': amount, 'address': address}
if network_fee is not None:
data['networkfee'] = network_fee
return self.session.post("%s/account/crypto/withdraw" % self.url, data=data).json()
def get_transaction(self, transaction_id):
"""Get transaction info."""
return self.session.get("%s/account/transactions/%s" % (self.url, transaction_id)).json()