首页 文章

如何通过Google财经等API获取货币汇率? [关闭]

提问于
浏览
137

现在,我确实找到了Google Finance API并开始查看,但我发现了很多关于投资组合,交易,头寸和其他我一无所知的信息 .

我在查看错误的文档吗?我需要做些什么来从GF获得汇率?这甚至可能吗?

EDIT

让事情变得更加清晰 . 我对技术内容不感兴趣,也不想要任何代码 .

10 回答

  • 40

    你可以试试geoplugin

    除了由IP完成的地理位置(但IP是提供商IP,所以不那么准确),他们也返回货币并有货币转换器:参见示例 .

    他们有111种货币已更新 .

  • 767

    谢谢你的所有答案 .

    Free currencyconverterapi:

    • 费率每30分钟更新一次

    • 无需帐户

    示例转换网址为:http://free.currencyconverterapi.com/api/v5/convert?q=EUR_USD&compact=y


    对于后人来说,这里有其他可能的答案:

    雅虎财务API停刊2017-11-06

    自2017-11-06起停止发布消息

    我们注意到此服务的使用违反了雅虎服务条款 . 因此,该服务正在停止 . 有关所有未来市场和股票数据研究,请参阅finance.yahoo.com .

    要求:http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDINR=X
    这个CSV被一个名为Curry的jQuery插件使用 . 由于稳定性问题,库里已经(2017-08-29)转而使用fixer.io . 如果您需要的不仅仅是CSV,可能会很有用 .

    • thanks to KeyoYahoo Query Language 允许您以XML或JSON一次获得一大堆货币 . 数据更新由第二个(而欧洲中央银行有一天的数据),并在周末停止 . 不需要任何形式的注册 .

    http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("USDEUR", "USDJPY", "USDBGN", "USDCZK", "USDDKK", "USDGBP", "USDHUF", "USDLTL", "USDLVL", "USDPLN", "USDRON", "USDSEK", "USDCHF", "USDNOK", "USDHRK", "USDRUB", "USDTRY", "USDAUD", "USDBRL", "USDCAD", "USDCNY", "USDHKD", "USDIDR", "USDILS", "USDINR", "USDKRW", "USDMXN", "USDMYR", "USDNZD", "USDPHP", "USDSGD", "USDTHB", "USDZAR", "USDISK")&env=store://datatables.org/alltableswithkeys

    这是YQL查询构建器,您可以在其中测试查询并复制URL :(不再可用)

    http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select%20*%20from%20yahoo.finance.xchange%20where%20pair% 20英寸%20%28%22USDMXN%22%2C%20%22USDCHF%22%29

    enter image description here

    开源汇率API

    Free for personal use(每月1000次点击)
    免费帐户中不允许更改"base"(来自"USD")
    需要注册 .
    要求:http://openexchangerates.org/latest.json
    响应:

    {
      "disclaimer": "This data is collected from various providers ...",
      "license": "all code open-source under GPL v3 ...",
      "timestamp": 1323115901,
      "base": "USD",
      "rates": {
          "AED": 3.66999725,
          "ALL": 102.09382091,
          "ANG": 1.78992886,
          // 115 more currency rates here ...
      }
    }
    

    currencylayer API

    Free Plan每月点击1,000次
    免费帐户中不允许更改"source"(来自"USD")
    需要注册 .
    文档:currencylayer.com/documentation

    JSON响应:

    {
      [...]
      "timestamp": 1436284516,
      "source": "USD",
      "quotes": {
          "USDAUD": 1.345352401,
          "USDCAD": 1.27373397,
          "USDCHF": 0.947845302,
          "USDEUR": 0.91313905,
          "USDGBP": 0.647603397,
          // 168 world currencies
          }
      }
    

    Fixer.io API(欧洲中央银行数据)

    免费计划每月点击1,000次
    免费帐户中不允许更改"source"(来自"USD")需要注册 .

    此API endpoints 已弃用,将于2018年6月1日停止工作 . 有关详细信息,请访问:https://github.com/fixerAPI/fixer#readme)

    网站:http://fixer.io/
    示例请求:http://api.fixer.io/latest?base=USD
    每天只收集一个值

    欧洲中央银行饲料

    文件:http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html#dev
    要求:http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml

    XML响应:

    <Cube>
      <Cube time="2015-07-07">
      <Cube currency="USD" rate="1.0931"/>
      <Cube currency="JPY" rate="133.88"/>
      <Cube currency="BGN" rate="1.9558"/>
      <Cube currency="CZK" rate="27.100"/>
    </Cube>
    
  • 52

    欧洲中央银行(ECB)也拥有我所知道的最可靠的免费饲料 . 它包含大约28种货币,至少每天更新 .

    http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml

    有关更多格式和工具,请参阅ECB参考页面:http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html

  • 0

    如果您需要一个免费且简单的API来将一种货币转换为另一种货币,请尝试free.currencyconverterapi.com .

    免责声明,我是该网站的作者,我将其用于我的其他网站 .

    该服务即使是商业应用也可免费使用,但不提供保修 . 出于性能原因,值仅每小时更新一次 .

    示例转换URL为:http://free.currencyconverterapi.com/api/v6/convert?q=EUR_PHP&compact=ultra&apiKey=sample-api-key,它将返回json格式的值,例如: {"EUR_PHP":60.849184}

  • 0

    我从http://www.scriptarticle.com/2012/05/03/get-live-currency-rates-and-currency-conversion-using-php-and-apis/获得了这些内容

    <?php
    
    function get_currency($from_Currency, $to_Currency, $amount) {
        $amount = urlencode($amount);
        $from_Currency = urlencode($from_Currency);
        $to_Currency = urlencode($to_Currency);
    
        $url = "http://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency";
    
        $ch = curl_init();
        $timeout = 0;
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    
        curl_setopt ($ch, CURLOPT_USERAGENT,
                     "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $rawdata = curl_exec($ch);
        curl_close($ch);
        $data = explode('bld>', $rawdata);
        $data = explode($to_Currency, $data[1]);
    
        return round($data[0], 2);
    }
    
    // Call the function to get the currency converted
    echo get_currency('USD', 'INR', 1);
    
    ?>
    
  • -1

    以下是一些使用PHP示例的交换API .

    [开放汇率API]

    每月免费提供1,000个请求 . 您必须注册并获取App ID . 免费帐户的基础货币USD . 检查supported currenciesdocumentation .

    // open exchange URL // valid app_id * REQUIRED *
    $exchange_url = 'https://openexchangerates.org/api/latest.json';
    $params = array(
        'app_id' => 'YOUR_APP_ID'
    );
    
    // make cURL request // parse JSON
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $exchange_url . '?' . http_build_query($params),
        CURLOPT_RETURNTRANSFER => true
    ));
    $response = json_decode(curl_exec($curl));
    curl_close($curl);
    
    if (!empty($response->rates)) {
        // convert 150 USD to JPY ( Japanese Yen )
        echo $response->rates->JPY * 150;
    }
    

    150 USD = 18039.09015 JPY

    [货币层API]

    每月免费提供1,000个请求 . 您必须注册并获取访问密钥 . 自由帐户支持自定义基本货币 not . 检查documentation .

    $exchange_url = 'http://apilayer.net/api/live';
    $params = array(
        'access_key' => 'YOUR_ACCESS_KEY',
        'source' => 'USD',
        'currencies' => 'JPY',
        'format' => 1 // 1 = JSON
    );
    
    // make cURL request // parse JSON
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $exchange_url . '?' . http_build_query($params),
        CURLOPT_RETURNTRANSFER => true
    ));
    $response = json_decode(curl_exec($curl));
    curl_close($curl);
    
    if (!empty($response->quotes)) {
        // convert 150 USD to JPY ( Japanese Yen )
        echo '150 USD = ' . $response->quotes->USDJPY * 150 . ' JPY';
    }
    

    150美元= 18036.75045日元

  • 57

    如果您正在寻找基于ruby的解决方案来解决此问题,我建议您使用Google Calculator方法,解决方案类似于以下内容:http://j.mp/QIC564

    require 'faraday'
    require 'faraday_middleware'
    require 'json'
    
    # Debug: 
    # require "pry"
    
    
    country_code_src = "USD"
    country_code_dst = "INR"
    connection = Faraday.get("http://www.google.com/ig/calculator?hl=en&q=1#{country_code_src}=?#{country_code_dst}")
    
    currency_comparison_hash = eval connection.body #Google's output is not JSON, it's a hash
    
    dst_currency_value, *dst_currency_text = *currency_comparison_hash[:rhs].split(' ')
    dst_currency_value = dst_currency_value.to_f
    dst_currency_text = dst_currency_text.join(' ')
    
    puts "#{country_code_dst} -> #{dst_currency_value} (#{dst_currency_text} to 1 #{country_code_src})"
    
  • 1

    这是一个简单的PHP脚本,它可以获得GBP和USD之间的汇率

    <?php
    $amount = urlencode("1");
    $from_GBP0 = urlencode("GBP");
    $to_usd= urlencode("USD");
    $Dallor = "hl=en&q=$amount$from_GBP0%3D%3F$to_usd";
    $US_Rate = file_get_contents("http://google.com/ig/calculator?".$Dallor);
    $US_data = explode('"', $US_Rate);
    $US_data = explode(' ', $US_data['3']);
    $var_USD = $US_data['0'];
    echo $to_usd;
    echo $var_USD;
    echo '
    '; ?>

    谷歌货币汇率不准确谷歌本身说==>谷歌不能保证计算器使用的汇率的准确性 . 您应该在进行任何可能受汇率变化影响的交易之前确认当前汇率 . Citibank N.A.提供的外币汇率根据许可证显示 . 价格仅供参考,如有更改,恕不另行通知 . 实际交易的价格可能会有所不同,花旗银行不会以任何显示的汇率进行任何交易 .

  • 14

    对于所有寻找货币转换暗示的新手,请看一下这个链接 . Datavoila

    它对我在C#中的项目有很大帮助 . 为了防止网站消失,我将在下面添加代码 . 只需将以下步骤添加到您自己的项目中即可 . 抱歉格式化 .

    const string fromCurrency = "USD";
    const string toCurrency = "EUR";
    const double amount = 49.95;
    // For other currency symbols see http://finance.yahoo.com/currency-converter/
    // Clear the output editor //optional use, AFAIK
    Output.Clear();
    
    // Construct URL to query the Yahoo! Finance API
    const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1";
    string url = String.Format(urlPattern, fromCurrency, toCurrency);
    
    // Get response as string
    string response = new WebClient().DownloadString(url);
    
    // Convert string to number
    double exchangeRate =
        double.Parse(response, System.Globalization.CultureInfo.InvariantCulture);
    
    // Output the result
    Output.Text = String.Format("{0} {1} = {2} {3}",
                                amount, fromCurrency,
                                amount * exchangeRate, toCurrency);
    

相关问题