New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bocfx

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bocfx

Easy API to get foreign exchange rate from Bank of China.

  • 0.8.1
  • PyPI
  • Socket score

Maintainers
1

bocfx

An easy-to-use python package for getting foreign exchange rate from Bank of China (BOC).
一个帮你快速获取中国银行外汇牌价的 Python 爬虫(也可作外汇牌价实时查询API)。
Author: Bob Lee


Features

特点

  • Multithreading 多线程
  • As a command-line application 支持命令行应用模式
  • As a python module 支持模块导入模式(import到你自己的项目里就能作API了)
  • Foreign exchange selection 支持多种外汇币种同时输出(默认是英、欧、美、加、澳)
  • Foreign exchange quotation filter 支持外汇牌价种类同时输出(买入、卖出、现钞、现汇、中行折算价)
  • Date selection (Realtime/History) 支持仅输出最新牌价 或 输出指定时间段内全部牌价变动
  • Line graph generation 支持生成历史波动曲线
  • .csv generation 支持导出csv格式表格文件
  • Set output path 支持导出到指定路径
  • Show or close loading bar 支持显示或关闭进度条
  • Export to database 支持导出到数据库(可使用Pandas的df.to_sql())

Contents

目录

Installation

安装

Generally, one line command can perfect installation.

pip3 install bocfx 

If your pip links python3, please use pip install bocfx to install bocfx.
REMEMBER, Bocfx may not support python2.


Basic Usage

基本用法 (输出最新的牌价)


As a command-line application

作为命令行工具使用

❯ bocfx


+-----+--------+--------+--------+--------+----------+---------------------+
|  5  | SE_BID | BN_BID | SE_ASK | BN_ASK | BOC_CONV |         Time        |
+-----+--------+--------+--------+--------+----------+---------------------+
| GBP | 873.01 | 845.88 | 879.44 | 883.32 |  874.54  | 2023-05-23 23:09:35 |
| EUR | 757.61 | 734.07 | 763.19 | 765.65 |  760.31  | 2023-05-23 23:09:35 |
| USD | 703.77 | 698.05 | 706.76 | 706.76 |  703.26  | 2023-05-23 23:09:35 |
| CAD | 520.43 |  504   | 524.27 | 526.58 |  520.83  | 2023-05-23 23:09:35 |
| AUD | 465.18 | 450.73 | 468.6  | 470.68 |  467.72  | 2023-05-23 23:09:35 |
+-----+--------+--------+--------+--------+----------+---------------------+
(SE = Spot Exchange, BN = Banknote)
❯ bocfx -f USD                


+-----+--------+--------+--------+--------+----------+---------------------+
|  1  | SE_BID | BN_BID | SE_ASK | BN_ASK | BOC_CONV |         Time        |
+-----+--------+--------+--------+--------+----------+---------------------+
| USD | 703.77 | 698.05 | 706.76 | 706.76 |  703.26  | 2023-05-23 23:25:12 |
+-----+--------+--------+--------+--------+----------+---------------------+
(SE = Spot Exchange, BN = Banknote)


As a Python module

作为 Python 模块导入使用

>>> from bocfx import bocfx

>>> output = bocfx('GBP,USD','SE,ASK') # 选择了英镑和美元,现汇卖出价
>>> output # The latest foreign exchange rate | 英镑和美元,现汇卖出价 (最新的牌价)
['879.22', '706.76'] 


Advanced Usage

进阶用法


As a command-line application

作为命令行工具使用时

-f | 可选外汇 | FX selection -s | 可选牌价 | Quotation types selection -t | 可选时间 | Time / Period selection -p | 输出波动图 | Output plot -c | 输出csv | Output csv table -o | 指定输出路径 | Set output path

bocfx [-f|--fx] [-s|--sort] [-t|--time] (-p|--plot) (-c|--csv) {-o|--op}


Example:
❯ bocfx -f GBP,USD,AUD -s ASK -t 30 -p -c -o '~/desktop/output'
100%|█████████████████████████████████████████████| 3/3 [00:03<00:00,  1.08s/it]
100%|████████████████████████████████████████| 199/199 [00:00<00:00, 422.62it/s]

+-----+--------+--------+---------------------+
|  3  | SE_ASK | BN_ASK |         Time        |
+-----+--------+--------+---------------------+
| GBP | 880.27 | 882.41 | 2019-02-24 10:30:00 |
| USD | 673.08 | 673.08 | 2019-02-24 10:30:00 |
| AUD | 480.65 | 481.82 | 2019-02-24 10:30:00 |
| GBP | 880.27 | 882.41 | 2019-02-24 05:30:00 |
| USD | 673.08 | 673.08 | 2019-02-24 05:30:00 |
| AUD | 480.65 | 481.82 | 2019-02-24 05:30:00 |
...
| GBP | 889.64 | 891.8  | 2019-01-25 00:00:05 |
| USD | 680.4  | 680.4  | 2019-01-25 00:00:05 |
| AUD | 484.37 | 485.56 | 2019-01-25 00:00:05 |
+-----+--------+--------+---------------------+
(SE = Spot Exchange, BN = Banknote)

