- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章python做量化投资系列之比特币初始配置由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了python比特币初始配置的具体代码,供大家参考,具体内容如下 。
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 13 10:36:19 2017
@author: yunjinqi
E-mail:yunjinqi@qq.com
Differentiate yourself in the world from anyone else.
"""
#用于访问OKCOIN 现货REST API
#####################################################
import
http.client
import
urllib
import
json
import
hashlib
import
time
def
buildMySign(params,secretKey):
sign
=
''
for
key
in
sorted
(params.keys()):
sign
+
=
key
+
'='
+
str
(params[key])
+
'&'
data
=
sign
+
'secret_key='
+
secretKey
return
hashlib.md5(data.encode(
"utf8"
)).hexdigest().upper()
def
httpGet(url,resource,params
=
''):
conn
=
http.client.HTTPSConnection(url, timeout
=
10
)
conn.request(
"GET"
,resource
+
'?'
+
params)
#print(resource + '?' + params)
response
=
conn.getresponse()
data
=
response.read().decode(
'utf8'
)
return
json.loads(data)
def
httpPost(url,resource,params):
headers
=
{
"Content-type"
:
"application/x-www-form-urlencoded"
}
conn
=
http.client.HTTPSConnection(url, timeout
=
10
)
temp_params
=
urllib.parse.urlencode(params)
#print("https://"+url+resource+"?"+str(temp_params))
conn.request(
"POST"
, resource,temp_params,headers)
response
=
conn.getresponse()
data
=
response.read().decode(
'utf-8'
)
params.clear()
conn.close()
return
data
#####################################################
import
urllib
class
OKCoinSpot:
def
__init__(
self
,url,apikey,secretkey):
self
.__url
=
url
self
.__apikey
=
apikey
self
.__secretkey
=
secretkey
print
(
self
.__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)
def
getKline(
self
,duration,size,since):
kline_resourse
=
"https://www.okcoin.cn/api/v1/kline.do"
params
=
{
#'api_key': self.__apikey,
'symbol'
:
"btc_cny"
,
'type'
: duration,
'size'
: size,
'since'
: since
}
temp_params
=
urllib.parse.urlencode(params)
#print(temp_params)
return
httpGet(
self
.__url, kline_resourse, temp_params)
########################################################
#!/usr/bin/python
# -*- coding: utf-8 -*-
#用于访问OKCOIN 期货REST API
import
urllib
class
OKCoinFuture:
def
__init__(
self
,url,apikey,secretkey):
self
.__url
=
url
self
.__apikey
=
apikey
self
.__secretkey
=
secretkey
#OKCOIN期货行情信息
def
future_ticker(
self
,symbol,contractType):
FUTURE_TICKER_RESOURCE
=
"/api/v1/future_ticker.do"
params
=
''
if
symbol:
params
+
=
'&symbol='
+
symbol
if
params
else
'symbol='
+
symbol
if
contractType:
params
+
=
'&contract_type='
+
contractType
if
params
else
'contract_type='
+
symbol
return
httpGet(
self
.__url,FUTURE_TICKER_RESOURCE,params)
#OKCoin期货市场深度信息
def
future_depth(
self
,symbol,contractType,size):
FUTURE_DEPTH_RESOURCE
=
"/api/v1/future_depth.do"
params
=
''
if
symbol:
params
+
=
'&symbol='
+
symbol
if
params
else
'symbol='
+
symbol
if
contractType:
params
+
=
'&contract_type='
+
contractType
if
params
else
'contract_type='
+
symbol
if
size:
params
+
=
'&size='
+
size
if
params
else
'size='
+
size
return
httpGet(
self
.__url,FUTURE_DEPTH_RESOURCE,params)
#OKCoin期货交易记录信息
def
future_trades(
self
,symbol,contractType):
FUTURE_TRADES_RESOURCE
=
"/api/v1/future_trades.do"
params
=
''
if
symbol:
params
+
=
'&symbol='
+
symbol
if
params
else
'symbol='
+
symbol
if
contractType:
params
+
=
'&contract_type='
+
contractType
if
params
else
'contract_type='
+
symbol
return
httpGet(
self
.__url,FUTURE_TRADES_RESOURCE,params)
#OKCoin期货指数
def
future_index(
self
,symbol):
FUTURE_INDEX
=
"/api/v1/future_index.do"
params
=
''
if
symbol:
params
=
'symbol='
+
symbol
return
httpGet(
self
.__url,FUTURE_INDEX,params)
#获取美元人民币汇率
def
exchange_rate(
self
):
EXCHANGE_RATE
=
"/api/v1/exchange_rate.do"
return
httpGet(
self
.__url,EXCHANGE_RATE,'')
#获取预估交割价
def
future_estimated_price(
self
,symbol):
FUTURE_ESTIMATED_PRICE
=
"/api/v1/future_estimated_price.do"
params
=
''
if
symbol:
params
=
'symbol='
+
symbol
return
httpGet(
self
.__url,FUTURE_ESTIMATED_PRICE,params)
#期货全仓账户信息
def
future_userinfo(
self
):
FUTURE_USERINFO
=
"/api/v1/future_userinfo.do?"
params
=
{}
params[
'api_key'
]
=
self
.__apikey
params[
'sign'
]
=
buildMySign(params,
self
.__secretkey)
return
httpPost(
self
.__url,FUTURE_USERINFO,params)
#期货全仓持仓信息
def
future_position(
self
,symbol,contractType):
FUTURE_POSITION
=
"/api/v1/future_position.do?"
params
=
{
'api_key'
:
self
.__apikey,
'symbol'
:symbol,
'contract_type'
:contractType
}
params[
'sign'
]
=
buildMySign(params,
self
.__secretkey)
return
httpPost(
self
.__url,FUTURE_POSITION,params)
#期货下单
def
future_trade(
self
,symbol,contractType,price
=
'
',amount='
',tradeType='
',matchPrice='
',leverRate='
'):
FUTURE_TRADE
=
"/api/v1/future_trade.do?"
params
=
{
'api_key'
:
self
.__apikey,
'symbol'
:symbol,
'contract_type'
:contractType,
'amount'
:amount,
'type'
:tradeType,
'match_price'
:matchPrice,
'lever_rate'
:leverRate
}
if
price:
params[
'price'
]
=
price
params[
'sign'
]
=
buildMySign(params,
self
.__secretkey)
return
httpPost(
self
.__url,FUTURE_TRADE,params)
#期货批量下单
def
future_batchTrade(
self
,symbol,contractType,orders_data,leverRate):
FUTURE_BATCH_TRADE
=
"/api/v1/future_batch_trade.do?"
params
=
{
'api_key'
:
self
.__apikey,
'symbol'
:symbol,
'contract_type'
:contractType,
'orders_data'
:orders_data,
'lever_rate'
:leverRate
}
params[
'sign'
]
=
buildMySign(params,
self
.__secretkey)
return
httpPost(
self
.__url,FUTURE_BATCH_TRADE,params)
#期货取消订单
def
future_cancel(
self
,symbol,contractType,orderId):
FUTURE_CANCEL
=
"/api/v1/future_cancel.do?"
params
=
{
'api_key'
:
self
.__apikey,
'symbol'
:symbol,
'contract_type'
:contractType,
'order_id'
:orderId
}
params[
'sign'
]
=
buildMySign(params,
self
.__secretkey)
return
httpPost(
self
.__url,FUTURE_CANCEL,params)
#期货获取订单信息
def
future_orderinfo(
self
,symbol,contractType,orderId,status,currentPage,pageLength):
FUTURE_ORDERINFO
=
"/api/v1/future_order_info.do?"
params
=
{
'api_key'
:
self
.__apikey,
'symbol'
:symbol,
'contract_type'
:contractType,
'order_id'
:orderId,
'status'
:status,
'current_page'
:currentPage,
'page_length'
:pageLength
}
params[
'sign'
]
=
buildMySign(params,
self
.__secretkey)
return
httpPost(
self
.__url,FUTURE_ORDERINFO,params)
#期货逐仓账户信息
def
future_userinfo_4fix(
self
):
FUTURE_INFO_4FIX
=
"/api/v1/future_userinfo_4fix.do?"
params
=
{
'api_key'
:
self
.__apikey}
params[
'sign'
]
=
buildMySign(params,
self
.__secretkey)
return
httpPost(
self
.__url,FUTURE_INFO_4FIX,params)
#期货逐仓持仓信息
def
future_position_4fix(
self
,symbol,contractType,type1):
FUTURE_POSITION_4FIX
=
"/api/v1/future_position_4fix.do?"
params
=
{
'api_key'
:
self
.__apikey,
'symbol'
:symbol,
'contract_type'
:contractType,
'type'
:type1
}
params[
'sign'
]
=
buildMySign(params,
self
.__secretkey)
return
httpPost(
self
.__url,FUTURE_POSITION_4FIX,params)
def
getKline(
self
,duration,size,since):
kline_resourse
=
"https://www.okcoin.com/api/v1/future_kline.do?"
params
=
{
#'api_key': self.__apikey,
'symbol'
:
"btc_usd"
,
'type'
: duration,
'contract_type'
:
"quarter"
,
'size'
: size,
'since'
: since
}
temp_params
=
urllib.parse.urlencode(params)
return
httpGet(
self
.__url, kline_resourse, temp_params)
#return httpPost(self.__url,kline_resourse,params)
#temp_params = urllib.parse.urlencode(params)
#print(temp_params)
# return httpGet(self.__url, kline_resourse, temp_params)
########################
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:http://blog.csdn.net/qq_26948675/article/details/54783472 。
最后此篇关于python做量化投资系列之比特币初始配置的文章就讲到这里了,如果你想了解更多关于python做量化投资系列之比特币初始配置的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 9 年前。 Improve
根据其他问题的列表,要构建我需要的原始交易: listunspent - 您可以获得所有未花费交易的列表 您可以决定要花哪些钱 您使用createrawtransaction来创建您的输入/输出,tx
我想查看不在我钱包中的btc地址余额。似乎像 blockchainexplorer 这样的网站会做这类事情。他们还提供 API,但我遇到了他们的 API 使用限制。所以我下载了完整的区 block 链
我的设置:在 Mongoose 模块的帮助下,我们处理所有 Mongo 数据库操作。对于每个新用户,都会生成一个钱包并将其存储在 Mongo 集合中。 方法:如果我们使用User.find({}, f
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我正在尝试建立一个以比特币为中心的网站,并且由于主机的限制,我需要能够执行以下操作,而无需在任何服务器上运行比特币守护程序: 创建一个新的比特币地址(getnewaddress($account))
我目前正在开发一个比特币应用程序,它涉及运行一个完整的比特币节点。 当我测试我的源代码时,我决定使用比特币注册测试模式。 这是我如何启动我的比特币节点: ./bitcoind -regtest -rp
私钥是随机生成的,不与任何钱包关联。 我想为比特币准备公钥生成的自定义(简单)实现。然而,经过几次尝试,我的结果是不正确的。我将它们与在线生成器进行了比较。我发现我使用了除法而不是 modinv。不幸
我是比特币和区 block 链的新手,希望您能帮助我解决一些问题。所以我启动了一个“regtest”网络并使用 生成了 101 个 block bitcoin-cli -regtest generat
当我在我的 bitcoind 服务器上调用 getwork 时,我得到以下信息: ./bitcoind getwork { "midstate" : "695d56ae173bbd0fd5f5
我正在编写一个 JavaScript 函数来返回当前的 BTC/USD 汇率。我做了一些研究,但我只想要一些简单的东西。它不会在服务器端用于计算值(明显的安全隐患),而只是为了方便我的用户。我有 2
我正在使用 Bitrise 生成构建并将其上传到 AppStore。当我在设备上运行应用程序或生成构建并通过 Xcode 上传到 AppStore 时没有出现任何错误,但是当我尝试通过 Bitrise
我目前正在我的 Windows 7 上创建“比特币”。 我已经完成了所有必要的步骤,现在我要进行最后一部分,以获取 .exe 文件。 这是我在 QT 4.8.5 命令提示符中输入的命令 qmake U
以下链接提供有关 BTC 地址的 JSON 数据 -> https://blockchain.info/address/1GA9RVZHuEE8zm4ooMTiqLicfnvymhzRVm?forma
我是一名优秀的程序员,十分优秀!