以下是使用币安Python API中的"卖出订单"的代码示例:
import requests
import hashlib
import hmac
import time
api_key = 'YOUR_API_KEY'
api_secret = b'YOUR_API_SECRET'
# 创建卖出订单
def create_sell_order(symbol, quantity, price):
endpoint = "https://api.binance.com/api/v3/order"
timestamp = int(time.time() * 1000)
params = {
'symbol': symbol,
'side': 'SELL',
'type': 'LIMIT',
'timeInForce': 'GTC',
'quantity': quantity,
'price': price,
'timestamp': timestamp,
'recvWindow': 5000
}
query_string = '&'.join([f"{k}={v}" for k, v in params.items()])
signature = hmac.new(api_secret, query_string.encode('utf-8'), hashlib.sha256).hexdigest()
headers = {
'X-MBX-APIKEY': api_key
}
# 发起请求
response = requests.post(endpoint, params=params, headers=headers)
return response.json()
# 使用示例
symbol = 'BTCUSDT'
quantity = 0.001
price = 60000.0
response = create_sell_order(symbol, quantity, price)
print(response)
请确保将 YOUR_API_KEY
和 YOUR_API_SECRET
替换为您自己的API密钥和密钥,并提供正确的交易对(symbol)、数量(quantity)和价格(price)。