.csv has already saved to /Users/bob/desktop/output/[GBP+USD+AUD]SE_ASK+BN_ASK_2019-01-25_2019-02-24.csv

Plot has already saved to /Users/bob/desktop/output/[GBP+USD+AUD]SE_ASK+BN_ASK_2019-01-25_2019-02-24.png



As a python module

from bocfx import bocfx

bocfx(FX=0, sort=0, time=-1, plot=0, csv=0, pt=0, op='~/bocfx_output')


Example:
>>> from bocfx import bocfx

# Equivalent command
# example01 = bocfx(FX='GBP,USD', sort='SE', time=1)

>>> example01 = bocfx('GBP,USD','SE',1)
100%|█████████████████████████████████████████████| 2/2 [00:01<00:00,  1.49it/s]

>>> type(example01)
<class 'list'>

>>> print(example01)
[[2, 'SE_BID', 'SE_ASK', 'Time'], ['USD', '669.74', '672.58', '2019-02-25 09:25:23'], ['GBP', '874.18', '880.62', '2019-02-25 09:25:13'], ... , ['GBP', '873.83', '880.27', '2019-02-24 00:00:05'], ['USD', '670.24', '673.08', '2019-02-24 00:00:05']]

>>> from bocfx import bocfx

# Equivalent command
# example02 = bocfx(FX='GBP,USD', sort='SE', time='2018-08-01,2018-08-02', plot=1, csv=1, pt=0, op='~/desktop/example/')

>>> example02 = bocfx('GBP,USD','SE','2018-08-01,2018-08-02',1,1,0,op='~/desktop/example/')
100%|█████████████████████████████████████████████| 2/2 [00:02<00:00,  1.05it/s]
100%|██████████████████████████████████████████| 26/26 [00:00<00:00, 134.46it/s]

.csv has already saved to /Users/bob/desktop/example/[GBP+USD]SE_BID+SE_ASK_2018-08-01_2018-08-02.csv

Plot has already saved to /Users/bob/desktop/example/[GBP+USD]SE_BID+SE_ASK_2018-08-01_2018-08-02.png

>>> type(example02)
<class 'list'>

>>> print(example02)
[[2, 'SE_BID', 'SE_ASK', 'Time'], ['GBP', '888.85', '895.4', '2018-08-02 23:19:36'], ['USD', '683.01', '685.91', '2018-08-02 23:19:36'], ... , ['GBP', '891.33', '897.89', '2018-08-01 00:00:05'], ['USD', '680.22', '683.1', '2018-08-01 00:00:05']]



Option and parameter

选项和参数


Option 1 -f/--fx

外汇种类

-f/--fx is the BOC foreign excahnge selector. This opinion supports multi-parameter.

, is the separator of each parameter, e.g. GBP,USD

Supported foreign currency:
FXISO CodeFull NameAlias
英镑GBPGreat Britain PoundUK
港币HKDHong Kong DollarHK
美元USDUnited States DollarUS/USA
瑞士法郎CHFSwiss Franc
德国马克DEMDeutsche Mark
法国法郎FRFFrench FrancFF
新加坡元SGDSingapore Dollar
瑞典克朗SEKSwedish Krona
丹麦克朗DKKDanish Krone
挪威克朗NOKNorwegian Krone
日元JPYJapanese YenJP
加拿大元CADCanadian DollarCA
澳大利亚元AUDAustralian DollarAU
欧元EUREuroEU
澳门元MOPMacao PatacaMO
菲律宾比索PHPPhilippine Peso
泰国铢THBThai Baht
新西兰元NZDNew Zealand DollarKIWI
韩国元WONSouth Korean WonSK
卢布RUBRussian RubleRU
林吉特MYRMalaysia RinggitSEN
新台币NTDNew Taiwan DollarTW
西班牙比塞塔ESPSpain Peseta
意大利里拉ITLItalian Lira
荷兰盾ANGNederlandse Gulden
比利时法郎BEFBelgian Franc
芬兰马克FIMFinnish Mark
印度卢比INRIndian Rupee
印尼卢比IDRIndonesian Rupee
巴西里亚尔BRLBrasil Rial
阿联酋迪拉姆AEDUnited Arab Emirates Dirham
南非兰特ZAFSouth African Rand
沙特里亚尔SARSaudi Arabian Riyal
土耳其里拉TRYYeni Türk LirasıYTL

FX, ISO and Alias can be used as values of this option, e.g. 英镑, GBP, UK are all correct.
This parameter is case-insensitive, e.g. GBP, gBp, UK, uk will get same output.
If not setting this parameter, the default value of parameter will be GBP, EUR, USD, CAD, AUD.


Example:
~
❯ bocfx            
100%|████████████████████████████████████████████| 5/5 [00:00<00:00, 612.38it/s]

