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
|
import requests
import json
# Replace YOUR_API_KEY and YOUR_SECRET_KEY with your own API keys from Gate.io
api_key = "YOUR_API_KEY"
secret_key = "YOUR_SECRET_KEY"
# The endpoint for the trade API
url = "https://api.gateio.io/api2/1/private/marginTrade"
# The parameters for the trade API
params = {
"currencyPair": "btc_usdt", # the currency pair you want to trade
"rate": 9000, # the rate at which you want to buy/sell
"amount": 0.01, # the amount of the currency you want to buy/sell
"tradeType": "buy", # the type of trade, buy or sell
"leverage": 10 # the leverage you want to use
}
# Add the API key to the parameters
params["nonce"] = 123456 # the nonce, a unique number for each API request
params["apikey"] = api_key
# Sign the API request with the secret key
signature = hmac.new(secret_key.encode(), json.dumps(params).encode(), hashlib.sha512).hexdigest()
# Add the signature to the API request
headers = {
"Sign": signature,
"Key": api_key
}
# Make the API request
response = requests.post(url, data=params, headers=headers)
# Check the API response
if response.status_code == 200:
# Parse the response JSON
result = response.json()
print(result)
else:
# Print the error message
print("Error:", response.text)
|
cs |
API 문서보고 짜야될거 말한마디면 바로쓸수있게끔 짜주니까 신기하긴하네
gateio 마진거래 파이썬으로 짜달라한거임