我正在为https://poloniex.com/support/api/编写一个机器人
公共方法都可以正常工作,但交易 API 方法需要一些额外的技巧:
对交易 API 的所有调用都通过 HTTP POST 发送到https://poloniex.com/tradingApi,并且必须包含以下标头:
密钥 - 您的 API 密钥。
签名 - 查询的 POST 数据根据 HMAC-SHA512 方法由您的密钥的“秘密”签名。
此外,所有查询都必须包含“nonce”POST 参数。nonce 参数是一个整数,它必须始终大于之前使用的 nonce。
来自交易 API 的所有响应都是 JSON 格式。
我的 returnBalances 代码如下所示:
import hashlib
import hmac
from time import time
import requests
class Poloniex:
def __init__(self, APIKey, Secret):
self.APIKey = APIKey
self.Secret = Secret
def returnBalances(self):
url = 'https://poloniex.com/tradingApi'
payload = {
'command': 'returnBalances',
'nonce': int(time() * 1000),
}
headers = {
'Key': self.APIKey, …
Run Code Online (Sandbox Code Playgroud)