首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >https请求--Python代码到C++

https请求--Python代码到C++
EN

Stack Overflow用户
提问于 2016-07-13 12:21:44
回答 1查看 571关注 0票数 0

它工作得很好。返回了正确的市场数据。

代码语言:javascript
运行
复制
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设置不正确,但我不知道如何修复它。有没有人有主意?谢谢!

代码语言:javascript
运行
复制
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);
}
EN

Stack Overflow用户

发布于 2017-12-25 12:09:12

我已经为robinhood api的非官方文档创建了一个开放的api规范。有了它,你就可以为大多数语言生成http客户端。

有关规格,请访问此处https://github.com/sabareeshkkanan/robinhood。有关如何使用此规范https://github.com/swagger-api/swagger-codegen生成客户端的信息,请访问此存储库

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38342637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档