package.json配置信息

1. 简介

kfs 构建功夫插件的时候, 需要根据 package.json 文件提供的描述信息来进行构建, 我们要求每一个插件的开发目录根目录都存在一个package.json文件

2. package.json 范例

 1    {
 2        "name": "@kungfu-trader/examples-strategy-python",
 3        "description": "KungFu Strategy 101 - Python Demo",
 4        "license": "Apache-2.0",
 5        "kungfuBuild": {
 6            "python": {
 7                "dependencies": {}
 8            }
 9        },
10        "kungfuConfig": {
11            "key": "KungfuStrategy101Python"
12        }
13    }

3. 字段说明

name

  • 插件仓库的名字(任意自定义字符)

description

插件的描述信息, 在功夫插件模块内会将此字段读取

kungfuBuild

为 cpp, python 插件打包指定依赖以及版本

1    "kungfuBuild": {
2        "python": {
3            "dependencies": {
4                "dotted_dict": "~=1.1.0",
5                "recordclass": "~=0.18.0",
6                "sortedcontainers": "~=2.4.0"
7            }
8        }
9    }

kungfuConfig

主要配置项, 针对strategy(策略/算法), td(交易柜台), md(行情柜台)分场景配置

 1    "kungfuConfig": {
 2        "key": "ConditionOrder",
 3        "name": "条件单",
 4        "ui_config": {
 5            "position": "make_order"
 6        },
 7        "config": {
 8            "strategy": {
 9                "type": "trade",
10                "settings": [
11                    {
12                        "key": "priceCondition",
13                        "name": "priceCondition",
14                        "type": "table",
15                        "columns": [
16                            {
17                                "key": "currentPrice",
18                                "name": "currentPrice",
19                                "type": "select",
20                                "options": [
21                                    {
22                                        "label": "currentPrice_0",
23                                        "value": "0"
24                                    },
25                                    {
26                                        "label": "currentPrice_1",
27                                        "value": "1"
28                                    },
29                                    {
30                                        "label": "currentPrice_2",
31                                        "value": "2"
32                                    }
33                                ]
34                            },
35                        ],
36                    }
37                ]
38            }
39        }
40    }

key:

key: 唯一key, 例如功夫app中存在十个插件, 这十个插件的key不能重复, 且对于柜台与交易任务,该key与目录结构存在对应关系

name:

name: 插件名称,会在功夫插件列表与对应入口进行展示

config说明:

config: 插件表单主要配置项(插件表单是指通过功夫app或者cli添加柜台/算法时所需填写的配置表单), 下级对应 strategy, md, td 三个选择,分别对应算法插件,行情接口插件,与交易柜台插件
不同插件配置下级说明
对于算法插件

config 下级为 strategy

"config": {
    "strategy": {

    }
}

举例说明 :

 1    "config": {
 2        "strategy": {
 3            "type": "trade",
 4            "settings": [
 5                {
 6                    "key": "accountId",
 7                    "name": "twap.accountId",
 8                    "type": "td",
 9                    "required": true,
10                    "primary": true
11                }
12            ]
13        }
14    }
对于 行情/交易插件

一般柜台接口同时提供行情交易接口,开发者可在config下同时配置行情交易(td),(md)配置项

"config": {

    "td": {

    },

    "md": {

    }
}

举例说明 :

 1    "config": {
 2        "td": {
 3            "type": [ "stock" ],
 4            "settings": [
 5                {
 6                    "key": "account_name",
 7                    "name": "account_name",
 8                    "type": "str",
 9                    "tip": "account_name_tip"
10                },
11                {
12                    "key": "account_id",
13                    "name": "account_id",
14                    "type": "str",
15                    "required": true,
16                    "primary": true,
17                    "tip": "account_id_tip"
18                },
19                {
20                    "key": "password",
21                    "name": "password",
22                    "type": "password",
23                    "required": true,
24                    "tip": "password_tip"
25                },
26                {
27                    "key": "td_port",
28                    "name": "td_port",
29                    "type": "int",
30                    "required": true,
31                    "tip": "td_port_tip"
32                },
33            ]
34        },
35        "md": {
36            "type": [ "stock" ],
37            "settings": [
38                {
39                    "key": "account_id",
40                    "name": "account_id",
41                    "type": "str",
42                    "required": true,
43                    "tip": "account_id_tip",
44                    "default": "15011218"
45                },
46                {
47                    "key": "password",
48                    "name": "password",
49                    "type": "password",
50                    "required": true,
51                    "tip": "password_tip",
52                },
53                {
54                    "key": "md_ip",
55                    "name": "md_ip",
56                    "type": "str",
57                    "required": true,
58                    "tip": "md_ip_tip",
59                    "default": "119.3.103.38"
60                },
61                {
62                    "key": "md_port",
63                    "name": "md_port",
64                    "type": "int",
65                    "required": true,
66                    "tip": "md_port_tip",
67                    "default": 6002
68                },
69            ]
70        }
71    }
type说明:

type: 对于柜台有效,标记柜台支持的交易类型,可选项为

属性

说明

stock

股票

stockoption

股票期权

techstock

科技股

Future

期货

bond

债券

fund

基金

index

指数

repo

回购

crypto

加密货币

cryptofuture

加密货币合约

cryptoufuture

加密货币u本位合约

multi

多品种

settings: 对应表单配置项
key
key: 表单项的key
name
name: 表单项的name
type
type表单项的类型: 可选项

属性

说明

str

字符串

password

密码

file

文件

files

多选文件

directory

目录

folder

文件夹

rangePicker

时间范围选择器

dateTimePicker

日期时间选择器

datePicker

日期选择器

timePicker

时间选择器

select

选择框

multiSelect

多选框

radio

单选栏

checkbox

复选框

bool

布尔类型

int

整型

float

浮点型

percent

百分比

td

选择交易账户

md

选择行情源

operator

选择算子

instrument

选择标的

instruments

选择多个标的

side

选择买卖

offset

选择开平

options
options: 其中当type字段类型为 select/checkbox/multiSelect/radio 时有效,对应结构如下:
1    {
2        "value": # string | number, 选项值;
3        "label": # string, 选项显示内容;
4    }
tips
tips: 备注信息
errMsg
errMsg: 报错信息
default
default: 默认值,类型需和 type 一致,目前只支持对一些基础类型设置(int/float/str/bool/percent/select/checkbox/multiSelect/radio)
required
required: true/false, 该项是否必填
primary
primary: true/false, 该项是否为主键