-
Notifications
You must be signed in to change notification settings - Fork 5
/
OkcoinSpotAPI.py
134 lines (105 loc) · 3.97 KB
/
OkcoinSpotAPI.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/python
# -*- coding: utf-8 -*-
#用于访问OKCOIN 现货REST API
from HttpMD5Util import buildMySign,httpGet,httpPost
class OKCoinSpot:
def __init__(self,url,apikey,secretkey):
self.__url = url
self.__apikey = apikey
self.__secretkey = secretkey
#获取OKCOIN现货行情信息
def ticker(self,symbol = ''):
TICKER_RESOURCE = "/api/v1/ticker.do"
params=''
if symbol:
params = 'symbol=%(symbol)s' %{'symbol':symbol}
return httpGet(self.__url,TICKER_RESOURCE,params)
#获取OKCOIN现货市场深度信息
def depth(self,symbol = ''):
DEPTH_RESOURCE = "/api/v1/depth.do"
params=''
if symbol:
params = 'symbol=%(symbol)s' %{'symbol':symbol}
return httpGet(self.__url,DEPTH_RESOURCE,params)
#获取OKCOIN现货历史交易信息
def trades(self,symbol = ''):
TRADES_RESOURCE = "/api/v1/trades.do"
params=''
if symbol:
params = 'symbol=%(symbol)s' %{'symbol':symbol}
return httpGet(self.__url,TRADES_RESOURCE,params)
#获取用户现货账户信息
def userinfo(self):
USERINFO_RESOURCE = "/api/v1/userinfo.do"
params ={}
params['api_key'] = self.__apikey
params['sign'] = buildMySign(params,self.__secretkey)
return httpPost(self.__url,USERINFO_RESOURCE,params)
#现货交易
def trade(self,symbol,tradeType,price='',amount=''):
TRADE_RESOURCE = "/api/v1/trade.do"
params = {
'api_key':self.__apikey,
'symbol':symbol,
'type':tradeType
}
if price:
params['price'] = price
if amount:
params['amount'] = amount
params['sign'] = buildMySign(params,self.__secretkey)
return httpPost(self.__url,TRADE_RESOURCE,params)
#现货批量下单
def batchTrade(self,symbol,tradeType,orders_data):
BATCH_TRADE_RESOURCE = "/api/v1/batch_trade.do"
params = {
'api_key':self.__apikey,
'symbol':symbol,
'type':tradeType,
'orders_data':orders_data
}
params['sign'] = buildMySign(params,self.__secretkey)
return httpPost(self.__url,BATCH_TRADE_RESOURCE,params)
#现货取消订单
def cancelOrder(self,symbol,orderId):
CANCEL_ORDER_RESOURCE = "/api/v1/cancel_order.do"
params = {
'api_key':self.__apikey,
'symbol':symbol,
'order_id':orderId
}
params['sign'] = buildMySign(params,self.__secretkey)
return httpPost(self.__url,CANCEL_ORDER_RESOURCE,params)
#现货订单信息查询
def orderinfo(self,symbol,orderId):
ORDER_INFO_RESOURCE = "/api/v1/order_info.do"
params = {
'api_key':self.__apikey,
'symbol':symbol,
'order_id':orderId
}
params['sign'] = buildMySign(params,self.__secretkey)
return httpPost(self.__url,ORDER_INFO_RESOURCE,params)
#现货批量订单信息查询
def ordersinfo(self,symbol,orderId,tradeType):
ORDERS_INFO_RESOURCE = "/api/v1/orders_info.do"
params = {
'api_key':self.__apikey,
'symbol':symbol,
'order_id':orderId,
'type':tradeType
}
params['sign'] = buildMySign(params,self.__secretkey)
return httpPost(self.__url,ORDERS_INFO_RESOURCE,params)
#现货获得历史订单信息
def orderHistory(self,symbol,status,currentPage,pageLength):
ORDER_HISTORY_RESOURCE = "/api/v1/order_history.do"
params = {
'api_key':self.__apikey,
'symbol':symbol,
'status':status,
'current_page':currentPage,
'page_length':pageLength
}
params['sign'] = buildMySign(params,self.__secretkey)
return httpPost(self.__url,ORDER_HISTORY_RESOURCE,params)