+-----+--------+--------+--------+--------+---------------------+
|  5  | SE_BID | BN_BID | SE_ASK | BN_ASK |         Time        |
+-----+--------+--------+--------+--------+---------------------+
| GBP | 874.37 | 847.2  | 880.81 | 882.95 | 2019-02-25 07:28:17 |
| EUR | 759.05 | 735.47 | 764.65 | 766.35 | 2019-02-25 07:28:17 |
| USD | 670.24 | 664.79 | 673.08 | 673.08 | 2019-02-25 07:28:17 |
| CAD | 509.47 | 493.39 | 513.23 | 514.47 | 2019-02-25 07:28:17 |
| AUD | 478.68 | 463.81 | 482.21 | 483.38 | 2019-02-25 07:28:17 |
+-----+--------+--------+--------+--------+---------------------+
(SE = Spot Exchange, BN = Banknote)

~
❯ bocfx -f GBP,USD                                             
100%|███████████████████████████████████████████| 2/2 [00:00<00:00, 1818.08it/s]

+-----+--------+--------+--------+--------+---------------------+
|  2  | SE_BID | BN_BID | SE_ASK | BN_ASK |         Time        |
+-----+--------+--------+--------+--------+---------------------+
| GBP | 874.37 | 847.2  | 880.81 | 882.95 | 2019-02-25 07:28:17 |
| USD | 670.24 | 664.79 | 673.08 | 673.08 | 2019-02-25 07:28:17 |
+-----+--------+--------+--------+--------+---------------------+
(SE = Spot Exchange, BN = Banknote)


Option 2 -s/--sort

牌价种类

-s/--sort is the filter of quotation types. This opinion supports multi-parameter.

, is the separator of each parameter.

-s/--sortSE Spot Exchange 现汇价BN Banknote 现钞价
BID Bid Price 买入价SE,BID SE_BIDBN,BID BN_BID
ASK Ask Price 卖出价SE,ASK SE_ASKBN,ASK BN_ASK

If not using this option, the default output will include all four sorts.

Example:
~
❯ bocfx -f GBP,USD -s ASK                                  
100%|████████████████████████████████████████████| 2/2 [00:00<00:00, 443.63it/s]

+-----+--------+--------+---------------------+
|  2  | SE_ASK | BN_ASK |         Time        |
+-----+--------+--------+---------------------+
| GBP | 880.81 | 882.95 | 2019-02-25 07:28:17 |
| USD | 673.08 | 673.08 | 2019-02-25 08:35:54 |
+-----+--------+--------+---------------------+
(SE = Spot Exchange, BN = Banknote)

~
❯ bocfx -f GBP,USD -s SE,BID
100%|████████████████████████████████████████████| 2/2 [00:00<00:00, 443.26it/s]

+-----+--------+---------------------+
|  2  | SE_BID |         Time        |
+-----+--------+---------------------+
| GBP | 874.57 | 2019-02-25 08:35:54 |
| USD | 670.24 | 2019-02-25 08:35:54 |
+-----+--------+---------------------+
(SE = Spot Exchange, BN = Banknote)


Option 3 -t/--time

时间范围选择

-t/--time can filter the date of foreign exchange quotation.

There are 3 ways to write parameter.

No.ExampleDefinition定义
16Get data from 6 days ago to today6 天之内的全部历史价格
22019-02-20Get data from 2019-02-20 to today选定时间到今天的全部历史价格
32019-02-20,2019-02-21Get data from 2019-02-20 to 2019-02-21选定时间范围内全部历史价格

If not using this option, only one price (the latest quotation price) will be output.

Option 4 -p/--plot

是否生成折线图

Using -p/--plot can generate a line graph with .png format.

The default output path is ~/bocfx_output/


Option 5 -c/--csv

是否生成csv表格

Using -c/--csv can output data in .csv format.

The default output path is ~/bocfx_output/


Option 6 -o/--op

自定义输出路径

Using -o/--op can change default output path.

Example: -o '~/desktop/example/'


Option 7 -b/--bar

开启进度条显示

Using -b/--bar can show loading bar while the tasks are running.


Web API (temporary demo) (discarded now)

HTTP GET: http://sh.boblee.cn:8080/apis/bocfx?FX=GBP,USD&sort=SE&time=&format=json

ParameterExamples
FX= (Blank = GBP,EUR,USD,CAD,AUD), GBP, GBP,USD,AUD
sort= (Blank = ALL four types), SE, BN, ASK, BID, SE,ASK, SE,BID, BN,ASK, BN,BID
time= (Blank = The latest record), 1, 2020-03-07, 2020-03-07,2020-03-14
format= (Blank = json), json, csv, original

Description of each parameter can be found .
每个参数的含义可参见上方的介绍.


Limitation

局限性

This package is no-database design.

All data are captured from http://srh.bankofchina.com/search/whpj/search.jsp in real time.

Thus, the speed of spider will be strongly influenced by the connectation quality!
本脚本会受 中国银行官网接口速度 的影响!


MIT Licence

Copyright (c) 2019 The Python Packaging Authority

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc