dongzong1866 2017-11-13 03:42
浏览 75

Tradeking / Ally Invest API PHP的市场报价请求

I am trying to use the Ally Invest/ Tradeking PHP API to request a market quote: https://www.ally.com/api/invest/documentation/market-ext-quotes-get-post/

Using the documentation, I installed PHP OAuth and I created the below code, but it doesnt seem to yield an output when i make the call:

$consumer_key     = 'Z3fPyf181adB63Gq4gQZAjL1b7xgx7jLGA92DQ9jnuk4';
$consumer_secret  = 'feDtEmHTWoRb4rDMZkF6gvXj0xd2lP5vGDXPCUiZJww7';
$access_token     = '251cgNlYK21b6tqbqYSImAiqJKk3c51lHu4UOOF71ZI4';
$access_secret    = 'aLth5Imx0VgB67IgFhDxmW3QVYKPxdtzNMmjbiNWYXI7';

$oauth = new OAuth($consumer_key,$consumer_secret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->setToken($access_token,$access_secret);
$noonce=date('U') ;
$oauth->setNonce($noonce);
$signature= $oauth->generateSignature("GET", "https://api.tradeking.com/v1/market/ext/quotes.xml?symbols=fb");
$url = 'https://api.tradeking.com/v1/market/ext/quotes.xml?symbols=fb';
$header = [
    "GET /v1/market/ext/quotes.xml?symbols=fb HTTP/1.1 
" .
    "Authorization: OAuth 
" .
    'oauth_consumer_key="'.$consumer_key.'"' . " 
" .
    'oauth_nonce="'.$noonce.'"' .  " 
" .
    'oauth_signature="'.$signature.'"' . " 
" .
    'oauth_signature_method="HMAC-SHA1"' . " 
" .
    'oauth_timestamp="'.time().'"' . " 
" .
    'oauth_token="'.$access_token.'"' . " 
" .
    'oauth_version="1.0"' . " 
" .
    'Connection: close' . " 
" .
    'Host: api.tradeking.com'

];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
$response = curl_exec($ch);
  • 写回答

1条回答 默认 最新

  • dp610807 2018-04-26 17:56
    关注

    You don't need to manually build the HTTP header -- PHP's OAuth library will do it for you. This is all you need:

    $oauth = new OAuth($consumer_key,$consumer_secret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
    $oauth->setToken($access_token,$access_secret);
    $url = 'https://api.tradeking.com/v1/market/ext/quotes.xml?symbols=fb';
    $oauth->fetch($url);
    print($oauth->getLastResponse());
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM