2016-07-13 14 views
0

私はPythonで書かれた関数をRobinhood(株取引ブローカー)APIを呼び出して引用コード(snipshotの次のコードで "get_quote(self、symbol)"関数を取得します)。それはうまく動作します。正しい市場データが返されました。https要求 - C++へのPythonコード

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); 
} 
+0

実行可能な例を投稿できますか? –

+0

できます。しかしどちらの場合でも、APIに接続するにはRobinhoodのユーザー名とパスワードが必要です。 –

+0

@MK。読み取り不可能なシンボルは、内部に疑問符が付いた数字の0のように見えます。 –

答えて

0

私はrobinhood APIの非公式なドキュメントのためのオープンAPI仕様を作成しました。これにより、ほとんどの言語でhttpクライアントを生成できます。

仕様についてはhttps://github.com/sabareeshkkanan/robinhoodをご覧ください。この仕様を使用してクライアントを生成する方法については、このレポを参照してください。https://github.com/swagger-api/swagger-codegen

関連する問題