如何通过 Google Finance 等 API 获取货币汇率?

发布于 2024-09-07 10:17:57 字数 258 浏览 7 评论 0原文

现在,我确实找到了 Google Finance API 并开始浏览它,但我发现了很多有关投资组合、交易、头寸和信息的信息其他我一无所知的事情。

我看错文档了吗?我需要做什么才能从 GF 获取汇率信息?这可能吗?

编辑

让事情变得更清楚一些。我对技术内容不感兴趣,也不想要任何代码。

Now, I did find the Google Finance API and started looking through that but I found a lot of info about portfolios, transactions, positions & other stuff I know nothing about.

Am I looking at the wrong docs? What do I need to do to get a feed of exchange rates from GF? Is this even possible?

EDIT

To make things a little clearer. I'm not interested in technical stuff nor do I want any code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

ㄖ落Θ余辉 2024-09-14 10:17:57

感谢您的所有回答。

免费的currencyconverterapi:

  • 每 30 分钟更新一次
  • 免费服务器现在需要

的 API 密钥。示例转换 URL 为:http://free.currencyconverterapi。 com/api/v5/convert?q=EUR_USD&compact=y


对于后代,它们与其他可能的答案一起:

  1. Yahoo Finance 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 自 (2017-08-29) 起改用 fixer.io。
如果您需要的不仅仅是 CSV,这可能会很有用。

  1. 感谢 Keyo雅虎查询语言可让您立即获得一大堆货币XML 或 JSON。数据每秒更新一次(而欧洲央行则有前一天的数据),并在周末停止。不需要任何形式的注册。

http://query.yahooapis.com/v1/public/yql? q=select * from yahoo.finance.xchange 其中配对 ("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%20in%20%28%22USDMXN%22%2C%20% 22USDCHF%22%29

yql 控制台不再可用

  1. 开源汇率 API

免费供个人使用(每月 1000 次点击)
免费帐户中不允许更改“基础”(从“美元”)
需要注册。
请求:http://openexchangerates.org/latest.json
响应:

   <!-- language: lang-js -->

    {
      "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 ...
      }
    }
  1. currencylayer API

免费计划每月 100 次点击
免费帐户中不允许更改“来源”(从“美元”)
需要注册。
文档:currencylayer.com/documentation

JSON 响应:

   <!-- language: lang-js -->

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

免费计划(每月 1000 次点击)
免费帐户中不允许更改“基础”(从“美元”)
需要注册
数据每 60 秒更新一次。
全球 179 种货币,包括货币、金属和加密货币
支持(即使是免费计划)Shell、Node.js、Java、Python、PHP、Ruby、JS、C#、C、Go、Swift。
文档:https://currencyfreaks.com/documentation.html

端点:

$ curl 'https://api.currencyfreaks.com/latest?apikey=YOUR_APIKEY'

JSON 响应:

{
    "date": "2020-10-08 12:29:00+00",
    "base": "USD",
    "rates": {
        "FJD": "2.139",
        "MXN": "21.36942",
        "STD": "21031.906016",
        "LVL": "0.656261",
        "SCR": "18.106031",
        "CDF": "1962.53482",
        "BBD": "2.0",
        "GTQ": "7.783265",
        "CLP": "793.0",
        "HNL": "24.625383",
        "UGX": "3704.50271",
        "ZAR": "16.577611",
        "TND": "2.762",
        "CUC": "1.000396",
        "BSD": "1.0",
        "SLL": "9809.999914",
        "SDG": 55.325,
        "IQD": "1194.293591",
          .
          .
          .
    [179 currencies]
    }
}
  1. Fixer.io API(欧洲央行数据)

每月 100 次点击的免费计划
免费帐户中不允许更改“来源”(从“美元”)
需要注册。

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

Website : http://fixer.io/

