-1

Using python 3.6.1 attempting to connect to foxbit (blinktrade platform) to check account balance I run the code in my terminal and it returns nothing. No traceback or anything. Just blankness. Any ideas? Thanks in advance!

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))
New2VBA
  • 347
  • 2
  • 6
  • 17

2 Answers2

0

Well, I changed my location and used different wifi. Apparently no problem with the code just a serious latency issue with my wifi.

New2VBA
  • 347
  • 2
  • 6
  • 17
-2

Use:

# Request Balance
msg = {
"MsgType": "U2",
"BalanceReqID": 1
}
print(send_msg(msg))
Floern
  • 33,559
  • 24
  • 104
  • 119
Sandro
  • 1
  • Please add some detail to support your solution. – Suhaib Janjua Jan 28 '18 at 18:20
  • 1
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – offbyone Jan 28 '18 at 18:22