Skip to content

Commit 95049cc

Browse files
committed
完成量化框架的交易模块
1 parent 9be76c3 commit 95049cc

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

33/closeprice.png

-5.73 KB
Loading

Investment/do.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# coding:utf-8
2+
# 量化交易框架:执行层
3+
4+
5+
import requests
6+
import json
7+
import base64
8+
import hmac
9+
import hashlib
10+
import datetime
11+
import time
12+
13+
14+
if __name__ == "__main__":
15+
base_url = "https://api.sandbox.gemini.com"
16+
endpoint = "/v1/order/new"
17+
url = base_url + endpoint
18+
19+
gemini_api_key = "account-PsnWZPOnOf0FatEh3pWj"
20+
gemini_api_secret = "49wC5psfvDhMmtKaNzmmVg42yYYb"
21+
22+
t = datetime.datetime.now()
23+
payload_nonce = str(int(time.mktime(t.timetuple()) * 1000))
24+
25+
payload = {
26+
"request" : "/v1/order/new",
27+
"nonce" : payload_nonce,
28+
"symbol" : "btcusd",
29+
"amount" : "5",
30+
"price" : "7428.00",
31+
"side" : "buy",
32+
"type" : "exchange limit",
33+
"options" : ["maker-or-cancel"]
34+
}
35+
36+
encoded_payload = json.dumps(payload).encode()
37+
b64 = base64.b64encode(encoded_payload)
38+
signature = hmac.new(bytes(gemini_api_secret, "latin-1"), b64, hashlib.sha384).hexdigest()
39+
print(signature)
40+
41+
requests_header = {
42+
"Content-Type" : "text/plain",
43+
"Content-Length" : "0",
44+
"X-GEMINI-APIKEY" : gemini_api_key,
45+
"X-GEMINI-PAYLOAD" : b64,
46+
"X-GEMINI-SIGNATURE" : signature,
47+
"Cache-Control" : "no-cache"
48+
}
49+
50+
response = requests.post(url,
51+
data = None,
52+
headers = requests_header)
53+
new_order = response.json()
54+
print(new_order)
55+

0 commit comments

Comments
 (0)