0
使用python 3.6.1試圖連接到foxbit(blinktrade平臺)來檢查帳戶餘額我在終端運行代碼,它什麼都不返回。沒有追蹤或任何東西。只是空白。有任何想法嗎?提前致謝!BlinkTrade Rest API返回Nothing(賬戶餘額請求)
import hashlib
import hmac
import time
import requests
import datetime
def send_msg(msg, env='prod'):
if env == 'prod':
BLINKTRADE_API_URL = 'https://api.blinktrade.com'
else:
BLINKTRADE_API_URL = 'https://api.testnet.blinktrade.com'
BLINKTRADE_API_VERSION = 'v1'
TIMEOUT_IN_SECONDS = 10
key = 'keykeykeykeykey32952592753'
secret = 'secretsecretsecret23535345'
secret2 = bytearray(secret, 'utf8') #turn secret into bytearray
dt = datetime.datetime.now()
nonce = str(int((time.mktime(dt.timetuple()) + dt.microsecond/1000000.0) * 1000000))
nonce = nonce.encode("utf8")
signature = hmac.new(secret2, nonce, digestmod=hashlib.sha256).hexdigest()
headers = {
'user-agent': 'blinktrade_tools/0.1',
'Content-Type': 'application/json', # You must POST a JSON message
'APIKey': key, # Your APIKey
'Nonce': nonce, # The nonce must be an integer, always greater than the previous one.
'Signature': signature # Use the API Secret to sign the nonce using HMAC_SHA256 algo
}
url = '%s/tapi/%s/message' % (BLINKTRADE_API_URL, BLINKTRADE_API_VERSION)
return requests.post(url, json=msg, verify=True, headers=headers).json()
# Request Balance
msg = {
"MsgType": "U2", # Balance Request
"BalanceReqID": 1 # An ID assigned by you. It can be any number. The response message associated with this request will contain the same ID.}
print(send_msg(msg))
請添加一些細節來支持你的解決方案。 –
儘管此代碼片段可能會解決問題,但[包括解釋](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。 – offbyone