-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test_2.py
More file actions
57 lines (50 loc) · 1.82 KB
/
client_test_2.py
File metadata and controls
57 lines (50 loc) · 1.82 KB
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
import time
import hmac
import hashlib
import base64
import requests
import json
import os
env_var_name = "WEEX_API_CREDENTIALS"
file_path = os.getenv(env_var_name)
with open(file_path, 'r') as f:
creds = json.load(f)
api_key = creds["access-key"]
secret_key = creds["access-signature"]
access_passphrase = creds["passphrase"]
def generate_signature(secret_key, timestamp, method, request_path, query_string, body):
message = timestamp + method.upper() + request_path + query_string + str(body)
signature = hmac.new(secret_key.encode(), message.encode(), hashlib.sha256).digest()
return base64.b64encode(signature).decode()
def send_request_post(api_key, secret_key, access_passphrase, method, request_path, query_string, body):
timestamp = str(int(time.time() * 1000))
body = json.dumps(body)
signature = generate_signature(secret_key, timestamp, method, request_path, query_string, body)
headers = {
"ACCESS-KEY": api_key,
"ACCESS-SIGN": signature,
"ACCESS-TIMESTAMP": timestamp,
"ACCESS-PASSPHRASE": access_passphrase,
"Content-Type": "application/json",
"locale": "en-US"
}
url = "https://api-contract.weex.com/" # Please replace with the actual API address
if method == "POST":
response = requests.post(url + request_path, headers=headers, data=body)
return response
def placeOrder():
request_path = "/capi/v2/order/placeOrder"
body = {
"symbol": "cmt_btcusdt",
"client_oid": "test",
"size": "10",
"type": "1",
"order_type": "0",
"match_price": "0",
"price": "93378.7"}
query_string = ""
response = send_request_post(api_key, secret_key, access_passphrase, "POST", request_path, query_string, body)
print(response.status_code)
print(response.text)
if __name__ == '__main__':
placeOrder()