Example request :
[http://api.fixer.io/latest?base=USD][7]

Only collects one value per each day

  1. 欧洲央行动态

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

XML 响应:

   <!-- language: lang-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>
  1. exchangeratesapi.io

根据该网站:

汇率API是欧洲央行发布的当前和历史外汇汇率的免费服务

This service is compatible with fixer.io and is really easy to use: no API key needed - UPDATE: API key is now needed, free tier is 250 requests/mo.
For example (this uses CURL, but you can use your favorite requesting tool):

    > curl https://api.exchangeratesapi.io/latest?base=GBP&symbols=USD&apikey=YOUR_KEY
    {"base":"GBP","rates":{"USD":1.264494191},"date":"2019-05-29"}
  1. CurrencyApi.net

免费计划每月 1250 次点击
150 种加密货币和实物货币 - 实时更新
免费帐户上的基础货币设置为美元
需要注册。
文档:currencyapi.net/documentation

JSON 响应:

    {
      "valid": true,
      "updated": 1567957373,
      "base": "USD",
      "rates": {
              "AED": 3.673042,
              "AFN": 77.529504,
              "ALL": 109.410403,
              // 165 currencies + some cryptos
          }
      }
  1. 来自 LabStack 的货币

更新:这些链接当前不起作用(2024 年 6 月)。也许停产了。

网站:https://labstack.com/currency
文档:https://labstack.com/docs/api/currency/convert< br>
定价:https://labstack.com/pricing
请求:https://currency.labstack.com/api/v1/兑换/1/美元/印度卢比
响应:

```js
 {
   "time": "2019-10-09T21:15:00Z",
   "amount": 71.1488
 }
 ```

1http://query.yahooapis.com/v1/public/yql?q=select * 来自 yahoo.finance.xchange,其中配对 ("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

  1. currency-api

  • 免费&使用 CDN 实现超快响应
  • 无速率限制
  • 200 多种货币,包括常见加密货币和加密货币Metals
  • 每日更新

文档:链接
请求: https://cdn.jsdelivr .net/npm/@fawazahmed0/currency-api@latest/v1/currencies/eur.json
请求(后备): https://latest.currency-api.pages .dev/v1/currencies/eur.json
响应:

{
  "date": "2024-08-24",
  "eur": {
    "usd": 1.12060937,
    "jpy": 161.73109954,
     ...
  }
}
  1. QWeb 的货币 API

  • 160 多种货币
  • 每日更新
  • 一对一和一对多查找
  • 带有 JSON 响应的简单 REST 端点
  • 无限请求所需的 API 密钥,没有基础货币限制(下午 8 美元)。

文档:链接

示例请求:

https://apis.qweb.co.uk/currency-exchange-rates/ACCESS_KEY/gbp/cad,eur,usd.json

示例响应:

{
    "from":"GBP",
    "rates":[
        {
            "currency":"CAD",
            "exchange":"1.719870000000"
        },
        {
            "currency":"EUR",
            "exchange":"1.171292099166"
        },
        {
            "currency":"USD",
            "exchange":"1.271310000000"
        }
    ],
    "answer":"success"
}

Thanks for all your answers.

Free currencyconverterapi:

  • Rates updated every 30 min
  • API key is now required for the free server.

A sample conversion URL is: http://free.currencyconverterapi.com/api/v5/convert?q=EUR_USD&compact=y


For posterity here they are along with other possible answers:

  1. Yahoo finance API Discontinued 2017-11-06###

Discontinued as of 2017-11-06 with message

It has come to our attention that this service is being used in
violation of the Yahoo Terms of Service. As such, the service is being
discontinued. For all future markets and equities data research,
please refer to finance.yahoo.com.

Request: http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDINR=X
This CSV was being used by a jQuery plugin called Curry. Curry has since (2017-08-29) moved to use fixer.io instead due to stability issues.
Might be useful if you need more than just a CSV.

  1. (thanks to Keyo) Yahoo Query Language lets you get a whole bunch of currencies at once in XML or JSON. The data updates by the second (whereas the European Central Bank has day old data), and stops in the weekend. Doesn't require any kind of sign up.

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

Here is the YQL query builder, where you can test a query and copy the url: (NO LONGER AVAILABLE)

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

yql console no longer available

  1. Open Source Exchange Rates API

Free for personal use (1000 hits per month)
Changing "base" (from "USD") is not allowed in Free account
Requires registration.
Request: http://openexchangerates.org/latest.json
Response:

   <!-- language: lang-js -->

    {
      "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 ...
      }
    }
  1. currencylayer API

Free Plan for 100 monthly hits
Changing "source" (from "USD") is not allowed in Free account
Requires registration.
Documentation: currencylayer.com/documentation

JSON Response:

   <!-- language: lang-js -->

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

Free Plan (1000 hits per month)
Changing 'Base' (From 'USD') is not allowed in free account
Requires registration
Data updated every 60 sec.
179 currencies worldwide including currencies, metals, and cryptocurrencies
Support (Even on the free plan) Shell,Node.js, Java, Python, PHP, Ruby, JS, C#, C, Go, Swift.
Documentation: https://currencyfreaks.com/documentation.html

Endpoint:

$ curl 'https://api.currencyfreaks.com/latest?apikey=YOUR_APIKEY'

JSON Response:

{
    "date": "2020-10-08 12:29:00+00",
    "base": "USD",
    "rates": {
        "FJD": "2.139",
        "MXN": "21.36942",
        "STD": "21031.906016",
        "LVL": "0.656261",
        "SCR": "18.106031",
        "CDF": "1962.53482",
        "BBD": "2.0",
        "GTQ": "7.783265",
        "CLP": "793.0",
        "HNL": "24.625383",
        "UGX": "3704.50271",
        "ZAR": "16.577611",
        "TND": "2.762",
        "CUC": "1.000396",
        "BSD": "1.0",
        "SLL": "9809.999914",
        "SDG": 55.325,
        "IQD": "1194.293591",
          .
          .
          .
    [179 currencies]
    }
}
  1. Fixer.io API (European Central Bank data)

Free Plan for 100 monthly hits
Changing "source" (from "USD") is not allowed in Free account
Requires registration.

This API endpoint is deprecated and will stop working on June 1st, 2018. For more information please visit: https://github.com/fixerAPI/fixer#readme)

Website : http://fixer.io/

Example request :
[http://api.fixer.io/latest?base=USD][7]

Only collects one value per each day

  1. European Central Bank Feed

Docs:
http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html#dev
Request: http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml

XML Response:

   <!-- language: lang-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>
  1. exchangeratesapi.io

According to the website:

Exchange rates API is a free service for current and historical foreign exchange rates published by the European Central Bank

This service is compatible with fixer.io and is really easy to use: no API key needed - UPDATE: API key is now needed, free tier is 250 requests/mo.
For example (this uses CURL, but you can use your favorite requesting tool):

    > curl https://api.exchangeratesapi.io/latest?base=GBP&symbols=USD&apikey=YOUR_KEY
    {"base":"GBP","rates":{"USD":1.264494191},"date":"2019-05-29"}
  1. CurrencyApi.net

Free Plan for 1250 monthly hits
150 Crypto and physical currencies - live updates
Base currency is set as USD on free account
Requires registration.
Documentation: currencyapi.net/documentation

JSON Response:

    {
      "valid": true,
      "updated": 1567957373,
      "base": "USD",
      "rates": {
              "AED": 3.673042,
              "AFN": 77.529504,
              "ALL": 109.410403,
              // 165 currencies + some cryptos
          }
      }
  1. Currency from LabStack

UPDATE: These links aren't currently working (June 2024). Maybe discontinued.

Website: https://labstack.com/currency
Documentation: https://labstack.com/docs/api/currency/convert
Pricing: https://labstack.com/pricing
Request: https://currency.labstack.com/api/v1/convert/1/USD/INR
Response:

```js
 {
   "time": "2019-10-09T21:15:00Z",
   "amount": 71.1488
 }
 ```

1: 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

  1. currency-api

  • Free & Blazing Fast response using CDN
  • No Rate limits
  • 200+ Currencies, Including Common Cryptocurrencies & Metals
  • Daily Updated

Documentation: Link
Request: https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/eur.json
Request(Fallback): https://latest.currency-api.pages.dev/v1/currencies/eur.json
Response:

{
  "date": "2024-08-24",
  "eur": {
    "usd": 1.12060937,
    "jpy": 161.73109954,
     ...
  }
}
  1. QWeb's Currency API

  • 160+ currencies
  • Updated daily
  • One-to-one and one-to-many lookups
  • Simple REST endpoints with JSON responses
  • API key required for unlimited requests with no base currency restrictions ( $8 p/m ).

Documentation: Link

Example request:

https://apis.qweb.co.uk/currency-exchange-rates/ACCESS_KEY/gbp/cad,eur,usd.json

Example response:

{
    "from":"GBP",
    "rates":[
        {
            "currency":"CAD",
            "exchange":"1.719870000000"
        },
        {
            "currency":"EUR",
            "exchange":"1.171292099166"
        },
        {
            "currency":"USD",
            "exchange":"1.271310000000"
        }
    ],
    "answer":"success"
}
飘然心甜 2024-09-14 10:17:57

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

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

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

The European Central Bank (ECB) also has the most reliable free feed that I know of. It contains approx 28 currencies and is updated at least daily.

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

For more formats and tools see the ECB reference page:
http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html

提赋 2024-09-14 10:17:57

如果您需要一个免费且简单的 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 }

If you need a free and simple API for converting one currency to another, try free.currencyconverterapi.com.

Disclaimer, I'm the author of the website and I use it for one of my other websites.

The service is free to use even for commercial applications but offers no warranty. For performance reasons, the values are only updated every hour.

A sample conversion URL is: http://free.currencyconverterapi.com/api/v6/convert?q=EUR_PHP&compact=ultra&apiKey=sample-api-key which will return a json-formatted value, e.g. {"EUR_PHP":60.849184}

梦旅人picnic 2024-09-14 10:17:57
鯉魚旗 2024-09-14 10:17:57

以下是一些使用 PHP 进行交换 API 的示例。

[ 开放汇率 API ]

每月免费提供 1,000 个请求。您必须注册并获取 App ID。免费账户的基础货币为美元。检查支持的货币文档

// 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 美元 = 18039.09015 日元

[ 货币层 API ]

每月免费提供 1,000 个请求。您必须注册并获取访问密钥。免费帐户支持自定义基础货币。查看文档

$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 日元

Here are some exchange APIs with PHP example.

[ Open Exchange Rates API ]

Provides 1,000 requests per month free. You must register and grab the App ID. The base currency USD for free account. Check the supported currencies and documentation.

// 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

[ Currency Layer API ]

Provides 1,000 requests per month free. You must register and grab the Access KEY. Custom base currency is not supported in free account. Check the 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 USD = 18036.75045 JPY

初见你 2024-09-14 10:17:57

除了通过IP进行地理定位之外,您还可以尝试geoplugin

(但IP是提供商IP,所以不太准确) ,它们还返回货币并具有货币转换器:请参阅示例。

他们更新了 111 种货币。

You can try geoplugin

Beside the geolocation done by IP (but the IP is the provider IP, so not so accurate), they return currencies also and have a currency converter: see examples.

They have 111 currencies updated.

久光 2024-09-14 10:17:57

如果您正在寻找基于 ruby​​ 的解决方案来解决此问题,我建议使用 Google 计算器方法,该解决方案类似于以下内容: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})"

If you're looking for a ruby based solution for this problem, I recommend using the Google Calculator method a solution similar to the following: 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})"
梦在深巷 2024-09-14 10:17:57

这是一个简单的 PHP 脚本,它获取英镑和美元之间的汇率

<?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 '<br/>'; 
?>

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

Here is one simple PHP Script which gets exchange rate between GBP and 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 '<br/>'; 
?>

Google currency rates are not accurate google itself says ==> Google cannot guarantee the accuracy of the exchange rates used by the calculator. You should confirm current rates before making any transactions that could be affected by changes in the exchange rates. Foreign currency rates provided by Citibank N.A. are displayed under licence. Rates are for information purposes only and are subject to change without notice. Rates for actual transactions may vary and Citibank is not offering to enter into any transaction at any rate displayed.

迷迭香的记忆 2024-09-14 10:17:57

对于所有寻找有关货币兑换提示的新手,请查看此链接。 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);

For all newbie guys searching for some hint about currency conversion, take a look at this link. Datavoila

It helped med a lot regarding my own project in C#. Just in case the site disappears, I'll add the code below. Just add the below steps to your own project. Sorry about the formatting.

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文