# 風(fēng)控系統(tǒng)部署手冊
版本|日期|作者|備注
----|----|----|---
0.0.1|2020-09-30||初始版本編寫
## 1 簡介
本文檔是主要是介紹風(fēng)控系統(tǒng)環(huán)境配置和風(fēng)控系統(tǒng)安裝的便捷手冊. 分為:
+ 系統(tǒng)依賴環(huán)境部署
+ 上賬系統(tǒng)部署
+ 上交所系統(tǒng)部署
+ 深交所系統(tǒng)部署
等三部分組成。在進(jìn)行系統(tǒng)配置前,請為創(chuàng)建一個 __`rishon`__ 并為該用戶開通 __`su`__ 權(quán)限顿苇,以便后續(xù)軟件包的安裝及其系統(tǒng)配置文件的創(chuàng)建和修改道逗。
## 2 系統(tǒng)環(huán)境部署
系統(tǒng)環(huán)境部署是指風(fēng)控系統(tǒng)運(yùn)行時,所依賴的系統(tǒng)庫,軟件庫等。主要有
+ gcc-7.5.0+
+ boost 1.65.1
+ odbc and msodbcsql17
+ python3.6.8 及第三方庫aiohttp
+ other tools
## 3 gcc-7.5.0
由于 __redhat 7__ 內(nèi)置的 __gcc__ 版本為 __4.8.5__。由于風(fēng)控系統(tǒng)采用了新版的 c++11/c++14/c++17 進(jìn)行開發(fā)闸与。__gcc-7.5.0__ 是一個較為全面支持c++17. 建議 gcc 通過源碼安裝,且版本 __最低__ 為 __gcc-7.5.0__
__Table 2.1: gcc-7.5.0 所依賴的庫和軟件表__
name|package name|download url|description
----|-----------|------------|-----------
m4|m4-1.4.16-10.el7.x86_64.rpm|[m4下載](http://mirror.centos.org/centos/7/os/x86_64/Packages/m4-1.4.16-10.el7.x86_64.rpm)|編譯 __gmp__ 依賴
gmp|gmp-6.2.0.tar|源碼安裝岸售,壓縮包已提供|gcc源碼編譯前需要安裝
mpfr|mpfr-4.1.0.tar.bz2|源碼安裝践樱,壓縮包已提供|gcc源碼編譯前需要安裝
mpc|mpc-1.2.0.tar.gz|源碼安裝,壓縮包已提供|gcc源碼編譯前需要安裝
isl|isl-0.16.1.tar.bz2|源碼安裝凸丸,壓縮包已提供|gcc源碼編譯前需要安裝
其中拷邢, __`gmp`__, __`mpfr`__ , __`mpc`__ 和 __`isl`__ 四個文件是通過源碼安裝。 如果系統(tǒng)可以聯(lián)網(wǎng)甲雅,可直接在 gcc 目錄下的執(zhí)行:
```
[gcc-7.5.0]$ ./contrib/download_prerequisites
```
即可解孙。另外,以上四個包, 詳見壓縮在文件 __`gcc-tmp.tar.bz`__抛人。
### 3.1? install m4
__`m4`__ 是直接用提供的安裝包進(jìn)行安裝弛姜,或者在命令行直接進(jìn)行
```
yum install m4
```
### 3.2 gmp
```
[rishon@stsz141654 tool]$ ls
gcc-tmp.tar.bz
[rishon@stsz141654 tool]$ tar xvf gcc-tmp.tar.bz
gmp-6.2.0.tar
isl-0.16.1.tar.bz2
mpc-1.2.0.tar.gz
mpfr-4.1.0.tar.bz2
[rishon@stsz141654 tool]$ tar xvf gmp-6.2.0.tar
[rishon@stsz141654 tool]$ cd gmp-6.2.0/
[rishon@stsz141654 gmp-6.2.0]$ mkdir build
[rishon@stsz141654 gmp-6.2.0]$ cd build/
[rishon@stsz141654 build]$ ls
[rishon@stsz141654 build]$ ../configure
config.status: linking ../mpn/x86_64/aorrlsh_n.asm to mpn/rsblsh_n.asm
config.status: linking ../mpn/generic/add_n_sub_n.c to mpn/add_n_sub_n.c
config.status: linking ../mpn/x86_64/addaddmul_1msb0.asm to mpn/addaddmul_1msb0.asm
config.status: linking ../mpn/x86_64/pentium4/gmp-mparam.h to gmp-mparam.h
config.status: executing libtool commands
configure: summary of build options:
? Version:? ? ? ? ? GNU MP 6.2.0
? Host type:? ? ? ? pentium4-pc-linux-gnu
? ABI:? ? ? ? ? ? ? 64
? Install prefix:? ? /usr/local
? Compiler:? ? ? ? ? gcc
? Static libraries:? yes
? Shared libraries:? yes
[rishon@stsz141654 build]$ make -j20
[rishon@stsz141654 build]$ sudo make install
```
### 3.3 mpfr
```
[rishon@stsz141654 tool]$ tar xvf mpfr-4.1.0.tar.bz2
[rishon@stsz141654 tool]$ cd mpfr-4.1.0/
[rishon@stsz141654 mpfr-4.1.0]$ ls
acinclude.m4? AUTHORS? ? compile? ? ? configure? ? COPYING.LESSER? examples? ? ltmain.sh? ? Makefile.in? NEWS? ? src? ? ? ? ? TODO? VERSION
aclocal.m4? ? BUGS? ? ? config.guess? configure.ac? depcomp? ? ? ? INSTALL? ? m4? ? ? ? ? missing? ? ? PATCHES? test-driver? tools
ar-lib? ? ? ? ChangeLog? config.sub? ? COPYING? ? ? doc? ? ? ? ? ? install-sh? Makefile.am? mpfr.pc.in? README? tests? ? ? ? tune
[rishon@stsz141654 mpfr-4.1.0]$ mkdir build
[rishon@stsz141654 mpfr-4.1.0]$ cd build/
[rishon@stsz141654 build]$ ../configure
[rishon@stsz141654 build]$ make -j20
[rishon@stsz141654 build]$ sudo make install
```
### 3.4 mpc
```
[rishon@stsz141654 tool]$ tar xvf mpc-1.2.0.tar.gz
[rishon@stsz141654 tool]$ cd mpc-1.2.0/
[rishon@stsz141654 mpc-1.2.0]$ mkdir build
[rishon@stsz141654 mpc-1.2.0]$ cd build
[rishon@stsz141654 build]$ ../configure
[rishon@stsz141654 build]$ make -j20
[rishon@stsz141654 build]$ sudo make install
```
### 3.5 isl
```
[rishon@stsz141654 tool]$ tar xvf isl-0.16.1.tar.bz2
[rishon@stsz141654 tool]$ cd isl-0.16.1/
[rishon@stsz141654 isl-0.16.1]$ mkdir build
[rishon@stsz141654 isl-0.16.1]$ cd build
[rishon@stsz141654 build]$ ../configure
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating bound_test.sh
config.status: creating codegen_test.sh
config.status: creating pip_test.sh
config.status: creating isl_config.h
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing include/isl/stdint.h commands
config.status: creating include/isl/stdint.h : _ISL_INCLUDE_ISL_STDINT_H
config.status: executing isl.pc commands
config.status: creating isl.pc.in
config.status: creating isl.pc
config.status: creating isl-uninstalled.pc
config.status: creating isl-uninstalled.sh
[rishon@stsz141654 build]$ make -j20
[rishon@stsz141654 build]$ sudo make install
```
### 3.6 gcc
```
[rishon@stsz141654 tool]$ tar xvf gcc-7.5.0.tar.bz2
[rishon@stsz141654 tool]$ cd gcc-7.5.0/
[rishon@stsz141654 mpc-1.2.0]$ mkdir build
[rishon@stsz141654 mpc-1.2.0]$ cd build
[rishon@stsz141654 build]$ ../configure --prefix=/usr/local/gcc7 --enable-languages=c,c++,go? --disable-multilib
[rishon@stsz141654 build]$ make -j20
[rishon@stsz141654 build]$ sudo make install
```
大概編譯20分鐘左右⊙叮可以把 __`/etc/local/lib`__ , __`/etc/local/gcc7/lib64`__ 和 __`/etc/local/lib64`__ 加到 __`/etc/ld.so.conf`__ 里面廷臼, 并執(zhí)行
__`su ldconfig`__.
## 4 boost 1.65.1
```
[rishon@stsz141654 tool]$ tar xvf boost 1.65.1.tar.gz
[rishon@stsz141654 tool]$ cd boost 1.65.1/
[rishon@stsz141654 boost 1.65.1]$ ./bootstrap.sh
[rishon@stsz141654 boost 1.65.1]$ ./b2 -j20
[rishon@stsz141654 boost 1.65.1]$ sudo ./b2 install
```
## 5 odbc and msodbcsql
odbc 和 msodbcsql 以下載安裝包為主。 [下載路徑](https://packages.microsoft.com/rhel/7/prod/)
+ [unixODBC-2.3.7-1](https://packages.microsoft.com/rhel/7/prod/unixODBC-2.3.7-1.rh.x86_64.rpm)
+ [unixODBC-devel-2.3.7-1](https://packages.microsoft.com/rhel/7/prod/unixODBC-devel-2.3.7-1.rh.x86_64.rpm)
+ [msodbcsql17-17.6.1.1](https://packages.microsoft.com/rhel/7/prod/msodbcsql17-17.6.1.1-1.x86_64.rpm)
依次安裝
```
sudo yum install unixODBC
sudo yum install unixODBC
sudo yum install msodbcsql17
```
如果安裝失敗, 可進(jìn)行強(qiáng)制安裝
+ __`rpm -ivh? unixODBC-2.3.1-14.el7.x86_64.rpm --force --nodeps`__ ,
+ __`rpm -ivh? unixODBC-devel-2.3.1-14.el7.x86_64.rpm --force --nodeps`__,
+ __`rpm -ivh? msodbcsql17-17.6.1.1-1.x86_64.rpm --force --nodeps`__
## 6 Python3.6.8
您可以選擇熟悉的方式自行安裝Python3.6.8 及第三方庫aiohttp 荠商。此外我們提供了一個方便的壓縮包惠桃,目錄結(jié)構(gòu)如下座硕,解壓之后執(zhí)行其中的install.sh 即可鞍爱。
```
[root@stsz141654 tool]# tar -zxvf python3_rpm.tar.gz
python3_rpm/
python3_rpm/python3-3.6.8-13.el7.x86_64.rpm
python3_rpm/python3-libs-3.6.8-13.el7.x86_64.rpm
python3_rpm/python3-pip-9.0.3-5.el7.noarch.rpm
python3_rpm/python3-setuptools-39.2.0-10.el7.noarch.rpm
python3_rpm/install.sh
[root@stsz141654 tool]# cd python3_rpm/
[root@stsz141654 python3_rpm]#
[root@stsz141654 python3_rpm]# cat install.sh
#!/bin/bash
rpm -ivh *.rpm
python3 -m pip install -i http://stockmirrors.paic.com.cn/pypi/web/simple aiohttp --trusted-host stockmirrors.paic.com.cn
[root@stsz141654 python3_rpm]# bash install.sh
warning: python3-3.6.8-13.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...? ? ? ? ? ? ? ? ? ? ? ? ? ################################# [100%]
Updating / installing...
? 1:python3-libs-3.6.8-13.el7? ? ? ? ################################# [ 25%]
? 2:python3-pip-9.0.3-5.el7? ? ? ? ? ################################# [ 50%]
? 3:python3-setuptools-39.2.0-10.el7 ################################# [ 75%]
? 4:python3-3.6.8-13.el7? ? ? ? ? ? ################################# [100%]
WARNING: Running pip install with root privileges is generally not a good idea. Try `__main__.py install --user` instead.
Collecting aiohttp
? Downloading http://stockmirrors.paic.com.cn/pypi/web/packages/7c/39/7eb5f98d24904e0f6d3edb505d4aa60e3ef83c0a58d6fe18244a51757247/aiohttp-3.6.2-cp36-cp36m-manylinux1_x86_64.whl (1.2MB)
? ? 100% |████████████████████████████████| 1.2MB 3.4MB/s
Requirement already satisfied: chardet<4.0,>=2.0 in /usr/local/lib/python3.6/site-packages (from aiohttp)
Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.6/site-packages (from aiohttp)
Requirement already satisfied: typing-extensions>=3.6.5; python_version < "3.7" in /usr/local/lib/python3.6/site-packages (from aiohttp)
Requirement already satisfied: idna-ssl>=1.0; python_version < "3.7" in /usr/local/lib/python3.6/site-packages (from aiohttp)
Requirement already satisfied: async-timeout<4.0,>=3.0 in /usr/local/lib/python3.6/site-packages (from aiohttp)
Collecting multidict<5.0,>=4.5 (from aiohttp)
? Downloading http://stockmirrors.paic.com.cn/pypi/web/packages/1a/95/f50352b5366e7d579e8b99631680a9e32e1b22adfa1629a8f23b1d22d5e2/multidict-4.7.6-cp36-cp36m-manylinux1_x86_64.whl (148kB)
? ? 100% |████████████████████████████████| 153kB 2.0MB/s
Collecting yarl<2.0,>=1.0 (from aiohttp)
? Downloading http://stockmirrors.paic.com.cn/pypi/web/packages/a0/b4/2cbeaf2c3ea53865d9613b315fe24e78c66acedb1df7e4be4e064c87203b/yarl-1.5.1-cp36-cp36m-manylinux1_x86_64.whl (257kB)
? ? 100% |████████████████████████████████| 266kB 1.8MB/s
Requirement already satisfied: idna>=2.0 in /usr/local/lib/python3.6/site-packages (from idna-ssl>=1.0; python_version < "3.7"->aiohttp)
Installing collected packages: multidict, yarl, aiohttp
Successfully installed aiohttp-3.6.2 multidict-4.7.6 yarl-1.5.1
```
## 7 其他軟工具
以下軟件非必須呻惕, 建議安裝
+ tree - list directroies and files
+ mlocate - locate files
+ lrzsz - send / recived tool
+ telnent - check port
+ htop - advanced top
+ sqlcmd - sql connect tool
+ tcpdump
## 7 配置odbc
### 7.1 查看 odbc 配置
用 __`odbcinst -j`__ 查看配置
```
[rishon@stsz141654 ~]$ odbcinst -j
unixODBC 2.3.7
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /home/rishon/.odbc.ini
```
### 7.2 配置 odbc 驅(qū)動
__odbcinst.ini__
```
[rishon@stsz141654 ~]$ cat /usr/local/etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.6.so.1.1
UsageCount=3
```
### 7.3 配置 odbc 數(shù)據(jù)源
__.odbc.ini__
```
[rishon@stsz141654 ~]$ cat /home/rishon/.odbc.ini
[counter]
Desciption = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.172.110
Port = 1433
Database = oiw_45499
[exchange]
Description = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.172.110
Port = 1433
Database = oiw_38971
[counter_cts]
Desciption = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.172.110
Port = 1433
Database = oiw_45488
[exchange_cts]
Description = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.248.20
Port = 1433
Database = oiw_38970
[uat_counter]
Desciption = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.236.34
Port = 1433
Database = oiw_46360
[uat_exchange]
Description = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.224.43
Port = 1433
Database = oiw_46360
[uat_counter_cts]
Desciption = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.236.34
Port = 1433
Database = oiw_41813
[uat_exchange_cts]
Description = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.232.157
Port = 1433
Database = oiw_41813
```
### 7.4 驗(yàn)證 odbc 數(shù)據(jù)源
```
[rishon@stsz141654 ~]$ isql -v counter sa Paic1234
+---------------------------------------+
| Connected!? ? ? ? ? ? ? ? ? ? ? ? ? ? |
|? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
| sql-statement? ? ? ? ? ? ? ? ? ? ? ? |
| help [tablename]? ? ? ? ? ? ? ? ? ? ? |
| quit? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
|? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
+---------------------------------------+
SQL>
```
## 8 risk_controller
風(fēng)控系統(tǒng)的目錄結(jié)構(gòu)如下
```
[rishon@stsz141654 mom]$ tree
.
├── query
│?? └── query_data
│??? ? ├── bin
│??? ? │?? └── query_data_v0.1.1_2020_09_27
│??? ? ├── data
│??? ? │?? ├── codes.txt
│??? ? │?? ├── cts-codes.txt
│??? ? │?? ├── sh
│??? ? │?? │?? ├── asset.txt
│??? ? │?? │?? ├── stk_info.txt
│??? ? │?? │?? └── order.txt
│??? ? │?? └── sz
│??? ? │??? ?? ├── asset.txt
│??? ? │??? ?? ├── stk_info.txt
│??? ? │??? ?? └── order.txt
│??? ? └── query_data -> bin/query_data_v0.1.1_2020_09_27
└── soft
? ? ├── sh_risk_controller
? ? │?? ├── bin
? ? │?? │?? └── sh_risk_controller_v1.1.1_2020_09_27
? ? │?? ├── conf
? ? │?? │?? └── configs.json
? ? │?? ├── configs.json -> conf/configs.json
? ? │?? ├── data
? ? │?? │?? ├── account.txt
? ? │?? │?? ├── asset.txt
? ? │?? │?? ├── order.txt
? ? │?? │?? └── stk_info.txt
? ? │?? └── sh_risk_controller -> bin/sh_risk_controller_v1.1.1_2020_09_27
? ? └── sz_risk_controller
? ? ? ? ├── bin
? ? ? ? │?? └── sz_risk_controller_v1.1.2_2020_09_27
? ? ? ? ├── binary_key
? ? ? ? │?? ├── 100101.key.txt
? ? ? ? │?? ├── 190007.key.txt
? ? ? ? │?? ├── 1.key.txt
? ? ? ? │?? ├── 200102.key.txt
? ? ? ? │?? ├── 200115.key.txt
? ? ? ? │?? ├── 290008.key.txt
? ? ? ? │?? ├── 2.key.txt
? ? ? ? │?? └── 6.key.txt
? ? ? ? ├── conf
? ? ? ? │?? └── config.json
? ? ? ? ├── config.json -> conf/config.json
? ? ? ? ├── data
? ? ? ? │?? ├── account.txt
? ? ? ? │?? ├── asset.txt
? ? ? ? │?? ├── order.txt
? ? ? ? │?? └── stk_info.txt
? ? ? ? └── sz_risk_controller -> bin/sz_risk_controller_v1.1.2_2020_09_27
```
## 9 上賬系統(tǒng)
目錄結(jié)構(gòu)為
```
[rishon@stsz141654 query_data]$ tree
.
├── bin
│?? └── query_data_vX.X.X_YYYY_MM_DD
├── data
│?? ├── codes.txt
│?? ├── cts-codes.txt
│?? ├── sh
│?? │?? ├── asset.txt
│?? │?? ├── stk_info.txt
│?? │?? └── order.txt
│?? └── sz
│??? ?? ├── asset.txt
│?? ? ? ├── stk_info.txt
│?? ? ? └── order.txt
├── async_get_secu_info.py
└── query_data -> bin/query_data_vX.X.X_YYYY_MM_DD
```
上賬系統(tǒng)分三大部分:
1. 股票列表信息():每天 __開市前拉取__ ,且當(dāng)天只會在開市時 __拉取一次__饰躲。
2. 股票持倉(query_data): __盤中啟動拉取__牙咏。
3. 未成交訂單(query_data): __盤中啟動拉取__。
上述 __1__ 部分提供了一個向行情API查詢的腳本嘹裂。
上述 __2__, __3__ 部分需要提供 __客戶ID__ 列表的文件作為輸入妄壶。
### 9.1 獲取股票列表信息
__`async_get_secu_info.py`__ 為一個并發(fā)的http請求腳本,向客戶指定的api查詢當(dāng)日股票的漲跌停價(jià)寄狼,交易量等信息丁寄,輸出到文件中,供風(fēng)控系統(tǒng)使用泊愧。
其幫助信息如下伊磺。
```
[root@redhat query_data]# python3 async_get_secu_info.py -h
usage: async_get_secu_info.py [-h] [--sz_output SZ_OUTPUT]
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [--sh_output SH_OUTPUT]
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? URL_HQ
positional arguments:
? URL_HQ? ? ? ? ? ? ? ? example:
? ? ? ? ? ? ? ? ? ? ? ? http://30.76.147.73:30078/JHQGateway/hq/request
optional arguments:
? -h, --help? ? ? ? ? ? show this help message and exit
? --sz_output SZ_OUTPUT
? ? ? ? ? ? ? ? ? ? ? ? output file path of stock list in SZ market, default:
? ? ? ? ? ? ? ? ? ? ? ? ./data/sz/stk_info.txt
? --sh_output SH_OUTPUT
? ? ? ? ? ? ? ? ? ? ? ? output file path of stock list in SH market, default:
? ? ? ? ? ? ? ? ? ? ? ? ./data/sh/stk_info.txt
```
一般不需要修改輸出的文件路徑。
必須要輸入行情API的地址拼卵,示例:
```
[root@redhat query_data]# python3 async_get_secu_info.py http://30.76.147.73:30078/JHQGateway/hq/request
2020-09-15 17:36:42,573 async_get_secu_info.py [line:180] INFO start all stock query
2020-09-15 17:36:42,573 async_get_secu_info.py [line:189] INFO request code_list start with index 0
2020-09-15 17:36:42,685 async_get_secu_info.py [line:106] INFO request success : http://30.76.147.73:30078/JHQGateway/hq/request/56004, {'listRange': '0', 'attrMark':'0', 'orderField': '0', 'sort': '0', 'local': 0, 'reqSize': '5000'}
...
2020-09-30 15:44:08,482 async_get_secu_info.py [line:206] INFO finish all stock query
2020-09-30 15:44:08,482 async_get_secu_info.py [line:208] INFO start write output to file
2020-09-30 15:44:08,499 async_get_secu_info.py [line:221] INFO finish writing file
2020-09-30 15:44:08,501 async_get_secu_info.py [line:227] INFO exit
```
### 9.2 持倉和未成交訂單查詢
持倉和未成交訂單查詢?yōu)楸P中啟動的時候執(zhí)行奢浑。即盤中啟動的時候先執(zhí)行持倉和訂單查詢后,再執(zhí)行相應(yīng)的風(fēng)控程序腋腮。
>bin 目錄下有歷史版本的二進(jìn)制可執(zhí)行程序。然后在項(xiàng)目目錄下有一個 __`query_data`__ 的軟連接指向該 __`bin/query_data_vX.X.X_YYYY_MM_DD`__ 的二進(jìn)制文件壤蚜。以便升級有問題時即寡,__回退__ 到上一個穩(wěn)定的 __歷史版本__。
主要參數(shù)及其詳情:
```
[rishon@stsz141654 query_data]$ ./query_data --help
usage: ./query_data [options] ...
options:
? -h, --host? ? ? ? ? ? host name (string [=10.25.229.151])
? -p, --port? ? ? ? ? ? port number (int [=9200])
? -c, --codes? ? ? ? ? user codes file (string [=./data/codes.txt])
? -x, --cts_host? ? ? ? host name (string [=10.25.163.162])
? -y, --cts_port? ? ? ? cts port number (int [=9100])
? -z, --cts_codes? ? ? cts user codes file (string [=./data/cts-codes.txt])
? -d, --szasset? ? ? ? sz asset file (string [=./data/sz/asset.txt])
? -e, --shasset? ? ? ? sh asset file (string [=./data/sh/asset.txt])
? -f, --szorder? ? ? ? sz uncomplete order file (string [=./data/sz/order.txt])
? -j, --shorder? ? ? ? sh uncomplete order file (string [=./data/sh/order.txt])
? -k, --szstk? ? ? ? ? user codes file (string [=./data/sz/stk_info.txt])
? -l, --shstk? ? ? ? ? user codes file (string [=./data/sh/stk_info.txt])
? -g, --logger_level? ? debug:1, info:2, warn:3, error:4, critical:5, off:6 (int [=2])
? -u, --market_num? ? ? 1-sz, 2-sh? (int [=3])
? -?, --help? ? ? ? ? ? print this message
[rishon@stsz141654 query_data]$ ./query_data -?
usage: ./query_data [options] ...
options:
? -h, --host? ? ? ? ? ? host name (string [=10.25.229.151])
? -p, --port? ? ? ? ? ? port number (int [=9200])
? -c, --codes? ? ? ? ? user codes file (string [=./data/codes.txt])
? -x, --cts_host? ? ? ? host name (string [=10.25.163.162])
? -y, --cts_port? ? ? ? cts port number (int [=9100])
? -z, --cts_codes? ? ? cts user codes file (string [=./data/cts-codes.txt])
? -d, --szasset? ? ? ? sz asset file (string [=./data/sz/asset.txt])
? -e, --shasset? ? ? ? sh asset file (string [=./data/sh/asset.txt])
? -f, --szorder? ? ? ? sz uncomplete order file (string [=./data/sz/order.txt])
? -j, --shorder? ? ? ? sh uncomplete order file (string [=./data/sh/order.txt])
? -k, --szstk? ? ? ? ? user codes file (string [=./data/sz/stk_info.txt])
? -l, --shstk? ? ? ? ? user codes file (string [=./data/sh/stk_info.txt])
? -g, --logger_level? ? debug:1, info:2, warn:3, error:4, critical:5, off:6 (int [=2])
? -u, --market_num? ? ? 1-sz, 2-sh? (int [=3])
? -?, --help? ? ? ? ? ? print this message
```
name|full name|short name|default value| description
----|---------|----------|-------------|-------------
極速IP地址|--host|-h|10.25.229.151|極速接口的IP地址袜刷,缺省值是 __10.25.229.151__聪富,可在啟動時命令行傳入所需要的值
極速端口|--port|-p|9200|極速接口的端口,缺省值是 __9200__著蟹,可在啟動時命令行傳入所需要的值
極速的客戶ID|--codes|-c|./data/codes.txt|極速客戶代碼列表文件路徑墩蔓,可在啟動時命令行傳入所需要的值。文件格式是一個客戶代碼占一行
集中IP地址|--cts_host|-x|10.25.163.162|集中接口的IP地址萧豆,缺省值是 __10.25.163.162__奸披,可在啟動時命令行傳入所需要的值
集中端口|--cts_port|-y|9100|集中接口的端口,缺省值是 __9100__涮雷,可在啟動時命令行傳入所需要的值
集中的客戶ID|--cts_codes|-z|9200|集中客戶代碼列表文件路徑阵面,可在啟動時命令行傳入所需要的值。文件格式是 __一個客戶代碼占一行__
深交所持倉|--szasset|-d|./data/sz/asset.txt|深交所持倉文件的路徑,建議在該路徑下 __touch該文件__. 接口會把查詢出來的結(jié)果集寫入到該文件
上交所持倉|--shasset|-e|./data/sh/asset.txt|上交所持倉文件的路徑样刷,建議在該路徑下 __touch該文件__. 接口會把查詢出來的結(jié)果集寫入到該文件
深交所未成交訂單|--szorder|-f|./data/sz/order.txt|深交所未成交訂單文件的路徑仑扑,建議在該路徑下 __touch該文件__. 接口會把查詢出來的結(jié)果集寫入到該文件
上交所未成交訂單|--shorder|-j|./data/sh/order.txt|上交所未成交訂單文件的路徑,建議在該路徑下 __touch該文件__. 接口會把查詢出來的結(jié)果集寫入到該文件
深交所股票信息|--szstk|-k|./data/sz/stk_info.txt|深交所股票信息文件的路徑置鼻,該路徑為 __股票信息查詢的列表清單__, 為 __輸入文件__
上交所未成交訂單|--shstk|-l|./data/sh/stk_info.txt|上交所股票信息文件的路徑镇饮,該路徑為 __股票信息查詢的列表清單__, 為 __輸入文件__ 接口會把查詢出來的結(jié)果集寫入到該文件
日志文件等級|--logger_level|-g|info|debug:1, info:2, warn:3, error:4, critical:5, off:6
證券市場|--market_num|-u|3|1-sz, 2-sh, 缺省為3箕母,拉取上交所和深交所所有的持倉和未成交訂單
## 10 深交所風(fēng)控
深交所目前是tcp流式協(xié)議:step協(xié)議(集中)和binary協(xié)議(極速)
### 10.1 目錄結(jié)構(gòu)
深交所有step(集中)和binary(極速)兩協(xié)議盒让。目錄結(jié)構(gòu)為:
```
[rishon@stsz141654 sz_risk_controller]$ tree
.
├── bin
│?? └── sz_risk_controller_vX.X.X_YYYY_MM_DD
├── binary_key
│?? ├── 100101.key.txt
│?? ├── 190007.key.txt
│?? ├── 1.key.txt
│?? ├── 200102.key.txt
│?? ├── 200115.key.txt
│?? ├── 290008.key.txt
│?? ├── 2.key.txt
│?? └── 6.key.txt
├── conf
│?? └── config.json
├── config.json -> conf/config.json
├── data
│?? ├── account.txt
│?? ├── asset.txt
│?? ├── order.txt
│?? └── stk_info.txt
└── sz_risk_controller -> bin/sz_risk_controller_vX.X.X_YYYY_MM_DD
```
> bin 目錄下有所有歷史版本的二進(jìn)制可執(zhí)行程序。在項(xiàng)目的主目錄下還有一個 __`sz_risk_controller`__ 的軟連接指向最新的 __` bin/sz_risk_controller_vX.X.X_YYYY_MM_DD`__ 的二進(jìn)制文件司蔬。軟連接另外一個作用是邑茄,當(dāng)升級失敗或者新版本有問題時,以便通過修改軟連接的方式 __回退__ 到上一個穩(wěn)定的 __歷史版本__. 同理俊啼,__`config.json`__ 也有軟連接肺缕,作用類似。
> binary_key 目錄下有 binary 協(xié)議所定義的一些key-value的鍵值對授帕,其中__100101__ 為新訂單同木,__200102__ 和 __200115__ 為執(zhí)行報(bào)告。
### 10.2 config.json 詳情
```
[rishon@stsz141654 sz_risk_controller]$ cat config.json
{
"task_ctrls_flag":0,
"binary": {
"tgw_host": "10.25.151.121",
"tgw_port": 17922,
"svr_port": 30000
},
"step":{
"tgw_host": "10.25.151.122",
"tgw_port": 8109,
"svr_port": 31000
},
"data_path": {
"funds_file":? ? ? "./data/account.txt",
"holding_file":? ? "./data/asset.txt",
"stk_info_file":? ? "./data/stk_info.txt",
"order_file":? ? "./data/order.txt"
},
"risk_limit":{
"float_shr_pct": 0.3,
"total_shr_pct": 0.03,
"nday_vol_pct": 0.3
},
"logger_level":{
"soft_level":"2",
"order_level":"1",
"error_level":"1"
}
}
```
+ task_ctrls_flag: 是否開啟風(fēng)控跛十。此參數(shù)缺省為0彤路,風(fēng)控啟動時忽略該參數(shù)的值。但風(fēng)控啟動后芥映,可以通過 __`kill -1 PID`__ 關(guān)閉風(fēng)控洲尊。注意,__關(guān)閉風(fēng)控后當(dāng)天不可再次開啟風(fēng)控__ 奈偏。
+ binary/step: 由tgw的ip地址(tgw_host/)及其端口(tgw_port)坞嘀,和自身開放的端口接收柜臺請求(svr_port)三部分組成.
+ data_path: 由股東代碼(funds_file),股票持倉(holding_file)惊来,股票信息(stk_info_file) 和未成交訂單(order_file) 四部分組成丽涩。
+ risk_limit: 集中度等參數(shù)配置。皆為交易所缺省值裁蚁。
+ logger_level:有軟件日常運(yùn)行日志(soft_level), 訂單日志(order_level)矢渊,和錯誤異常日志(error_level)三部分日志級別控制。
> risk_limit 請不要修改配置枉证,因皆為交易所缺省值矮男。目前該版本還沒有實(shí)現(xiàn),為后續(xù)的集中度等所預(yù)留刽严。
> 各類日志可以在運(yùn)行中昂灵,如果想提升或者降低日志級別請先修改想要的日志級別避凝,然后執(zhí)行 __`kill -1 PID`__ 即可。
> 如果想盤中查看未成交訂單眨补,請執(zhí)行 __`kill -2 PID`__管削。 會在深交所主目錄下生成一個 orders.txt 軟連接。該動作請勿頻繁執(zhí)行撑螺,尤其是業(yè)務(wù)繁忙的時候含思。
### 10.3 日志級別詳情
目前日志級別有:
1. 調(diào)試日志:1 - debug
2. 一般日志:2 - info
3. 警告日志:3 - warn
4. 錯誤日志:4 - error
5. 致命日志:5 - critical
6. 關(guān)閉所有日志:6 - off
六部分組成。優(yōu)先級是開啟當(dāng)前日志級別后甘晤,比當(dāng)前日志級別大的日志都會輸出含潘。比如,開啟 info 日志线婚,會輸出的日志級別有 info遏弱,warn,error塞弊,critical漱逸;但比 info 低的 debug 日志級別不會輸出。所有日志都為異步方式游沿。
> 如果錯誤日志開啟了debug日志饰抒,風(fēng)控系統(tǒng)會按 __`tcpdump -A`__ 的形式打印tcp的十六進(jìn)制的文本數(shù)據(jù)流,請慎重適當(dāng)開啟日志打印诀黍,盡管日志是異步方式打印袋坑。
### 10.4 深交所風(fēng)控系統(tǒng)運(yùn)行
線上不建議手動直接運(yùn)行系統(tǒng)。如果要在命令行手動執(zhí)行風(fēng)控眯勾,請以 __后臺__ 的形式執(zhí)行
```
./sz_risk_controller config.json
```
### 10.5 啟動后狀態(tài)檢查
風(fēng)控系統(tǒng)啟動后枣宫,可以查看風(fēng)控系統(tǒng)主目錄下的:
1. __`error.log`__:錯誤日志和tcp包流日志。
2. __`daily.log`__:系統(tǒng)運(yùn)行的常規(guī)日志咒精。
3. __`monitor.log`__:系統(tǒng)監(jiān)控日志镶柱,主要有各個柜臺運(yùn)行次數(shù),訂單處理次數(shù)等詳情數(shù)據(jù)的輸出模叙。
4. __`order.log`__:新訂單詳情日志,和執(zhí)行報(bào)告返回時的詳情
各個文件輸出的情況鞋屈。也可以直接命令行執(zhí)行
```
[rishon@stsz141654 ~]$ ps -ef |grep sh_risk_controller
```
或者在命令行直接進(jìn)行
```
[rishon@stsz141654 ~]$ netstatus -anplt |grep sz_
```
## 11 上交所風(fēng)控
上交所目前是接口庫的形式范咨,通過掃表的方式實(shí)現(xiàn)。目前厂庇,上交所風(fēng)控系統(tǒng)支持多個接口庫的鏈接渠啊。
### 11.1 目錄結(jié)構(gòu)
```
[rishon@stsz141654 sh_risk_controller]$ tree
.
├── bin
│?? └── sh_risk_controller_vX.X.X_YYYY_MM_DD
├── conf
│?? └── configs.json
├── configs.json -> conf/configs.json
├── data
│?? ├── account.txt
│?? ├── asset.txt
│?? ├── order.txt
│?? └── stk_info.txt
└── sh_risk_controller -> bin/sh_risk_controller_vX.X.X_YYYY_MM_DD
```
> bin 目錄下有所有歷史版本的二進(jìn)制可執(zhí)行程序。在項(xiàng)目的主目錄下還有一個 __`sh_risk_controller`__ 的軟連接指向最新的 __` bin/sh_risk_controller_vX.X.X_YYYY_MM_DD`__ 的二進(jìn)制文件权旷。軟連接另外一個作用是替蛉,當(dāng)升級失敗或者新版本有問題時,以便通過修改軟連接的方式 __回退__ 到上一個穩(wěn)定的 __歷史版本__. 同理,__`configs.json`__ 也有軟連接躲查,作用類似它浅。
### 11.2 configs.json 詳情
```
[rishon@stsz141654 sh_risk_controller]$ cat configs.json
{
"task_ctrls_flag":0,
"logger_level":
{
"soft_level":"1",
"order_level":"1",
"error_level":"1"
},
"data":[
{
"dsn_counter": {
"database": "uat_counter",
"user": "oiw",
"password": "oiw123",
"seatId":"46360"
},
"dsn_exchange": {
"database": "uat_exchange",
"user": "oiw",
"password": "oiw2005",
"seatId":"46360"
}
},
{
"dsn_counter": {
"database": "uat_counter_cts",
"user": "oiw",
"password": "oiw123",
"seatId":"41813"
},
"dsn_exchange": {
"database": "uat_exchange_cts",
"user": "oiw",
"password": "oiw2005",
"seatId":"41813"
}
}
],
"data_path": {
"file_account":? "./data/account.txt",
"file_asset":? ? "./data/asset.txt",
"file_stk_info": "./data/stk_info.txt",
"file_order": "./data/order.txt"
}
}
```
+ task_ctrls_flag: 是否開啟風(fēng)控。此參數(shù)缺省為0镣煮,風(fēng)控啟動時忽略該參數(shù)的值姐霍。但風(fēng)控啟動后,可以通過 __`kill -1 PID`__ 關(guān)閉風(fēng)控典唇。關(guān)閉風(fēng)控后镊折,系統(tǒng)為透傳〗橄危可以理解為柜臺直連了交易所恨胚。上交所風(fēng)控系統(tǒng)支持系統(tǒng)運(yùn)行時多次開啟或者關(guān)閉風(fēng)控功能。
+ logger_level:有軟件日常運(yùn)行日志(soft_level), 訂單日志(order_level)炎咖,和錯誤異常日志(error_level)三部分日志級別控制
+ data 組別是接口庫的配置赃泡。其中 __`dsn_counter`__ 為 __`柜臺接口庫`__ , __`dsn_exchange`__ 為 __`交易所接口庫`___。
+ database: 為接口庫的dsn的接口庫的配置塘装,主要是接口庫的ip急迂,端口信息。詳情見 __`11.5 dsn配置詳情`__ 章節(jié)蹦肴。
+ seatId 席位號僚碎,目前席位號是追繳到表名后面的。如果席位號為空阴幌,則代表表名無后綴勺阐。
+ data_path: 由股東代碼(funds_file),股票持倉(holding_file)矛双,股票信息(stk_info_file) 和未成交訂單(order_file) 四部分組成渊抽。
### 11.3 日志級別詳情
目前日志級別有:
1. 調(diào)試日志:1 - debug
2. 一般日志:2 - info
3. 警告日志:3 - warn
4. 錯誤日志:4 - error
5. 致命日志:5 - critical
6. 關(guān)閉所有日志:6 - off
六部分組成。優(yōu)先級是開啟當(dāng)前日志級別后议忽,比當(dāng)前日志級別大的日志都會輸出懒闷。比如,開啟 info 日志栈幸,會輸出的日志級別有 info愤估,warn,error速址,critical玩焰;但比 info 低的 debug 日志級別不會輸出。所有日志都為異步方式芍锚。
### 11.4 表結(jié)構(gòu)詳情
__申報(bào)表(ordwth)__
```
CREATE TABLE dbo.ordwth_[seatId]
(
rec_num? INT NOT NULL,
[date]? CHAR (8),
[time]? CHAR (8),
reff? ? CHAR (10),
acc? ? ? CHAR (10),
stock? ? CHAR (6),
bs? ? ? CHAR (1),
price? ? CHAR (8),
qty? ? ? CHAR (8),
status? CHAR (1),
owflag? CHAR (3),
ordrec? CHAR (8),
firmid? CHAR (5),
branchid CHAR (5),
checkord BINARY (16),
CONSTRAINT PK_ordwth_[seatId] PRIMARY KEY (rec_num)
)
```
__確認(rèn)表(ordwth2)__
```
CREATE TABLE dbo.ordwth2_[seatId]
(
rec_num? ? INT NOT NULL,
[date]? ? CHAR (8),
[time]? ? CHAR (8),
reff? ? ? CHAR (10),
acc? ? ? ? CHAR (10),
stock? ? ? CHAR (6),
bs? ? ? ? CHAR (1),
price? ? ? CHAR (8),
qty? ? ? ? CHAR (8),
status? ? CHAR (1),
qty2? ? ? CHAR (8),
remark? ? CHAR (30),
status1? ? CHAR (1),
teordernum CHAR (8),
owflag? ? CHAR (3),
ordrec? ? CHAR (8),
firmid? ? CHAR (5),
branchid? CHAR (5),
checkord? BINARY (16),
rec_num2? INT IDENTITY NOT NULL,
CONSTRAINT PK_ordwth2_[seatId] PRIMARY KEY (rec_num2)
)
CREATE UNIQUE INDEX ordwth2_[seatId]_uidx
ON dbo.ordwth2_[seatId] (rec_num)
```
__成交回報(bào)表(cjbh)__
```
CREATE TABLE dbo.cjhb_[seatId]
(
rec_num INT IDENTITY NOT NULL,
gddm? ? CHAR (10),
gdxm? ? CHAR (8),
bcrq? ? CHAR (8),
cjbh? ? INT NOT NULL,
gsdm? ? CHAR (5),
cjsl? ? CHAR (10),
bcye? ? CHAR (10),
zqdm? ? CHAR (6) NOT NULL,
sbsj? ? CHAR (6),
cjsj? ? CHAR (6),
cjjg? ? CHAR (8),
cjje? ? CHAR (12),
sqbh? ? CHAR (10),
bs? ? ? CHAR (1) NOT NULL,
mjbh? ? CHAR (5),
CONSTRAINT PK_cjhb_[seatId] PRIMARY KEY (rec_num)
)
```
> 如果沒有配置席位號昔园,那么相應(yīng)的表名為:__ordwth蔓榄, ordwth2, cjbh__默刚。
### 11.5 dsn 部署詳情
dsn 部署詳情可參閱 __`7.1 查看 odbc 配置`__ , __`7.2 配置 odbc 驅(qū)動`__ 和 __`7.3 配置 odbc 數(shù)據(jù)源`__, 此處再做進(jìn)一步詳情甥郑。
#### 11.5.1 查看 odbc 配置
用 __`odbcinst -j`__ 查看配置
```
[rishon@stsz141654 ~]$ odbcinst -j
unixODBC 2.3.7
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /home/rishon/.odbc.ini
```
+ unixODBC 2.3.7: unixODBC版本信息
+ DRIVERS:unixODBC驅(qū)動配置信息,為整個系統(tǒng)所有用戶共享羡棵,一經(jīng)配置壹若,一般無需修改。此處主要是 __`libmsodbcsql`__ 庫路徑
+ SYSTEM DATA SOURCES:unixODBC 系統(tǒng)數(shù)據(jù)配置信息皂冰,為整個系統(tǒng)所有用戶共享店展,一經(jīng)配置,一般無需修改秃流。此處若是配置了數(shù)據(jù)源赂蕴,為整個系統(tǒng)用戶可見。缺省為空舶胀,無配置信息概说。
+ FILE DATA SOURCES:unixODBC文件配置信息目錄,為整個系統(tǒng)所有用戶共享嚣伐,一經(jīng)配置糖赔,一般無需修改。確實(shí)是空美麗轩端。
+ USER DATA SOURCES:unixODBC當(dāng)前用戶的 __`dsn`__ 配置信息放典,為當(dāng)前用戶所有,此處配置當(dāng)前用戶的數(shù)據(jù)源基茵。該文件一般為當(dāng)前用戶主目錄奋构,文件名為:__`.odbc.ini`__ 。
#### 11.5.2 配置 odbc 驅(qū)動
文件 __`odbcinst.ini`__ 為系統(tǒng)所有拱层,一般無需修改弥臼。以下為一個樣板:
```
[rishon@stsz141654 ~]$ cat /usr/local/etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.6.so.1.1
UsageCount=3
```
其中的 __`Driver`__ 為 __mssql__ 庫文件路徑。
### 11.5.3 配置 odbc 數(shù)據(jù)源
文件 __`.odbc.ini`__ 為當(dāng)前用戶的 __`dsn`__ 數(shù)據(jù)源配置根灯。以下為為一個樣本:
```
[rishon@stsz141654 ~]$ cat /home/rishon/.odbc.ini
[counter]
Desciption = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.172.110
Port = 1433
Database = oiw_45499
[exchange]
Description = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.172.110
Port = 1433
Database = oiw_38971
[counter_cts]
Desciption = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.172.110
Port = 1433
Database = oiw_45488
[exchange_cts]
Description = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.248.20
Port = 1433
Database = oiw_38970
[uat_counter]
Desciption = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.236.34
Port = 1433
Database = oiw_46360
[uat_exchange]
Description = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.224.43
Port = 1433
Database = oiw_46360
[uat_counter_cts]
Desciption = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.236.34
Port = 1433
Database = oiw_41813
[uat_exchange_cts]
Description = mssql server
Driver = ODBC Driver 17 for SQL Server
Server = 10.25.232.157
Port = 1433
Database = oiw_41813
```
其中:
1. __`[uat_exchange_cts]`__ 即為上交所風(fēng)控的 __`config.json|data|dsn__xxx|database`__ 的值径缅。此處的 __`Database`__ 為庫名。
2. __`Server`__ 為接口庫的 IP烙肺。
3. __`Port`__ 為接口庫的端口 port 芥驳。
4. __`Database`__ 為接口庫的數(shù)據(jù)庫名。
> 請注意每組名字茬高,如 __`uat_exchange_cts`__ 的惟一性。
### 11.6 上交所風(fēng)控系統(tǒng)運(yùn)行
線上不建議手動直接運(yùn)行系統(tǒng)假抄。如果要在命令行手動執(zhí)行風(fēng)控怎栽,請以 __后臺__ 的形式執(zhí)行
```
./sh_risk_controller configs.json
```
### 11.7 啟動后狀態(tài)檢查
風(fēng)控系統(tǒng)啟動后丽猬,可以查看風(fēng)控系統(tǒng)主目錄下的:
1. __`error.log`__:錯誤日志。
2. __`daily.log`__:系統(tǒng)運(yùn)行的常規(guī)日志熏瞄。
3. __`monitor.log`__:系統(tǒng)監(jiān)控日志脚祟,主要有各個柜臺運(yùn)行次數(shù),訂單處理次數(shù)等詳情數(shù)據(jù)的輸出强饮。
4. __`order.log`__:新訂單詳情日志由桌,和執(zhí)行報(bào)告返回時的詳情
各個文件輸出的情況。也可以直接命令行執(zhí)行
```
[rishon@stsz141654 ~]$ ps -ef |grep sh_risk_controller
```