【问题标题】:BlinkTrade Rest API Returns Nothing (Account Balance Request)BlinkTrade Rest API 不返回任何内容(账户余额请求)
【发布时间】:2017-07-15 18:21:12
【问题描述】:

使用 python 3.6.1 尝试连接到 foxbit(blinktrade 平台)以检查账户余额,我在终端中运行代码,但它没有返回任何内容。没有追溯或任何东西。只是一片空白。有任何想法吗?提前致谢!

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))

【问题讨论】:

    标签: python python-3.x bitcoin python-3.6


    【解决方案1】:

    好吧,我改变了我的位置并使用了不同的 wifi。显然代码没有问题,只是我的 wifi 存在严重的延迟问题。

    【讨论】:

      【解决方案2】:

      用途:

      # Request Balance
      msg = {
      "MsgType": "U2",
      "BalanceReqID": 1
      }
      print(send_msg(msg))
      

      【讨论】:

      • 请添加一些细节来支持您的解决方案。
      • 虽然这段代码 sn-p 可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 2013-12-28
      • 1970-01-01
      • 2021-07-07
      • 2018-05-03
      相关资源
      最近更新 更多