Back

Python Rest API

Hi!

Thank you for providing a wonder environment to investigate the wonderful world of market data.

I run on Linux and would like to use the REST external API so I can edit in emacs, and such.  My first test has been unsuccessful and I'm betting someone else spot the problem.   I looked at jorgemanbia ruby implemention and tried to do the same thing..  It didn't work.. lol

import reqests, hashlib, time

authTok = "string from my accounts page"

user = 12345 # number from by accounts page

hasher = hashlib.sha256()
hasher.update(authTok)

ts = int(time.time())

authStr = hasher.hexdigest()

payload = {"Timestamp" : ts}

resp = requests.get("https://www.quantconnect.com/api/v2/projects/read", auth = (user, authTok), params = payload)

print resp.status_code
print resp.text

#################

when run, the printing the resp.text gives the following string

{"errors":["Hash doesn't match. UID: 123455 Hash: the string from hexdigest Timestamp: ''"],"success":false}

 

Any clues, pointers, help?

Thanks, Bill Bitner

Update Backtest








Bill Bitner, we have a C# API that can be used with pythonnet to create a Python REST API.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thanks Alexandre Catarino for your time and reply.    By looking at the C# API, I was able to spot the errors in my code.   Here is the code snippet to read  projects list via the rest API

#!/usr/bin/env python

import hashlib
import time
import requests
from requests_toolbelt.utils import dump

authTok = "The hex digit string from the accounts page"
user = 12345 # my userId from the accounts page

hasher = hashlib.sha256()
ts = int(time.time())
authStr = "%s:%d"%(authTok, ts) # this is in the API
hasher.update(authStr)
authHexDigest = hasher.hexdigest()
print authHexDigest
head = {"Content-type": "application/json", "Timestamp" : "%d"%(ts)} # Timestamp must be in the header too!
resp = requests.get("https://www.quantconnect.com/api/v2/projects/read", auth = (user, authHexDigest), headers = head, params = {})

data = dump.dump_all(resp)
print(data.decode('utf-8'))

Thanks again!!

Bill Bitner

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed