Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gold Price CLI

一个终端小工具,用公开数据抓取:

  • 伦敦金价,单位 美元/盎司
  • 美元兑人民币汇率,单位 USD/CNY

然后按公式换算出:

人民币/克 = 美元/盎司 × USD/CNY ÷ 31.1034768

运行

单次查询:

python3 -m gold_price

手动输入美元价格并换算成人民币:

python3 -m gold_price --usd 4201.60

手动输入人民币价格并反向换算成美元:

python3 -m gold_price --cny 933.16

持续刷新:

python3 -m gold_price --watch

自定义刷新节奏:

python3 -m gold_price --watch --interval 5 --gold-refresh 5 --fx-refresh 3600

输出

程序默认输出:

伦敦金价:4219.40 美元/盎司 -> 934.92 元/克

手动换算输出示例:

伦敦金换算:4201.60 美元/盎司 -> 933.16 元/克
伦敦金换算:933.16 元/克 -> 4201.60 美元/盎司

数据源

  • 金价:https://api.gold-api.com/price/XAU
  • 汇率主源:https://open.er-api.com/v6/latest/USD
  • 汇率备用源:https://api.frankfurter.app/latest?from=USD&to=CNY

说明:

  • 金价源是秒级更新的实时接口。
  • 默认汇率源属于公开免密钥接口,更新频率通常低于金价,不适合做高频外汇交易用途。

测试

python3 -m unittest discover -s tests -v

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages