它工作得很好。返回了正确的市场数据。
import requests
import urllib
class Robinhood(object):
# All known endpoints as of September 5th, 2015
endpoints = {
    "quotes": "https://api.robinhood.com/quotes/",
    "user": "https://api.robinhood.com/user/",
    "user/additional_info": "https://api.robinhood.com/user/additional_info/",
    "user/basic_info": "https://api.robinhood.com/user/basic_info/",
    "user/employment": "https://api.robinhood.com/user/employment/",
    "user/investment_profile": "https://api.robinhood.com/user/investment_profile/",
    "watchlists": "https://api.robinhood.com/watchlists/"
    }
def get_quote(self, symbol):
    ''' Returns a qoute object for a given symbol including all data returned by Robinhood's API'''
    data = { 'symbols' : symbol }
    res = self.session.get(self.endpoints['quotes'], params=data)
    if res.status_code == 200:
        return res.json()['results']
    else:
        raise Exception("Could not retrieve quote: " + res.text)我尝试使用Curl库在C++中实现此逻辑。但它不起作用。没有编译或运行时错误,但程序返回了一个不可读的字符,而不是股票的市场价格。在我看来,我的URL设置不正确,但我不知道如何修复它。有没有人有主意?谢谢!
std::string RobinhoodAPI::GetQuote(std::string ticker)
{
 struct response resStr;
init_string(&resStr);
std::string url = "https://api.robinhood.com/quotes/symbols=AVP/";
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resStr);
 resCode = curl_easy_perform(curl);
 std::cout << std::string(resStr.ptr);
 return std::string(resStr.ptr);
}发布于 2017-12-25 12:09:12
我已经为robinhood api的非官方文档创建了一个开放的api规范。有了它,你就可以为大多数语言生成http客户端。
有关规格,请访问此处https://github.com/sabareeshkkanan/robinhood。有关如何使用此规范https://github.com/swagger-api/swagger-codegen生成客户端的信息,请访问此存储库
https://stackoverflow.com/questions/38342637
复制相似问题