# JS组件示例合集
从最简单的HelloWorld到复杂的策略下单,通过一系列的组件示例由浅入深的展示组件中各个接口与工具的使用。
开发组直接工作在Github (opens new window)上,所有代码细节通通展示给你。也欢迎你的PR。
如果你对Smart组件开发并没有了解,推荐按照列表的顺序查看各个组件的实现,由浅入深的了解我们的组件体系。
组件示例还在不断丰富中,有什么想了解的,可以随时联系我们。
# 项目搭建类
通过项目演进,了解各个文件作用。熟悉整个结构后,可以使用脚手架工具@xtp-smart/cli快速生成项目。
hello-world: 没有任何逻辑,只显示"Hello World"字样todomvc-jquery: 不调用任何SDK中的API,引用自TodoMVC(opens new window)中的JQuery(opens new window)实现webpack-typescript: 使用webpack编译typescript语言,直接生成调式或生产版本的组件。
# API类
lifecycle: 展示组件的生命周期quote: 获取行情信息的组件kungfu: 操作存放在机房的KungFu策略notification-sound: 组件在后台发送通知,特别是在组件在后台运行的情况下。
# UI类
charts: 使用Echarts图标组件展示交易数据。
# 基础API示例
# 订阅行情及接收行情推送
smart.on_init(function () {
console.log("onInit");
// 订阅
smart.current_account.subscribe(['600000'], smart.Type.Exchange.SSE);
smart.current_account.on_quote(quote=>{
console.log("quote : ", JSON.stringify(quote));
// 输出:
// {
// "source_id": "xtp",
// "trading_day": "20230912",
// "rcv_time": "20230912094203000",
// "data_time": "20230912094203000",
// "instrument_id": "600000",
// "exchange_id": "SSE",
// "instrument_type": 1,
// "pre_close_price": 7.04,
// "pre_settlement_price": null,
// "last_price": 7.04,
// "volume": 960295,
// "turnover": 6764965.800000001,
// "pre_open_interest": null,
// "open_interest": null,
// "open_price": 7.03,
// "high_price": 7.06,
// "low_price": 7.03,
// "upper_limit_price": 7.74,
// "lower_limit_price": 6.34,
// "close_price": 0,
// "settlement_price": null,
// "bid_price": [ 7.04, 7.03, 7.02, 7.01, 7, 0, 0, 0, 0, 0 ],
// "ask_price": [ 7.05, 7.06, 7.07, 7.08, 7.09, 0, 0, 0, 0, 0 ],
// "bid_volume": [ 152105, 402300, 486400, 748600, 1566800, 0, 0, 0, 0, 0 ],
// "ask_volume": [ 85700, 568000, 178600, 322300, 619300, 0, 0, 0, 0, 0 ],
// "avg_price": 7.044674605199445,
// "iopv": 0,
// "instrument_status": "T111",
// "code": "600000.SH"
// }
// 取消订阅
smart.current_account.unsubscribe([quote.instrument_id], quote.exchange_id);
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 订阅指数行情及接收指数行情推送
smart.on_init(function () {
console.log("onInit");
// 订阅指数行情
smart.current_account.subscribe_index(["000001", "CESCPD", "931646"]);
// 接收指数行情
smart.current_account.on_quote(quote => {
if(quote.instrument_type == smart.Type.InstrumentType.Index){
console.log("quote为",JSON.stringify(quote));
// 输出:
// {
// "source_id": "xtp",
// "trading_day": "20240403",
// "rcv_time": "20240403102829740",
// "data_time": "20240403102829740",
// "instrument_id": "000001",
// "exchange_id": "SSE",
// "instrument_type": 5,
// "pre_close_price": 3074.9586,
// "pre_settlement_price": null,
// "last_price": 3063.8628,
// "volume": 168518138,
// "turnover": 180227286056.7,
// "pre_open_interest": null,
// "open_interest": null,
// "open_price": 3074.8929,
// "high_price": 3079.02,
// "low_price": 3061.9143,
// "upper_limit_price": 0,
// "lower_limit_price": 0,
// "close_price": 0,
// "settlement_price": null,
// "bid_price": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
// "ask_price": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
// "bid_volume": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
// "ask_volume": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
// "avg_price": 0,
// "iopv": 0,
// "instrument_status": " ",
// "code": "000001.SH"
// }
// 取消订阅指数行情
smart.current_account.unsubscribe_index([quote.instrument_id]);
}
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 委托下单
smart.on_init(async function () {
console.log("onInit");
let order = await smart.current_account.insert_order(
'600000',
smart.Type.Exchange.SSE,
7.03,
100,
smart.Type.PriceType.Limit,
smart.Type.Side.Buy,
smart.Type.Offset.Init
);
console.log("order为", JSON.stringify(order));
// 输出:
// {
// "rcv_time": "undefined",
// "order_id": "37906458003637256",
// "source_order_id": "37906458003637256",
// "insert_time": "undefined",
// "update_time": "undefined",
// "trading_day": "undefine",
// "instrument_id": "600000",
// "exchange_id": "SSE",
// "account_id": "253191000961",
// "client_id": "44b571e1-507d-11ee-9eb1-e1cdb10f52b8",
// "instrument_type": 1,
// "limit_price": 7.03,
// "frozen_price": 7.03,
// "volume": 100,
// "volume_traded": 0,
// "volume_left": 100,
// "tax": null,
// "commission": null,
// "status": 1,
// "side": 1,
// "offset": 100,
// "price_type": 1,
// "volume_condition": 0,
// "time_condition": 2,
// "parent_order_id": "",
// "code": "600000.SH",
// "traffic": "front",
// "traffic_sub_id": "JSDemo-_dev_",
// "cancel_time": "undefined",
// "order_cancel_client_id": "undefined",
// "instrument_name": "浦发银行",
// "trade_amount": 0,
// "xtp_business_type": "XTP_BUSINESS_TYPE_CASH",
// "xtp_market_type": "XTP_MKT_SH_A",
// "xtp_price_type": "XTP_PRICE_LIMIT",
// "xtp_position_effect_type": "XTP_POSITION_EFFECT_INIT",
// "xtp_side_type": "XTP_SIDE_BUY",
// "xtp_order_status": "XTP_ORDER_STATUS_INIT",
// "exchange_id_name": "上交所",
// "instrument_type_name": "股票",
// "status_name": "初始化",
// "side_name": "买",
// "offset_name": "初始值",
// "price_type_name": "限价",
// "xtp_business_type_name": "普通股票",
// "xtp_market_name": "沪A",
// "xtp_price_type_name": "限价",
// "xtp_position_effect_type_name": "初始值",
// "xtp_side_type_name": "买",
// "xtp_order_status_name": "初始化",
// "volume_condition_name": "任何数量",
// "time_condition_name": "本节有效",
// "traffic_name": "客户端策略",
// "business_type": "front"
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 委托撤单
smart.on_init(async function () {
console.log("onInit");
let order = await smart.current_account.insert_order(
'600000',
smart.Type.Exchange.SSE,
7.03,
100,
smart.Type.PriceType.Limit,
smart.Type.Side.Buy,
smart.Type.Offset.Init
);
let result = await smart.current_account.cancel_order(order.order_id);
console.log("result为", JSON.stringify(result));
//输出:{"orderXtpId":"37906458003637263","userName":"253191000961","requestID":"cancelOrder_13"}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 订阅及取消订阅ETF折溢价预期利润
smart.on_init(async function () {
console.log("onInit");
let profitList = await smart.subscribeETFProfit(); // 订阅并返回ETF预期利润等信息
console.log(JSON.stringify(profitList[0]));
// 输出:
// {
// "instrument_id": "159601",
// "iopv": 0.7242999999999999,
// "iopv_buy": 0.7238,
// "iopv_sale": 0.7245,
// "diopv": 0.7242,
// "dis_profit": -4824.784780000167,
// "pre_profit": -2065.677600000065
// }
smart.on(smart.Event.ON_ETF_PROFIT, etfProfit => { // 接收ETF预期利润等信息推送
console.log(JSON.stringify(etfProfit));
// 输出:
// {
// "instrument_id": "159971",
// "iopv": 1.3420999999999998,
// "iopv_buy": 1.3414,
// "iopv_sale": 1.3428,
// "diopv": 1.3421,
// "dis_profit": -11039.280519999907,
// "pre_profit": -18191.886200000095
// }
smart.unsubscribeETFProfit(); // 取消订阅ETF折溢价预期利润
})
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 订阅港股通实时额度
smart.on_init(function () {
console.log("onInit");
//订阅港股通实时额度,额度数据变化时触发ON_HKRL_DATA事件;重复订阅会立即返回最近一次的额度数据
smart.subscribe_hkrl();
smart.on(smart.Event.ON_HKRL_DATA, data => {
console.log("get ON_HKRL_DATA:", JSON.stringify(data));
// 输出:
// {
// "dataTime": "20240214093000123",
// "marketId": "XHKG",
// "marketSegmentId": "XHKG-SZSE",
// "thresholdAmount": 0,
// "posAmt": 0,
// "amountStatus": "0",
// "serverTimestamp": 1707874200123
// }
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 查询证券信息根据证券代码和交易所
smart.on_init(function () {
console.log("onInit");
let instrument = smart.getInstrument('600000', smart.Type.Exchange.SSE);
console.log("instrument为",JSON.stringify(instrument));
// 输出:
// {
// "instrument_id": "600000",
// "instrument_name": "浦发银行",
// "instrument_type": "Stock",
// "instrument_type_ext": "XTP_SECURITY_MAIN_BOARD",
// "exchange_id": "SSE",
// "exchange_id_name": "上交所",
// "xtp_market_type": "XTP_MKT_SH_A",
// "name_py": "pfyh",
// "price_tick": 0.01,
// "precision": 2,
// "buy_volume_unit": 100,
// "sell_volume_unit": 1,
// "bid_volume_unit": 100,
// "ask_volume_unit": 1,
// "bid_upper_limit_volume": 1000000,
// "bid_lower_limit_volume": 100,
// "ask_upper_limit_volume": 1000000,
// "market_bid_volume_unit": 100,
// "market_ask_volume_unit": 1,
// "market_bid_upper_limit_volume": 1000000,
// "market_bid_lower_limit_volume": 100,
// "market_ask_upper_limit_volume": 1000000,
// "pre_close_price": 7.04,
// "upper_limit_price": 7.74,
// "lower_limit_price": 6.340000000000001,
// "is_registration": false,
// "kw": "浦发银行",
// "code": "600000.SH",
// "ask_lower_limit_volume": 1,
// "market_ask_lower_limit_volume": 1
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 查询可交易的ETF列表
获取可交易的ETF列表
smart.on_init(async function () {
console.log("onInit");
let etfList = await smart.getETFList();
console.log(JSON.stringify(etfList[0]));
// 输出:
// {
// "instrument_id": "159601",
// "instrument_name": "A50ETF",
// "instrument_type": "Fund",
// "instrument_type_ext": "XTP_SECURITY_ETF_INTER_MARKET_STOCK",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "name_py": "a50etf",
// "price_tick": 0.001,
// "precision": 3,
// "buy_volume_unit": 100,
// "sell_volume_unit": 1,
// "bid_volume_unit": 100,
// "ask_volume_unit": 1,
// "bid_upper_limit_volume": 1000000,
// "bid_lower_limit_volume": 100,
// "ask_upper_limit_volume": 1000000,
// "market_bid_volume_unit": 100,
// "market_ask_volume_unit": 1,
// "market_bid_upper_limit_volume": 1000000,
// "market_bid_lower_limit_volume": 100,
// "market_ask_upper_limit_volume": 1000000,
// "pre_close_price": 0.77,
// "upper_limit_price": 0.8470000000000001,
// "lower_limit_price": 0.6930000000000001,
// "is_registration": false,
// "kw": "A50ETF",
// "code": "159601.SZ",
// "cash_component": 498.65,
// "estimate_amount": 5110.65,
// "max_cash_ratio": 0.5,
// "net_value": 0.7699,
// "redemption_status": 1,
// "total_amount": 2001836.65,
// "unit": 2600000,
// "basket": [],
// "marketType": "XTP_MKT_SZ_A",
// "etf": "159601",
// "etfName": "A50ETF",
// "subscribeRedemptionTicker": "159601",
// "subscribeStatus": 1,
// "redemptionStatus": 1,
// "maxCashRatio": 0.5,
// "estimateAmount": 5110.65,
// "cashComponent": 498.65,
// "netValue": 0.7699,
// "totalAmount": 2001836.65,
// "ask_lower_limit_volume": 1,
// "market_ask_lower_limit_volume": 1
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 查询ETF成分股列表
获取ETF成分股列表
instrument_idString(必填) - ETF代码
smart.on_init(async function () {
console.log("onInit");
let list = await smart.getETFBasket("159601");
console.log(JSON.stringify(list[0]));
// 输出:
// {
// "instrument_id": "601601",
// "instrument_name": "中国太保",
// "instrument_type": "Stock",
// "instrument_type_ext": "XTP_SECURITY_MAIN_BOARD",
// "exchange_id": "SSE",
// "exchange_id_name": "上交所",
// "xtp_market_type": "XTP_MKT_SH_A",
// "name_py": "zgtb",
// "price_tick": 0.01,
// "precision": 2,
// "buy_volume_unit": 100,
// "sell_volume_unit": 1,
// "bid_volume_unit": 100,
// "ask_volume_unit": 1,
// "bid_upper_limit_volume": 1000000,
// "bid_lower_limit_volume": 100,
// "ask_upper_limit_volume": 1000000,
// "market_bid_volume_unit": 100,
// "market_ask_volume_unit": 1,
// "market_bid_upper_limit_volume": 1000000,
// "market_bid_lower_limit_volume": 100,
// "market_ask_upper_limit_volume": 1000000,
// "pre_close_price": 29.86,
// "upper_limit_price": 32.85,
// "lower_limit_price": 26.87,
// "is_registration": false,
// "kw": "中国太保",
// "code": "601601.SH",
// "amount": 0,
// "creation_amount": 0,
// "creation_premium_ratio": 0.1,
// "premium_ratio": 0.1,
// "quantity": 700,
// "redemption_amount": 0,
// "redemption_discount_ratio": 0.1,
// "replace_type": "ERT_CASH_OPTIONAL",
// "ticker": "159601",
// "marketType": "XTP_MKT_SZ_A",
// "componentTicker": "601601",
// "componentName": "中国太保",
// "componentMarketType": "XTP_MKT_SH_A",
// "replaceType": "ERT_CASH_OPTIONAL",
// "premiumRatio": 0.1,
// "requestId": 11012,
// "lastResp": false,
// "creationPremiumRatio": 0.1,
// "redemptionDiscountRatio": 0.1,
// "creationAmount": 0,
// "redemptionAmount": 0,
// "ask_lower_limit_volume": 1,
// "market_ask_lower_limit_volume": 1
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 查询可交易的IPO列表
获取IPO列表
smart.on_init(async function () {
console.log("onInit");
let list = await smart.getIPOList();
console.log(JSON.stringify(list[0]));
// 输出:
// {
// "instrument_id": "300641",
// "instrument_name": "主测886",
// "instrument_type": "Stock",
// "instrument_type_ext": "XTP_TICKER_TYPE_STOCK",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "name_py": "",
// "price_tick": 0,
// "precision": 0,
// "buy_volume_unit": 0,
// "sell_volume_unit": 0,
// "bid_volume_unit": 0,
// "ask_volume_unit": 0,
// "bid_upper_limit_volume": 0,
// "bid_lower_limit_volume": 0,
// "ask_upper_limit_volume": 0,
// "market_bid_volume_unit": 0,
// "market_ask_volume_unit": 0,
// "market_bid_upper_limit_volume": 0,
// "market_bid_lower_limit_volume": 0,
// "market_ask_upper_limit_volume": 0,
// "pre_close_price": 0,
// "upper_limit_price": 0,
// "lower_limit_price": 0,
// "is_registration": false,
// "kw": "",
// "code": "300641.SZ",
// "price": 9.01,
// "qty_upper_limit": 99999500,
// "unit": 500
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 获取国债逆回购列表
获取国债逆回购列表
smart.on_init(async function () {
console.log("onInit");
let list = await smart.getBondReverseRepoList();
console.log(JSON.stringify(list[0]));
// 输出:
// {
// "instrument_id": "131800",
// "instrument_name": "R-003",
// "instrument_type": "Bond",
// "instrument_type_ext": "XTP_SECURITY_NATIONAL_BOND_REVERSE_REPO",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "name_py": "r-003",
// "price_tick": 0.005,
// "precision": 3,
// "buy_volume_unit": 10,
// "sell_volume_unit": 10,
// "bid_volume_unit": 10,
// "ask_volume_unit": 10,
// "bid_upper_limit_volume": 100000000,
// "bid_lower_limit_volume": 10,
// "ask_upper_limit_volume": 100000000,
// "market_bid_volume_unit": 10,
// "market_ask_volume_unit": 10,
// "market_bid_upper_limit_volume": 100000000,
// "market_bid_lower_limit_volume": 10,
// "market_ask_upper_limit_volume": 100000000,
// "pre_close_price": 2.045,
// "upper_limit_price": 999999999.9999001,
// "lower_limit_price": 0.005,
// "is_registration": false,
// "kw": "R-003",
// "code": "131800.SZ",
// "ask_lower_limit_volume": 10,
// "market_ask_lower_limit_volume": 10
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 查询可转债信息 标准版不支持
查询可转债信息
smart.on_init(async function () {
console.log("onInit");
let convertableBond = await smart.getConvertableBond("113658.SH");
console.log(JSON.stringify(convertableBond));
// 输出:
// {
// "instrument_id": "113658",
// "instrument_name": "密卫转债",
// "instrument_type": "Bond",
// "instrument_type_ext": "XTP_SECURITY_CONVERTABLE_BOND",
// "exchange_id": "SSE",
// "exchange_id_name": "上交所",
// "xtp_market_type": "XTP_MKT_SH_A",
// "name_py": "mwzz",
// "price_tick": 0.001,
// "precision": 3,
// "buy_volume_unit": 10,
// "sell_volume_unit": 10,
// "bid_volume_unit": 10,
// "ask_volume_unit": 10,
// "bid_upper_limit_volume": 1000000,
// "bid_lower_limit_volume": 10,
// "ask_upper_limit_volume": 1000000,
// "market_bid_volume_unit": 10,
// "market_ask_volume_unit": 10,
// "market_bid_upper_limit_volume": 1000000,
// "market_bid_lower_limit_volume": 10,
// "market_ask_upper_limit_volume": 1000000,
// "pre_close_price": 107.083,
// "upper_limit_price": 128.5,
// "lower_limit_price": 85.66600000000001,
// "is_registration": false,
// "kw": "密卫转债",
// "code": "113658.SH",
// "qtyMax": 999999990,
// "qtyMin": 10,
// "swapFlag": 1,
// "swapPrice": 134.07,
// "underlyingTicker": "603713",
// "unit": 10,
// "ask_lower_limit_volume": 10,
// "market_ask_lower_limit_volume": 10
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 获取国债逆回购列表
国债逆回购列表
smart.on_init(function () {
console.log("onInit");
let list = smart.reverse_repo_list;
console.log(JSON.stringify(list[0]));
// 输出:
// {
// "instrument_id": "131800",
// "instrument_name": "R-003",
// "instrument_type": "Bond",
// "instrument_type_ext": "XTP_SECURITY_NATIONAL_BOND_REVERSE_REPO",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "name_py": "r-003",
// "price_tick": 0.005,
// "precision": 3,
// "buy_volume_unit": 10,
// "sell_volume_unit": 10,
// "bid_volume_unit": 10,
// "ask_volume_unit": 10,
// "bid_upper_limit_volume": 100000000,
// "bid_lower_limit_volume": 10,
// "ask_upper_limit_volume": 100000000,
// "market_bid_volume_unit": 10,
// "market_ask_volume_unit": 10,
// "market_bid_upper_limit_volume": 100000000,
// "market_bid_lower_limit_volume": 10,
// "market_ask_upper_limit_volume": 100000000,
// "pre_close_price": 2.045,
// "upper_limit_price": 999999999.9999001,
// "lower_limit_price": 0.005,
// "is_registration": false,
// "kw": "R-003",
// "code": "131800.SZ",
// "ask_lower_limit_volume": 10,
// "market_ask_lower_limit_volume": 10
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 国债逆回购下单
smart.on_init(async function () {
console.log("onInit");
let order = await smart.current_account.insert_order("204001",smart.Type.Exchange.SSE,2.045,1000,smart.Type.PriceType.Limit,smart.Type.Side.Buy,smart.Type.Offset.Init,0,"",smart.Type.BusinessType.REPO);
console.log("order为",JSON.stringify(order));
// 输出:
// {
// "rcv_time": "undefined",
// "order_id": "37906458003637255",
// "source_order_id": "37906458003637255",
// "insert_time": "undefined",
// "update_time": "undefined",
// "trading_day": "undefine",
// "instrument_id": "204001",
// "exchange_id": "SSE",
// "account_id": "253191000961",
// "client_id": "93612201-507b-11ee-9eb1-e1cdb10f52b8",
// "instrument_type": 3,
// "limit_price": 2.045,
// "frozen_price": 2.045,
// "volume": 1000,
// "volume_traded": 0,
// "volume_left": 1000,
// "tax": null,
// "commission": null,
// "status": 1,
// "side": 1,
// "offset": 100,
// "price_type": 1,
// "volume_condition": 0,
// "time_condition": 2,
// "parent_order_id": "",
// "code": "204001.SH",
// "traffic": "front",
// "traffic_sub_id": "JSDemo-_dev_",
// "cancel_time": "undefined",
// "order_cancel_client_id": "undefined",
// "instrument_name": "GC001",
// "trade_amount": 0,
// "xtp_business_type": "XTP_BUSINESS_TYPE_REPO",
// "xtp_market_type": "XTP_MKT_SH_A",
// "xtp_price_type": "XTP_PRICE_LIMIT",
// "xtp_position_effect_type": "XTP_POSITION_EFFECT_INIT",
// "xtp_side_type": "XTP_SIDE_BUY",
// "xtp_order_status": "XTP_ORDER_STATUS_INIT",
// "exchange_id_name": "上交所",
// "instrument_type_name": "债券",
// "status_name": "初始化",
// "side_name": "买",
// "offset_name": "初始值",
// "price_type_name": "限价",
// "xtp_business_type_name": "回购业务",
// "xtp_market_name": "沪A",
// "xtp_price_type_name": "限价",
// "xtp_position_effect_type_name": "初始值",
// "xtp_side_type_name": "买",
// "xtp_order_status_name": "初始化",
// "volume_condition_name": "任何数量",
// "time_condition_name": "本节有效",
// "traffic_name": "客户端策略",
// "business_type": "front"
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 获取所有证券列表
smart.on_init(function () {
console.log("onInit");
let list = smart.instrument_list;
console.log(JSON.stringify(list[0]));
// 输出:
// {
// "instrument_id": "000001",
// "instrument_name": "平安银行",
// "instrument_type": "Stock",
// "instrument_type_ext": "XTP_SECURITY_MAIN_BOARD",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "name_py": "payh",
// "price_tick": 0.01,
// "precision": 2,
// "buy_volume_unit": 100,
// "sell_volume_unit": 1,
// "bid_volume_unit": 100,
// "ask_volume_unit": 1,
// "bid_upper_limit_volume": 1000000,
// "bid_lower_limit_volume": 100,
// "ask_upper_limit_volume": 1000000,
// "market_bid_volume_unit": 100,
// "market_ask_volume_unit": 1,
// "market_bid_upper_limit_volume": 1000000,
// "market_bid_lower_limit_volume": 100,
// "market_ask_upper_limit_volume": 1000000,
// "pre_close_price": 11.34,
// "upper_limit_price": 12.47,
// "lower_limit_price": 10.21,
// "is_registration": false,
// "kw": "平安银行",
// "code": "000001.SZ",
// "ask_lower_limit_volume": 1,
// "market_ask_lower_limit_volume": 1
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 获取证券列表按照证券代码_市场
获取证券列表按照证券代码_市场
smart.on_init(function () {
console.log("onInit");
let instrument_map = smart.instrument_map;
console.log(JSON.stringify(instrument_map['000001_SZE']));
// 输出:
// {
// "instrument_id": "000001",
// "instrument_name": "平安银行",
// "instrument_type": "Stock",
// "instrument_type_ext": "XTP_SECURITY_MAIN_BOARD",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "name_py": "payh",
// "price_tick": 0.01,
// "precision": 2,
// "buy_volume_unit": 100,
// "sell_volume_unit": 1,
// "bid_volume_unit": 100,
// "ask_volume_unit": 1,
// "bid_upper_limit_volume": 1000000,
// "bid_lower_limit_volume": 100,
// "ask_upper_limit_volume": 1000000,
// "market_bid_volume_unit": 100,
// "market_ask_volume_unit": 1,
// "market_bid_upper_limit_volume": 1000000,
// "market_bid_lower_limit_volume": 100,
// "market_ask_upper_limit_volume": 1000000,
// "pre_close_price": 11.34,
// "upper_limit_price": 12.47,
// "lower_limit_price": 10.21,
// "is_registration": false,
// "kw": "平安银行",
// "code": "000001.SZ",
// "ask_lower_limit_volume": 1,
// "market_ask_lower_limit_volume": 1
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 获取证券列表按照类型分类
按证券类型进行区分的Map结构
smart.on_init(function () {
console.log("onInit");
//"Stock"(股票) | "Bond"(债券) | "Fund"(基金) | "Index"(指数) | "StockOption"(股票期权) | "Future"(期货) | "Unknown"(未知)
let fund_list = smart.instrument_map_by_type["Fund"];
console.log(JSON.stringify(fund_list[0]));
// 输出:
// {
// "instrument_id": "159001",
// "instrument_name": "货币ETF",
// "instrument_type": "Fund",
// "instrument_type_ext": "XTP_SECURITY_MONETARY_FUND_SZ",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "name_py": "hbetf",
// "price_tick": 0.001,
// "precision": 3,
// "buy_volume_unit": 100,
// "sell_volume_unit": 1,
// "bid_volume_unit": 100,
// "ask_volume_unit": 1,
// "bid_upper_limit_volume": 1000000,
// "bid_lower_limit_volume": 1,
// "ask_upper_limit_volume": 1000000,
// "market_bid_volume_unit": 100,
// "market_ask_volume_unit": 1,
// "market_bid_upper_limit_volume": 1000000,
// "market_bid_lower_limit_volume": 1,
// "market_ask_upper_limit_volume": 1000000,
// "pre_close_price": 100.001,
// "upper_limit_price": 110.001,
// "lower_limit_price": 90.001,
// "is_registration": false,
// "kw": "货币ETF",
// "code": "159001.SZ",
// "ask_lower_limit_volume": 1,
// "market_ask_lower_limit_volume": 1
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 消息通知弹窗
组件消息推送到全局
level消息状态:open、info、success、warning、errortitle头部标题msg需要推送的消息内容duration消息显示时间timestamp时间戳
smart.on_init(function () {
console.log("onInit");
let params = {
level: 'success',
title: '标题',
msg: '具体内容',
duration: 4.5,
timestamp: Date.now()
}
smart.notice(params);
});
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 接收委托信息推送
smart.on_init(function () {
console.log("onInit");
//接收委托推送 不保序
smart.current_account.on_order(order => {
console.log("order为",JSON.stringify(order));
// 输出:
// {
// "rcv_time": "20230912133207548",
// "order_id": "37906458003637227",
// "source_order_id": "37906458003637227",
// "insert_time": "20230912133207548",
// "update_time": "0",
// "trading_day": "20230912",
// "instrument_id": "600918",
// "exchange_id": "SSE",
// "account_id": "253191000961",
// "client_id": "13",
// "instrument_type": 1,
// "limit_price": 7.23,
// "frozen_price": 7.23,
// "volume": 200,
// "volume_traded": 0,
// "volume_left": 200,
// "tax": null,
// "commission": null,
// "status": 1,
// "error_id": 0,
// "side": 1,
// "offset": 100,
// "price_type": 1,
// "volume_condition": 0,
// "time_condition": 2,
// "parent_order_id": "cm_b6aa5b20-512d-11ee-a9fa-9be044826453",
// "code": "600918.SH",
// "traffic": "common",
// "traffic_sub_id": "",
// "cancel_time": "0",
// "order_cancel_client_id": "0",
// "instrument_name": "中泰证券",
// "trade_amount": 0,
// "xtp_business_type": "XTP_BUSINESS_TYPE_CASH",
// "xtp_market_type": "XTP_MKT_SH_A",
// "xtp_price_type": "XTP_PRICE_LIMIT",
// "xtp_position_effect_type": "XTP_POSITION_EFFECT_INIT",
// "xtp_side_type": "XTP_SIDE_BUY",
// "xtp_order_status": "XTP_ORDER_STATUS_INIT",
// "exchange_id_name": "上交所",
// "instrument_type_name": "股票",
// "status_name": "初始化",
// "side_name": "买",
// "offset_name": "初始值",
// "price_type_name": "限价",
// "xtp_business_type_name": "普通股票",
// "xtp_market_name": "沪A",
// "xtp_price_type_name": "限价",
// "xtp_position_effect_type_name": "初始值",
// "xtp_side_type_name": "买",
// "xtp_order_status_name": "初始化",
// "volume_condition_name": "任何数量",
// "time_condition_name": "本节有效",
// "traffic_name": "普通下单",
// "business_type": "common"
// }
});
smart.current_account.insert_order(
'600918',
smart.Type.Exchange.SSE,
7.23,
200,
smart.Type.PriceType.Limit,
smart.Type.Side.Buy,
smart.Type.Offset.Init
);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 接收成交回报推送
smart.on_init(function () {
console.log("onInit");
//接收成交回报推送 不保序
smart.current_account.on_trade(trade => {
console.log("trade为",JSON.stringify(trade));
// 输出:
// {
// "rcv_time": "20230912133207560",
// "order_id": "37906458003637227",
// "parent_order_id": "cm_b6aa5b20-512d-11ee-a9fa-9be044826453",
// "trade_time": "20230912133207560",
// "trading_day": "",
// "instrument_id": "600918",
// "exchange_id": "SSE",
// "account_id": "253191000961",
// "client_id": "13",
// "instrument_type": 1,
// "side": 1,
// "offset": 100,
// "price": 7.23,
// "volume": 200,
// "tax": null,
// "commission": null,
// "code": "600918.SH",
// "traffic": "common",
// "traffic_sub_id": "",
// "instrument_name": "中泰证券",
// "trade_amount": 1446,
// "xtp_business_type": "XTP_BUSINESS_TYPE_CASH",
// "xtp_market_type": "XTP_MKT_SH_A",
// "xtp_exec_id": "0000000000036709",
// "xtp_report_index": "153734059393044",
// "xtp_order_exch_id": "0141020000036619",
// "xtp_trade_type": "0",
// "xtp_branch_pbu": "13688",
// "xtp_position_effect_type": "XTP_POSITION_EFFECT_INIT",
// "xtp_side_type": "XTP_SIDE_BUY",
// "exchange_id_name": "上交所",
// "instrument_type_name": "股票",
// "side_name": "买",
// "offset_name": "初始值",
// "xtp_business_type_name": "普通股票",
// "xtp_market_name": "沪A",
// "xtp_position_effect_type_name": "初始值",
// "xtp_side_type_name": "买",
// "traffic_name": "普通下单",
// "xtp_trade_type_name": "普通成交",
// "business_type": "common",
// "_rowid": "XTP_BUSINESS_TYPE_CASH_XTP_MKT_SH_A_0000000000036709_XTP_SIDE_BUY_600918_0"
// }
});
smart.current_account.insert_order(
'600918',
smart.Type.Exchange.SSE,
7.23,
200,
smart.Type.PriceType.Limit,
smart.Type.Side.Buy,
smart.Type.Offset.Init
);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 接收资产变化推送
smart.on_init(function () {
console.log("onInit");
//接收资产变化推送
smart.current_account.on_assets(assets=>{
console.log("assets为",JSON.stringify(assets));
// 输出:
// {
// "total_asset": 999997842.94,
// "buying_power": 999996419.85,
// "security_asset": 0,
// "fund_buy_amount": 2151,
// "fund_buy_fee": 6.06,
// "fund_sell_amount": 0,
// "fund_sell_fee": 0,
// "withholding_amount": 1423.09,
// "frozen_margin": 0,
// "frozen_exec_cash": 0,
// "frozen_exec_fee": 0,
// "pay_later": 0,
// "preadva_pay": 0,
// "orig_banlance": 0,
// "banlance": 0,
// "deposit_withdraw": 0,
// "trade_netting": 0,
// "captial_asset": 0,
// "force_freeze_amount": 0,
// "preferred_amount": 0,
// "market_value": 4253600706,
// "update_time": 1694496728239
// }
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 接收持仓变化推送
smart.on_init(function () {
console.log("onInit");
//接收持仓变化推送
smart.current_account.on_position(position=>{
console.log("position为",JSON.stringify(position));
// 输出:
// {
// "instrument_id": "600918",
// "instrument_name": "中泰证券",
// "direction": 2,
// "direction_name": "净",
// "name_py": "ztzq",
// "volume": 200,
// "sellable_volume": 0,
// "position_cost_price": 7.26,
// "profit_price": 7.26,
// "last_price": 0,
// "market_value": 0,
// "unrealized_pnl": 0,
// "yesterday_volume": 0,
// "purchase_redeemable_qty": 200,
// "executable_option": 0,
// "executable_underlying": 0,
// "locked_position": 0,
// "usable_locked_position": 0,
// "exchange_id": "SSE",
// "exchange_id_name": "上交所",
// "xtp_market_type": "XTP_MKT_SH_A",
// "xtp_market_name": "沪A",
// "_instrument_id_direction": "600918_2",
// "code": "600918.SH"
// }
});
smart.current_account.insert_order(
'600918',
smart.Type.Exchange.SSE,
7.26,
200,
smart.Type.PriceType.Limit,
smart.Type.Side.Buy,
smart.Type.Offset.Init
);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# JS和Python双向通信
只有同时使用python组件的时候有效
start.py
from smart import *
import time
from datetime import datetime
import logging
from smart.type import AccountType
logger = logging.getLogger()
def init():
def testPy(data):
logger.debug(f"testPy:{data}")
# 输出:testPy:{'hi': "It's JS", 'reqID': 'jspy_0', 'reqtype': 1}
return {"hi":"goodJob"}
smart.registCallableFunction("testPy",testPy)
smart.callJSFunction("testJS",{"hi":"It's python!"})
def show():
print("show")
def hide():
print("hide")
def close():
print("close")
smart.on_init(init)
smart.on_show(show)
smart.on_hide(hide)
smart.on_close(close)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
src/index.js (首次使用需在终端执行npm install命令,代码编写完成后需在终端执行npm run build命令进行构建发布)
import Vue from 'vue'
import App from './js/App'
import smartx_ui from '@xtp-smart/ui'
import iView from 'iview';
Vue.use(smartx_ui);
Vue.use(iView);
import '!style-loader!css-loader!iview/dist/styles/iview.css';
import '@xtp-smart/style/dist/css/smartx.min.css'
smart.on_init(function () {
console.log("onInit");
const globalApp = new Vue({
render: h => h(App),
}).$mount('#app');
let port0 = smart.runPython("./start.py");
smart.registCallableFunction("testJS",function(data){
console.log("testJS:",data)
// 输出:testJS: { hi: 'It\'s python!', reqtype: 1 }
function testPyHandler(rsp){
console.log("testPyHandler:",rsp)
// 输出:testPyHandler: { hi: 'goodJob', reqtype: 1 }
}
smart.callPythonFunction(port0,"testPy",{"hi":"It's JS"},testPyHandler)
})
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 两融业务下单 仅支持两融账户
smart.on_init(async function () {
console.log("onInit");
//融资买入
let order = await smart.current_account.insert_order(
'600000',
smart.Type.Exchange.SSE,
7.00,
100,
smart.Type.PriceType.Limit,
smart.Type.Side.MarginTrade,
smart.Type.Offset.Init,
null,
null,
smart.Type.BusinessType.MARGIN
);
console.log("order为",JSON.stringify(order));
// 输出:
// {
// "rcv_time": "undefined",
// "order_id": "36223105735070612",
// "source_order_id": "36223105735070612",
// "insert_time": "undefined",
// "update_time": "undefined",
// "trading_day": "undefine",
// "instrument_id": "600000",
// "exchange_id": "SSE",
// "account_id": "53410900072",
// "client_id": "4b00cad1-510a-11ee-9eb1-e1cdb10f52b8",
// "instrument_type": 1,
// "limit_price": 7,
// "frozen_price": 7,
// "volume": 100,
// "volume_traded": 0,
// "volume_left": 100,
// "tax": null,
// "commission": null,
// "status": 1,
// "side": 21,
// "offset": 100,
// "price_type": 1,
// "volume_condition": 0,
// "time_condition": 2,
// "parent_order_id": "",
// "code": "600000.SH",
// "traffic": "front",
// "traffic_sub_id": "JSDemo-_dev_",
// "cancel_time": "undefined",
// "order_cancel_client_id": "undefined",
// "instrument_name": "浦发银行",
// "trade_amount": 0,
// "xtp_business_type": "XTP_BUSINESS_TYPE_MARGIN",
// "xtp_market_type": "XTP_MKT_SH_A",
// "xtp_price_type": "XTP_PRICE_LIMIT",
// "xtp_position_effect_type": "XTP_POSITION_EFFECT_INIT",
// "xtp_side_type": "XTP_SIDE_MARGIN_TRADE",
// "xtp_order_status": "XTP_ORDER_STATUS_INIT",
// "exchange_id_name": "上交所",
// "instrument_type_name": "股票",
// "status_name": "初始化",
// "side_name": "融资买入",
// "offset_name": "初始值",
// "price_type_name": "限价",
// "xtp_business_type_name": "融资融券",
// "xtp_market_name": "沪A",
// "xtp_price_type_name": "限价",
// "xtp_position_effect_type_name": "初始值",
// "xtp_side_type_name": "融资买入",
// "xtp_order_status_name": "初始化",
// "volume_condition_name": "任何数量",
// "time_condition_name": "本节有效",
// "traffic_name": "客户端策略",
// "business_type": "front"
// }
// 融券卖出
order = await smart.current_account.insert_order(
'600000',
smart.Type.Exchange.SSE,
7.00,
100,
smart.Type.PriceType.Limit,
smart.Type.Side.ShortSell,
smart.Type.Offset.Init,
null,
null,
smart.Type.BusinessType.MARGIN
);
console.log("order为",JSON.stringify(order));
// 输出:
// {
// "rcv_time": "undefined",
// "order_id": "36223105735070614",
// "source_order_id": "36223105735070614",
// "insert_time": "undefined",
// "update_time": "undefined",
// "trading_day": "undefine",
// "instrument_id": "600000",
// "exchange_id": "SSE",
// "account_id": "53410900072",
// "client_id": "b2872c31-510a-11ee-9eb1-e1cdb10f52b8",
// "instrument_type": 1,
// "limit_price": 7,
// "frozen_price": 7,
// "volume": 100,
// "volume_traded": 0,
// "volume_left": 100,
// "tax": null,
// "commission": null,
// "status": 1,
// "side": 22,
// "offset": 100,
// "price_type": 1,
// "volume_condition": 0,
// "time_condition": 2,
// "parent_order_id": "",
// "code": "600000.SH",
// "traffic": "front",
// "traffic_sub_id": "JSDemo-_dev_",
// "cancel_time": "undefined",
// "order_cancel_client_id": "undefined",
// "instrument_name": "浦发银行",
// "trade_amount": 0,
// "xtp_business_type": "XTP_BUSINESS_TYPE_MARGIN",
// "xtp_market_type": "XTP_MKT_SH_A",
// "xtp_price_type": "XTP_PRICE_LIMIT",
// "xtp_position_effect_type": "XTP_POSITION_EFFECT_INIT",
// "xtp_side_type": "XTP_SIDE_SHORT_SELL",
// "xtp_order_status": "XTP_ORDER_STATUS_INIT",
// "exchange_id_name": "上交所",
// "instrument_type_name": "股票",
// "status_name": "初始化",
// "side_name": "融券卖出",
// "offset_name": "初始值",
// "price_type_name": "限价",
// "xtp_business_type_name": "融资融券",
// "xtp_market_name": "沪A",
// "xtp_price_type_name": "限价",
// "xtp_position_effect_type_name": "初始值",
// "xtp_side_type_name": "融券卖出",
// "xtp_order_status_name": "初始化",
// "volume_condition_name": "任何数量",
// "time_condition_name": "本节有效",
// "traffic_name": "客户端策略",
// "business_type": "front"
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# 查询信用资产信息
smart.on_init(async function () {
console.log("onInit");
// 手动查询信用资产信息,会触发on_assets监听函数
let assets = await smart.current_account.queryCreditAssets();
console.log("assets为", JSON.stringify(assets));
// 输出:
// {
// "total_asset": 100001382.54,
// "buying_power": 90000000,
// "security_asset": 0,
// "fund_buy_amount": 0,
// "fund_buy_fee": 0,
// "fund_sell_amount": 0,
// "fund_sell_fee": 0,
// "withholding_amount": 0,
// "frozen_margin": 0,
// "frozen_exec_cash": 0,
// "frozen_exec_fee": 0,
// "pay_later": 0,
// "preadva_pay": 0,
// "orig_banlance": 0,
// "banlance": 0,
// "deposit_withdraw": 0,
// "trade_netting": 0,
// "captial_asset": 0,
// "force_freeze_amount": 0,
// "preferred_amount": 0,
// "market_value": 2072353,
// "update_time": 1694498526847,
// "all_asset": 102075734.54,
// "all_debt": 1072560.87,
// "guaranty": 99249659.778,
// "line_of_credit": 49997187.94,
// "maintenance_ratio": 95.17010865779581,
// "remain_amount": 863752.87,
// "cash_remain_amt": 863101.89,
// "cash_interest": 1797.29,
// "security_interest": 650.98,
// "extras_money": 0
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 查询券源合约 仅支持两融账户
smart.on_init(async function () {
console.log("onInit");
//查询券源合约列表(已分配成交的券源合约信息,仅支持两融账户)
let creditSourceOrders = await smart.query_credit_source_orders();
console.log("get creditSourceOrders count:", creditSourceOrders.length);
creditSourceOrders.forEach(order => {
console.log("get credit source order:", JSON.stringify(order));
// 输出:
// {
// "sno": "2024021400000001",
// "contract_no": "20240214000001",
// "position_id": "2024021400000001",
// "stk_code": "00700",
// "stk_name": "腾讯控股",
// "market": "XHKG",
// "fund_id": "12345678",
// "fund_name": "test",
// "source_type": "1",
// "status": "1",
// "stk_total": 1000,
// "stk_used": 200,
// "stk_avl": 800,
// "use_rate": 0.065,
// "fee": 0,
// "term_code": 0,
// "lender_id": "XH-01",
// "lender_name": "出借人",
// "req_date": "20240214",
// "assign_date": "20240214",
// "sys_date": "20240214",
// "end_date": "20240314",
// "close_date": "",
// "intr_date": "20240215",
// "remark": ""
// }
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 券源申请合约查询 仅支持两融账户
smart.on_init(async function () {
console.log("onInit");
//查询当前账户的券源申请合约列表(仅支持两融账户)
let orderList = await smart.current_account.query_source_apply_orders();
console.log("get source apply orders count:", orderList.length);
orderList.forEach(order => {
console.log("get source apply order:", JSON.stringify(order));
});
});
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 查询自选股列表
smart.on_init(async function () {
console.log("onInit");
let stock_list = await smart.querySelfSelectStockList("金融行业", "xtp", smart.current_account.account_id);
console.log("stock list为", stock_list);
// 输出:['002708.SZ', '002209.SZ', '300922.SZ', '003022.SZ', '000301.SZ', '002881.SZ', '002599.SZ', '002532.SZ', '002665.SZ', '000547.SZ']
});
1
2
3
4
5
6
7
2
3
4
5
6
7
# 融资融券负债合约推送
smart.on_init(function () {
console.log("onInit");
// 获取信用账户当前融资负债合约列表
let credit_debt_finance_list = smart.current_account.credit_debt_finance_list;
console.log("creditDebtFinanceList[0]为", JSON.stringify(credit_debt_finance_list[0]));
// 输出:
// {
// "debt_id": "201903110005100000175",
// "instrument_id": "000002",
// "instrument_name": "万 科A",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "name_py": "wka",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "remain_amt": 430983.83,
// "remain_principal": 430086,
// "remain_interest": 897.83,
// "debt_status": 0,
// "end_date": "20321231",
// "orig_end_date": "20321231",
// "order_xtp_id": "0",
// "order_date": "20190311",
// "extended": false,
// "code": "000002.SZ"
// }
//信用融资负债合约增加或变更推送
smart.current_account.on_credit_debt_finance(function(debtFinance){
console.log("creditDebtFinance为", JSON.stringify(debtFinance));
// 输出:
// {
// "debt_id": "534109000720000000000000005",
// "instrument_id": "600000",
// "instrument_name": "浦发银行",
// "exchange_id": "SSE",
// "exchange_id_name": "上交所",
// "name_py": "pfyh",
// "xtp_market_type": "XTP_MKT_SH_A",
// "remain_amt": 712.03,
// "remain_principal": 712.03,
// "remain_interest": 0,
// "debt_status": 0,
// "end_date": "20240311",
// "orig_end_date": "20240311",
// "order_xtp_id": "36223105735070617",
// "order_date": "20230912",
// "extended": false,
// "code": "600000.SH"
// }
});
// 获取信用账户当前融券负债合约列表
let credit_debt_security_list = smart.current_account.credit_debt_security_list;
console.log("creditDebtSecurityList[0]为", JSON.stringify(credit_debt_security_list[0]));
// 输出:
// {
// "debt_id": "201903110005100000177",
// "instrument_id": "000002",
// "instrument_name": "万 科A",
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "name_py": "wka",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "remain_interest": 464.67,
// "remain_volume": 10000,
// "due_right_volume": 0,
// "debt_status": 0,
// "end_date": "20321231",
// "orig_end_date": "20321231",
// "order_xtp_id": "0",
// "order_date": "20190311",
// "extended": false,
// "code": "000002.SZ"
// }
// 信用融券负债合约增加或变更推送
smart.current_account.on_credit_debt_security(function(debtSecurity){
console.log("creditDebtSecurity为", JSON.stringify(debtSecurity));
// 输出:
// {
// "debt_id": "534109000720000000000000006",
// "instrument_id": "600000",
// "instrument_name": "浦发银行",
// "exchange_id": "SSE",
// "exchange_id_name": "上交所",
// "name_py": "pfyh",
// "xtp_market_type": "XTP_MKT_SH_A",
// "remain_interest": 0,
// "remain_volume": 100,
// "due_right_volume": 0,
// "debt_status": 0,
// "end_date": "20240311",
// "orig_end_date": "20240311",
// "order_xtp_id": "36223105735070618",
// "order_date": "20230912",
// "extended": false,
// "code": "600000.SH"
// }
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 可融券头寸更新推送
smart.on_init(function () {
console.log("onInit");
// 可融券头寸更新推送
smart.current_account.on_credit_ticker_assign(function(creditTickerAssignInfo){
console.log("creditTickerAssignInfo为", JSON.stringify(creditTickerAssignInfo));
// 输出:
// {
// "instrument_id": "600000",
// "instrument_name": "浦发银行",
// "exchange_id": "SSE",
// "exchange_id_name": "上交所",
// "name_py": "pfyh",
// "left_volume": 74500,
// "frozen_volume": 0,
// "yesterday_volume": 0,
// "xtp_market_type": "XTP_MKT_SH_A",
// "code": "600000.SH",
// "limit_volume": "0"
// }
})
smart.current_account.insert_order(
'600000',
smart.Type.Exchange.SSE,
7.00,
100,
smart.Type.PriceType.Limit,
smart.Type.Side.ShortSell,
smart.Type.Offset.Init,
null,
null,
smart.Type.BusinessType.MARGIN
);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 订阅bar行情及接收bar行情推送
// 方式一:
// 订阅bar行情
smart.on_init(async function () {
console.log("onInit");
const codes= ['000001.SZ','600000.SH'];
const period = "1m"; // 1 分钟
const failList = await smart.subscribe_bar(codes, period); // 正常的订阅
if (failList) {// 存在订阅失败的code
for (const code of failList) {
console.log("subscribe_bar订阅存在失败的code", code);
// 可以重新发起订阅
}
} else {
// 订阅全部成功
console.log("subscribe_bar全部成功");
}
//接收bar行情
smart.on(smart.Event.ON_BAR, quote=>{
console.log(quote);
// {
// close: 10.6,
// code: "000001.SZ",
// end_time: "2023-10-20 14:29:00",
// exchange_id: "SZE",
// high: 10.61,
// instrument_id: "000001",
// low: 10.6,
// open: 10.61,
// period: "1m",
// source_id: "xtp",
// start_time: "2023-10-20 14:28:00",
// start_turnover: 479989248.64,
// start_volume: 45295409,
// time_interval: 1,
// trading_day: "2023-10-20",
// turnover: 1083034,
// type: "bar_1min",
// volume: 102100
// }
//取消订阅bar行情
smart.unsubscribe_bar([quote.code], period);
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 方式二:订阅bar行情时直接传入监听bar行情的回调函数
smart.on_init(async function () {
console.log("onInit");
const codes= ['000001.SZ','600000.SH'];
const period = "1m"; // 1 分钟
function on_bar(quote: any) {
console.log(quote);
// {
// close: 10.6,
// code: "000001.SZ",
// end_time: "2023-10-20 14:29:00",
// exchange_id: "SZE",
// high: 10.61,
// instrument_id: "000001",
// low: 10.6,
// open: 10.61,
// period: "1m",
// source_id: "xtp",
// start_time: "2023-10-20 14:28:00",
// start_turnover: 479989248.64,
// start_volume: 45295409,
// time_interval: 1,
// trading_day: "2023-10-20",
// turnover: 1083034,
// type: "bar_1min",
// volume: 102100
// }
//取消订阅bar行情
smart.unsubscribe_bar([quote.code], period);
}
const failList = await smart.subscribe_bar(codes, period, on_bar)
if (failList) {// 存在订阅失败的code
for (const code of failList) {
console.log("subscribe_bar订阅存在失败的code", code);
// 可以重新发起订阅
}
} else {// 订阅全部成功
console.log("subscribe_bar全部成功");
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 方式三:订阅bar行情时,定义默认的on_bar来监听bar行情
smart.on_init(async function () {
console.log("onInit");
const codes= ['000001.SZ','600000.SH'];
const period = "1m"; // 1 分钟
smart.on_bar = function on_bar(quote: any) {
console.log(quote);
// {
// close: 10.6,
// code: "000001.SZ",
// end_time: "2023-10-20 14:29:00",
// exchange_id: "SZE",
// high: 10.61,
// instrument_id: "000001",
// low: 10.6,
// open: 10.61,
// period: "1m",
// source_id: "xtp",
// start_time: "2023-10-20 14:28:00",
// start_turnover: 479989248.64,
// start_volume: 45295409,
// time_interval: 1,
// trading_day: "2023-10-20",
// turnover: 1083034,
// type: "bar_1min",
// volume: 102100
// }
//取消订阅bar行情
smart.unsubscribe_bar([quote.code], period);
}
const failList = await smart.subscribe_bar(codes, period)
if (failList) {// 存在订阅失败的code
for (const code of failList) {
console.log("subscribe_bar订阅存在失败的code", code);
// 可以重新发起订阅
}
} else {// 订阅全部成功
console.log("subscribe_bar全部成功");
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 获取当天任意分钟的bar行情
smart.on_init(async function () {
console.log("onInit");
const codes= ['000001.SZ','600000.SH'];
const period = "5m"; // 5分钟
const result = await smart.query_bar_today_async(codes, period);
console.info("查询bar行情", result);
// {
// 000001.SZ: [
// {
// close: 10.39,
// code: "000001.SZ",
// end_time: "2023-10-30 09:35:00",
// exchange_id: "SZE",
// high: 10.4,
// instrument_id: "000001",
// low: 10.37,
// open: 10.4,
// period: "5m",
// source_id: "xtp",
// start_time: "2023-10-30 09:30:00",
// start_turnover: 0,
// start_volume: 0,
// time_interval: 5,
// trading_day: "2023-10-30",
// turnover: 58720661.05,
// type: "bar_5min",
// volume: 5650991
// },
// {
// type: "bar_5min",
// code: "000001.SZ",
// instrument_id: "000001",
// exchange_id: "SZE",
// trading_day: "2023-10-30",
// ...
// }
// ],
// 600000.SH: [
// {
// close: 6.83,
// code: "600000.SH",
// end_time: "2023-10-30 09:35:00",
// exchange_id: "SSE",
// high: 6.89,
// instrument_id: "600000",
// low: 6.82,
// open: 6.86,
// period: "5m",
// source_id: "xtp",
// start_time: "2023-10-30 09:30:00",
// start_turnover: 0,
// start_volume: 0,
// time_interval: 5,
// trading_day: "2023-10-30",
// turnover: 39546462,
// type: "bar_5min",
// volume: 5767820
// },
// {
// type: "bar_5min",
// code: "600000.SH",
// instrument_id: "600000",
// exchange_id: "SSE",
// trading_day: "2023-10-30",
// ...
// }
// ]
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 获取历史bar数据-query_bar_async
smart.on_init(async function () {
console.log("onInit");
const result = await smart.query_bar_async(
{
code: "000001.SZ", // String(必填) 证券代码 SZ:深证 SH:上海
start_date: "2024-01-12 10:00:00", // String(必填) 开始日期 格式yyyy-MM-dd hh:mm:ss
end_date: "2024-01-12 15:00:00", // String(必填) 结束日期 格式yyyy-MM-dd hh:mm:ss
period: "5m", // String(选填) 频次 仅支持1m 5m 15m 30m 60m 1d 1w 默认1d,(m代表分钟,d代表天,w代表周)
adjust_type: "pre" // String(选填) 复权方式 none:不复权 pre:前复权 post:后复权 默认前复权
}
);
console.info(result);
// [{
// close: 9.19,
// code: "000001.SZ",
// end_time: "2024-01-12 10:00:00",
// exchange_id: "SZE",
// high: 9.2,
// instrument_id: "000001",
// low: 9.17,
// open: 9.19,
// period: "5m",
// source_id: "xtp",
// start_time: "2024-01-12 09:55:00",
// start_turnover: 123997543,
// start_volume: 13549009,
// time_interval: "5m",
// trading_day: "2024-01-12",
// turnover: 21865172,
// type: "bar_5min",
// volume: 2380100
// }, ...]
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 通用指标订阅及接收数据推送
// 方式一:
smart.on_init(async function () {
console.log("onInit");
//订阅
const failList = await smart.subscribe_indicator("etf", ['159915.SZ']);
if (failList) {// 存在订阅失败的code
for (const code of failList) {
console.log("subscribe_indicator订阅存在失败的code", code);
// 可以重新发起订阅
}
} else {// 订阅全部成功
console.log("subscribe_indicator全部成功");
}
//接收数据
smart.on(smart.Event.ON_INDICATOR, (type, quote) => {
console.log(`通用指标etf行情:指标为${type} 数据为` + JSON.stringify(quote));
// 通用指标etf行情:指标为etf 数据为
// {
// "code": "512160.SH",
// "etfData": {
// "saleEtfProfit": 1936000,
// "iopvSale": 0.9676,
// "diopv": 0.9671,
// "iopvBuy": 0.9667,
// "buyEtfProfit": 1938000,
// "sumQuantity": 118400,
// "shTickerPreAmtSum": 1263296,
// "bidQty": 10900,
// "shTickerDisAmtSum": 1262078,
// "askQty": 219100,
// "preCashAndEsa": -1758.41,
// "szTickerPreAmtSum": 673567,
// "disCashAndEsa": -1758.41,
// "szTickerDisAmtSum": 673178,
// "estimateAmountDiff": 0,
// "iopv": 0.967,
// "lastPrice": 0.969
// },
// "type": "etf"
// }
// 取消通用指标订阅
smart.unsubscribe_indicator(quote.type, [quote.code]);
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 方式二:
smart.on_init(async function () {
console.log("onInit");
//接收数据
function on_indicator(type, data) {
console.log(`通用指标etf行情1:指标为${type} 数据为` + JSON.stringify(data));
// 通用指标etf行情:指标为etf 数据为
// {
// "code": "512160.SH",
// "etfData": {
// "saleEtfProfit": 1936000,
// "iopvSale": 0.9676,
// "diopv": 0.9671,
// "iopvBuy": 0.9667,
// "buyEtfProfit": 1938000,
// "sumQuantity": 118400,
// "shTickerPreAmtSum": 1263296,
// "bidQty": 10900,
// "shTickerDisAmtSum": 1262078,
// "askQty": 219100,
// "preCashAndEsa": -1758.41,
// "szTickerPreAmtSum": 673567,
// "disCashAndEsa": -1758.41,
// "szTickerDisAmtSum": 673178,
// "estimateAmountDiff": 0,
// "iopv": 0.967,
// "lastPrice": 0.969
// },
// "type": "etf"
// }
//取消通用指标订阅
smart.unsubscribe_indicator(type, [data.code]);
}
//订阅
const failList = await smart.subscribe_indicator("etf", ['159915.SZ'], on_indicator);
if (failList) {// 存在订阅失败的code
for (const code of failList) {
console.log("subscribe_indicator订阅存在失败的code", code);
// 可以重新发起订阅
}
} else {// 订阅全部成功
console.log("subscribe_indicator全部成功");
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 方式三:
//接收数据
smart.on_init(async function () {
console.log("onInit");
smart.on_indicator = function on_indicator(type, data) {
console.log(`通用指标etf行情3:指标为${type} 数据为` + JSON.stringify(data));
// 通用指标etf行情:指标为etf 数据为
// {
// "code": "512160.SH",
// "etfData": {
// "saleEtfProfit": 1936000,
// "iopvSale": 0.9676,
// "diopv": 0.9671,
// "iopvBuy": 0.9667,
// "buyEtfProfit": 1938000,
// "sumQuantity": 118400,
// "shTickerPreAmtSum": 1263296,
// "bidQty": 10900,
// "shTickerDisAmtSum": 1262078,
// "askQty": 219100,
// "preCashAndEsa": -1758.41,
// "szTickerPreAmtSum": 673567,
// "disCashAndEsa": -1758.41,
// "szTickerDisAmtSum": 673178,
// "estimateAmountDiff": 0,
// "iopv": 0.967,
// "lastPrice": 0.969
// },
// "type": "etf"
// }
// 取消订阅
smart.unsubscribe_indicator(type, [data.code]);
}
//订阅
const failList = await smart.subscribe_indicator("etf", ['159915.SZ']);
if (failList) {// 存在订阅失败的code
for (const code of failList) {
console.log("subscribe_indicator订阅存在失败的code", code);
// 可以重新发起订阅
}
} else {
// 订阅全部成功
console.log("subscribe_indicator全部成功");
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 获取市场数据-query_market_data_async
smart.on_init(async function () {
console.log("onInit");
const result = await smart.query_market_data_async(
{
code: "000001.SZ", // String(必填) 证券代码 SZ:深证 SH:上海
start_date: "2024-01-12 10:00:00", // String(必填) 开始日期 格式yyyy-MM-dd hh:mm:ss
end_date: "2024-01-12 15:00:00", // String(必填) 结束日期 格式yyyy-MM-dd hh:mm:ss
}
);
console.info(result);
// [
// {
// "source_id": "xtp",
// "trading_day": "20240112",
// "date_time": "20240112130000246",
// "instrument_id": "600000",
// "exchange_id": "SSE",
// "instrument_type": 1,
// "pre_close_price": 6.53,
// "last_price": 6.52,
// "volume": 20946547,
// "turnover": 136733365,
// "open_price": 6.52,
// "high_price": 6.56,
// "low_price": 6.5,
// "upper_limit_price": 7.18,
// "lower_limit_price": 5.88,
// "bid_price": [ 6.51, 6.5, 6.49, 6.48, 6.47, 0, 0, 0, 0, 0 ],
// "ask_price": [ 6.52, 6.53, 6.54, 6.55, 6.56, 0, 0, 0, 0, 0 ],
// "bid_volume": [ 667270, 2726772, 1069400, 908900, 274000, 0, 0, 0, 0, 0 ],
// "ask_volume": [ 620300, 424100, 670300, 709790, 1090500, 0, 0, 0, 0, 0 ],
// "code": "600000.SH"
// }, ...
// ]
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 获取当前交易日及下一交易日-get_trading_day_async
smart.on_init(async function () {
console.log("onInit");
const result = await smart.get_trading_day_async();
console.info(result);
// {CURRENT_TRDY: "20240415", NEXT_TRDY: "20240416"}
});
1
2
3
4
5
6
7
2
3
4
5
6
7
# 查询数据-获取历史bar行情
smart.on_init(async function () {
console.log("onInit");
const result = await smart.query_data_async(
"bar", // method方法:固定值
{
code: "000001.SZ", // 证券代码 SZ:深证 SH:上海
start_date: "2013-01-04", // 开始日期
end_date: "2014-01-04", // 结束日期
period: "5m", // 频次 仅支持1m 5m 15m 30m 60m 1d 1w 默认1d,(m代表分钟,d代表天,w代表周)
adjust_type: "pre" // 复权方式 none:不复权 pre:前复权 post:后复权 默认前复权
}
);
console.info(result);
// [{
// close: 9.19,
// code: "000001.SZ",
// end_time: "2024-01-12 10:00:00",
// exchange_id: "SZE",
// high: 9.2,
// instrument_id: "000001",
// low: 9.17,
// open: 9.19,
// period: "5m",
// source_id: "xtp",
// start_time: "2024-01-12 09:55:00",
// start_turnover: 123997543,
// start_volume: 13549009,
// time_interval: "5m",
// trading_day: "2024-01-12",
// turnover: 21865172,
// type: "bar_5min",
// volume: 2380100
// }...]
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 查询数据-获取市场数据
smart.on_init(async function () {
console.log("onInit");
const result = await smart.query_data_async(
"market_data", // method方法:固定值
{
code: "000001.SZ", // String(必填) 证券代码 SZ:深证 SH:上海
start_date: "2024-01-12 10:00:00", // String(必填) 开始日期 格式yyyy-MM-dd hh:mm:ss
end_date: "2024-01-12 15:00:00", // String(必填) 结束日期 格式yyyy-MM-dd hh:mm:ss
}
);
console.info(result);
// [
// {
// "source_id": "xtp",
// "trading_day": "20240112",
// "date_time": "20240112130000246",
// "instrument_id": "600000",
// "exchange_id": "SSE",
// "instrument_type": 1,
// "pre_close_price": 6.53,
// "last_price": 6.52,
// "volume": 20946547,
// "turnover": 136733365,
// "open_price": 6.52,
// "high_price": 6.56,
// "low_price": 6.5,
// "upper_limit_price": 7.18,
// "lower_limit_price": 5.88,
// "bid_price": [ 6.51,6.5,6.49,6.48,6.47,0,0,0,0,0 ],
// "ask_price": [ 6.52,6.53,6.54,6.55,6.56,0,0,0,0,0 ],
// "bid_volume": [ 667270,2726772,1069400,908900,274000,0,0,0,0,0 ],
// "ask_volume": [ 620300,424100,670300,709790,1090500,0,0,0,0,0 ],
// "code": "600000.SH"
// }, ...
// ]
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 查询数据-获取当前交易日及下一交易日
smart.on_init(async function () {
console.log("onInit");
const result = await smart.query_data_async(
"current_next_trading_day" // String(必填) method方法:固定值
);
console.info(result);
//[{CURRENT_TRDY: "20240415" // 当前交易日, NEXT_TRDY: "20240416" // 下一交易日}]
});
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 分页查询数据-获取历史bar行情
smart.on_init(async function () {
console.log("onInit");
const result = await smart.query_data_page_async(
"bar", // method方法:固定值
{
code: "000001.SZ", // 证券代码 SZ:深证 SH:上海
start_date: "2013-01-04", // 开始日期
end_date: "2014-01-04", // 结束日期
period: "5m", // 频次 仅支持1m 5m 15m 30m 60m 1d 1w 默认1d,(m代表分钟,d代表天,w代表周)
adjust_type: "pre", // 复权方式 none:不复权 pre:前复权 post:后复权 默认前复权
current_page: 1, // 当前页,不传 默认当前页 为1
page_size: 10000 // 分页数量,最大为10000
}
);
console.info(result);
// {
// data: [{
// close: 9.19,
// code: "000001.SZ",
// end_time: "2024-01-12 10:00:00",
// exchange_id: "SZE",
// high: 9.2,
// instrument_id: "000001",
// low: 9.17,
// open: 9.19,
// period: "5m",
// source_id: "xtp",
// start_time: "2024-01-12 09:55:00",
// start_turnover: 123997543,
// start_volume: 13549009,
// time_interval: "5m",
// trading_day: "2024-01-12",
// turnover: 21865172,
// type: "bar_5min",
// volume: 2380100
// }, ...],
// currentPage: 1,
// pageSize: 10000,
// totalCount: 43,
// totalPage: 1
// }
console.info(`query_data_page_async 当前页:${result.currentPage}, 每页记录数:${result.pageSize}, 总记录数:${result.totalCount}, 总页数:${result.totalPage}`);
// query_data_page_async 当前页:1, 每页记录数:10000, 总记录数:43, 总页数:1
console.info("query_data_page_async 查询数据集", result.data);
// [{
// close: 9.19,
// code: "000001.SZ",
// end_time: "2024-01-12 10:00:00",
// exchange_id: "SZE",
// high: 9.2,
// instrument_id: "000001",
// low: 9.17,
// open: 9.19,
// period: "5m",
// source_id: "xtp",
// start_time: "2024-01-12 09:55:00",
// start_turnover: 123997543,
// start_volume: 13549009,
// time_interval: "5m",
// trading_day: "2024-01-12",
// turnover: 21865172,
// type: "bar_5min",
// volume: 2380100
// }, ...]
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 分页查询数据-获取市场数据
smart.on_init(async function () {
console.log("onInit");
const result = await smart.query_data_page_async(
"market_data", // String(必填) method方法:固定值
{
code: "000001.SZ", // String(必填) 证券代码 SZ:深证 SH:上海
start_date: "2024-01-12 08:30:00", // String(必填) 开始日期
end_date: "2024-01-12 15:00:00", // String(必填) 结束日期
current_page: 1, // 当前页,不传 默认当前页 为1
page_size: 1000 // 分页数量,最大为10000
}
);
console.info(result);
// {
// data:[{
// ask_price: (10) [9.19, 9.2, 9.21, 9.22, 9.23, 0, 0, 0, 0, 0]
// ask_volume: (10) [368100, 904500, 463100, 719900, 483500, 0, 0, 0, 0, 0]
// bid_price: (10) [9.18, 9.17, 9.16, 9.15, 9.14, 0, 0, 0, 0, 0]
// bid_volume: (10) [363900, 606900, 757200, 1069400, 441500, 0, 0, 0, 0, 0]
// code: "000001.SZ"
// date_time: "20240112100000000"
// exchange_id: "SZE"
// high_price: 9.2
// instrument_id: "000001"
// last_price: 9.19
// low_price: 9.11
// lower_limit_price: 8.25
// open_price: 9.13
// pre_close_price: 9.17
// source_id: "xtp"
// trading_day: "20240112"
// turnover: 145870062
// upper_limit_price: 10.09
// volume: 15929909}......]
// currentPage: 1,
// pageSize: 1000,
// totalCount: 4150,
// totalPage: 5,
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 标的担保品查询 仅支持两融账户
smart.on_init(async function () {
console.log("onInit");
// 请求查询标的担保品信息
const result = await smart.query_credit_assure();
console.log("标的担保品数量:", result.length);
for (const assure of result) {
console.log("标的担保品:", JSON.stringify(assure));
}
// 输出:
// {
// "ticker": "000404",
// "xtp_market_type": "XTP_MKT_SZ_A",
// "exchange_id": "SZE",
// "pledge_rate": 0.65,
// "fair_price": 0.0,
// "fair_flag": "0",
// "update_date": "20200323",
// "status": "0",
// "capital": "695995979.00",
// "circulating_shares": "693540122.00",
// "position_limit_rate": "0.00",
// "mtk_cal_flag": "1",
// "node_id": 9
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 跨组件之间发送消息
发送组件:
smart.on_init(async function () {
console.log("onInit");
// 向指定组件发送消息,plugin_id为目标接收组件的组件ID
const plugin_id = "sun_python1-local";
const msg_obj = {"x": "data1", "y": "data2"};
smart.post_params(plugin_id, msg_obj);
});
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
接收数据组件:
smart.on_init(async function () {
console.log("onInit");
// 监听跨组件消息推送,接收发送组件通过post_params发来的数据
smart.on(smart.Event.ON_POST_PARAMS, data => {
console.log("ON_POST_PARAMS【OK】:", JSON.stringify(data));
// 输出:{"x": "data1", "y": "data2"}
});
});
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 查询新股申购额度
smart.on_init(async function () {
console.log("onInit");
// 请求查询用户新股申购额度信息
const quotaList = await smart.getIPOQuotaList();
console.log("getIPOQuotaList count:", quotaList.length);
for (const quota of quotaList) {
console.log("getIPOQuotaList:", JSON.stringify(quota));
}
// 输出:{"lastResp": false, "marketType": "XTP_MKT_SZ_A", "quantity": 999999999, "requestId": 3, "tech_quantity": 0, "unused": 0}
});
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 查询今日可转债申购信息列表
smart.on_init(async function () {
console.log("onInit");
// 请求查询今日可转债申购信息列表
const bondList = await smart.getBondIPOList();
console.log("getBondIPOList count:", bondList.length);
for (const bond of bondList) {
console.log("getBondIPOList:", JSON.stringify(bond));
}
// 输出:{"lastResp": false, "marketType": "XTP_MKT_SZ_A", "price": 11.25, "qtyUpperLimit": 260000, "requestId": 3, "ticker": "304129", "tickerName": "展芯股份", "tickerType": "XTP_TICKER_TYPE_STOCK", "unit": 500}
});
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 获取交易日历列表
smart.on_init(async function () {
console.log("onInit");
// 获取指定市场、指定日期区间的交易日历列表
const start_date = "20260701";
const end_date = "20260730";
const market_type = "XTP_MKT_SZ_A";
const tradingDates = await smart.get_trading_dates(start_date, end_date, market_type);
console.log("get_trading_dates count:", tradingDates.length);
for (const date of tradingDates) {
console.log("get_trading_dates:", JSON.stringify(date));
}
// 输出:{"xtpMarketType": "XTP_MKT_SZ_A", "tradeDay": "20260701"}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 算法API示例
# 创建及启动算法策略 标准版不支持
smart.on_init(async function () {
console.log("onInit");
// 1.配置策略参数
const param={
"start_time":"09:35:00",
"end_time":"15:00:00",
"ticker":"600918",
"market":"SH",
"side":"BUY",
"quantity":300,
"limit_action":false,
"expire_action":false,
"price":0,
"business_type":"CASH"
}
const config = {
"strategyType": 3103,
"clientStrategyId": String(Math.floor(Date.now()*1000) + (100000 + Math.floor(Math.random() * 100000))),
"strategyParam": JSON.stringify(param)
} // 各算法编号"strategyType"及配置项参数"strategyParam"详见SmartX SDK API文档createStrategy方法中的"config参数参考文档"
// 2.下单委托创建
try {
let strategy = await smart.current_account.createStrategy(smart.Type.StrategyPlatformType.Algo, config.clientStrategyId, config);
console.info("下单委托创建", strategy);
// 输出:AlgoXStrategy {strategy_platform_type: "algo", strategy_id: 0, status: "XTP_STRATEGY_STATE_CREATED", isPrivate: false, status_name: "未知", …}
// 3.下单委托提交
try {
strategy = await smart.current_account.startStrategy(strategy.strategy_platform_type, strategy.clent_id);
console.info("下单委托提交", strategy);
//输出:AlgoXStrategy {strategy_platform_type: "algo", strategy_id: 0, status: "XTP_STRATEGY_STATE_CREATED", isPrivate: false, status_name: "未知", …}
} catch (error) {
console.error("下单委托异常", error);
}
} catch (error) {
console.error("下单委托异常", error);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 快速启动算法策略 标准版不支持
smart.on_init(async function () {
console.log("onInit");
// 1.配置策略参数
const param={
"start_time":"09:35:00",
"end_time":"15:00:00",
"ticker":"600918",
"market":"SH",
"side":"BUY",
"quantity":300,
"limit_action":false,
"expire_action":false,
"price":0,
"business_type":"CASH"
}
const config = {
"strategyType": 3103,
"clientStrategyId": String(Math.floor(Date.now()*1000) + (100000 + Math.floor(Math.random() * 100000))),
"strategyParam": JSON.stringify(param)
} // 各算法编号"strategyType"及配置项参数"strategyParam"详见SmartX SDK API文档createStrategy方法中的"config参数参考文档"
// 2.下单委托创建和提交
try {
let strategy = await smart.current_account.insertAlgoOrder(smart.Type.StrategyPlatformType.Algo,config.clientStrategyId, config);
console.info("下单委托提交", strategy);
//输出:AlgoXStrategy {strategy_platform_type: "algo", strategy_id: "1694655060612168", status: "Unknown", isPrivate: false, status_name: "未知", …}
} catch (error) {
console.error("下单委托异常", error);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 停止算法策略
smart.on_init(async function () {
console.log("onInit");
// 1.配置策略参数
const param={
"start_time":"09:35:00",
"end_time":"15:00:00",
"ticker":"600918",
"market":"SH",
"side":"BUY",
"quantity":300,
"limit_action":false,
"expire_action":false,
"price":0,
"business_type":"CASH"
}
const config = {
"strategyType": 3103,
"clientStrategyId": String(Math.floor(Date.now()*1000) + (100000 + Math.floor(Math.random() * 100000))),
"strategyParam": JSON.stringify(param)
} // 各算法编号"strategyType"及配置项参数"strategyParam"详见SmartX SDK API文档createStrategy方法中的"config参数参考文档"
// 2.下单委托创建和提交
try {
let strategy = await smart.current_account.insertAlgoOrder(smart.Type.StrategyPlatformType.Algo,config.clientStrategyId, config);
// 停止委托提交
setTimeout(async function(){
try {
const result = await strategy.stopStrategy();
console.info("停止委托提交完成", result);
//输出:{xtpStrategyId: "1168434462756"}
} catch (error) {
console.error("停止委托提交异常", error);
}
}, 2000);
} catch (error) {
console.error("下单委托异常", error);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 强停算法策略
smart.on_init(async function () {
console.log("onInit");
// 1.配置策略参数
const param={
"start_time":"09:35:00",
"end_time":"15:00:00",
"ticker":"600918",
"market":"SH",
"side":"BUY",
"quantity":300,
"limit_action":false,
"expire_action":false,
"price":0,
"business_type":"CASH"
}
const config = {
"strategyType": 3103,
"clientStrategyId": String(Math.floor(Date.now()*1000) + (100000 + Math.floor(Math.random() * 100000))),
"strategyParam": JSON.stringify(param)
} // 各算法编号"strategyType"及配置项参数"strategyParam"详见SmartX SDK API文档createStrategy方法中的"config参数参考文档"
// 2.下单委托创建和提交
try {
let strategy = await smart.current_account.insertAlgoOrder(smart.Type.StrategyPlatformType.Algo,config.clientStrategyId, config);
// 强停委托
setTimeout(async function(){
try {
const result = await strategy.forceStopStrategy();
console.info("强停委托提交", result);
//输出:{xtpStrategyId: "1168434462757"}
} catch (error) {
console.error("强停委托失败", error);
}
}, 2000);
} catch (error) {
console.error("下单委托异常", error);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Kungfu策略API示例
# 获取策略列表
smart.on_init(async function () {
console.log("onInit");
const strategy_map = smart.current_account.strategy_map;
console.log("strategy_map为",strategy_map);
//输出:
// {
// subscribe_all_market_alphax: AlphaXStrategy,
// 5-23_alphax: AlphaXStrategy,
// test_ob_0628_alphax: AlphaXStrategy,
// zlm_817_alphax: AlphaXStrategy,
// msg_test_alphax: AlphaXStrategy,
// …
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 获取功夫td列表
smart.on_init(async function () {
console.log("onInit");
let td_list = smart.alphax_td_list;
console.log("td_list[0]为", JSON.stringify(td_list[0]));
// 输出:
// {
// "account_id": "15003925",
// "source_name": "xtp",
// "receive_md": false,
// "quoteBrokerId": 8,
// "userName": "15003925",
// "config": {},
// "status": "Stopped",
// "process_name": "td_xtp_15003925",
// "status_name": "已停止",
// "strategy_platform_type": "alphax",
// "process_type": "td",
// "source": "xtp"
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 获取功夫md列表
smart.on_init(async function () {
console.log("onInit");
let md_list = smart.alphax_md_list;
console.log("md_list[0]为", JSON.stringify(md_list[0]));
// 输出:
// {
// "account_id": "internal",
// "source_name": "xtp",
// "receive_md": true,
// "userName": "15003925",
// "config": {},
// "status": "Stopped",
// "process_name": "md_xtp",
// "status_name": "已停止",
// "strategy_platform_type": "alphax",
// "process_type": "md",
// "source": "xtp"
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 监听功夫td进程状态变化
smart.on_init(async function () {
console.log("onInit");
// 当登录smart客户端时,td自动启动,一般启动策略前先通过获取功夫td列表检查策略使用到的td是否都已经启动,没有启动可以通过api启动,或者当检测到td崩溃后可以通过api启动
smart.on_alphax_td_status_change(statusChange => console.log("td状态改变", JSON.stringify(statusChange)));
// 输出:
// {
// "process_name": "td_xtp_15003925",
// "account_id": "15003925",
// "source": "xtp",
// "status": "Started",
// "status_name": "已启动",
// "strategy_platform_type": "alphax"
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 监听功夫md进程状态变化
smart.on_init(async function () {
console.log("onInit");
// 当登录smart客户端时,md自动启动,一般启动策略前先通过获取功夫md列表检查策略使用到的md是否都已经启动,没有启动可以通过api启动,或者当检测到md崩溃后可以通过api启动
smart.on_alphax_md_status_change(statusChange => console.log("md状态改变", JSON.stringify(statusChange)));
// 输出:
// {
// "process_name": "md_xtp",
// "account_id": "internal",
// "source": "xtp",
// "status": "Started",
// "status_name": "已启动",
// "strategy_platform_type": "alphax"
// }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 启动功夫td
smart.on_init(async function () {
console.log("onInit");
const strategy_map = smart.current_account.strategy_map;
// 当登录smart客户端时,td自动启动,一般启动策略前先通过获取功夫td列表检查策略使用到的td是否都已经启动,没有启动可以通过api启动,或者当检测到td崩溃后可以通过api启动
try {
let strategy = strategy_map["123_alphax"];
let result = await strategy.startTD(smart.current_account.account_id);
console.log("td启动result为", JSON.stringify(result));
// 输出:
// {
// "strategy_platform_type": "alphax",
// "process_name": "td_xtp_15003925",
// "process_type": "td",
// "status": "Started",
// "status_name": "已启动",
// "account_id": "15003925",
// "source": "xtp"
// }
} catch(e) {
console.log(JSON.stringify(e));
// 输出:
// {
// "name": "PluginError",
// "message": "进程已开启!",
// "code": "0001",
// "data": {
// "strategy_platform_type": "alphax",
// "process_name": "td_xtp_15003925",
// "process_type": "td",
// "status": "Started",
// "status_name": "已启动",
// "account_id": "15003925",
// "source": "xtp"
// }
// }
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 启动功夫md
smart.on_init(async function () {
console.log("onInit");
const strategy_map = smart.current_account.strategy_map;
// 当登录smart客户端时,md自动启动,一般启动策略前先通过获取功夫md列表检查策略使用到的md是否都已经启动,没有启动可以通过api启动,或者当检测到md崩溃后可以通过api启动
try {
let strategy = strategy_map["123_alphax"];
let result = await strategy.startMD(smart.current_account.account_id);
console.log("md启动result为", JSON.stringify(result));
// 输出:
// {
// "strategy_platform_type": "alphax",
// "process_name": "md_xtp",
// "process_type": "md",
// "status": "Started",
// "status_name": "已启动",
// "account_id": "internal",
// "source": "xtp"
// }
} catch(e) {
console.log(JSON.stringify(e));
// 输出:
// {
// "name": "PluginError",
// "message": "进程已开启!",
// "code": "0001",
// "data": {
// "strategy_platform_type": "alphax",
// "process_name": "md_xtp_internal",
// "process_type": "md",
// "status": "Started",
// "status_name": "已启动",
// "account_id": "15003925",
// "source": "xtp"
// }
// }
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 监听功夫策略进程状态变化
smart.on_init(async function () {
console.log("onInit");
const strategy_map = smart.current_account.strategy_map;
let strategy = strategy_map["123_alphax"];
await strategy.loadData();//必要的,详见文档
strategy.on_strategy_status_change(statusChange => console.log("statusChange为", statusChange));
});
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 功夫策略启动前向后台策略传参
smart.on_init(async function () {
console.log("onInit");
try {
const strategy_map = smart.current_account.strategy_map;
let strategy = strategy_map["123_alphax"];
// 策略平台落地的参数文件的相对本策略根目录的相对路径,该文件要预先存在
let result = await strategy.postStrategyParamsBeforeStart({ aaa: "bbb" }, "/lib/config.json");
console.log("向后台传参result为", result)
// 输出:{ msg: "success!", code: 200 }
} catch(e) {
console.log(e);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 启动服务端功夫策略
smart.on_init(async function () {
console.log("onInit");
try {
const strategy_map = smart.current_account.strategy_map;
let strategy = strategy_map["123_alphax"];
let status = await strategy.startStrategy();
console.log("status为", JSON.stringify(status));
// 输出:
// {
// "strategy_platform_type": "alphax",
// "process_name": "123",
// "process_type": "strategy",
// "status": "Started",
// "status_name": "已启动",
// "strategy_id": "123"
// }
} catch(e) {
console.log(e);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 获取策略委托列表
smart.on_init(async function () {
console.log("onInit");
try {
const strategy_map = smart.current_account.strategy_map;
let strategy = strategy_map["123_alphax"];
let order_list = strategy.strategy_order_list; // Order对象数组
console.log("order_list[0]为", JSON.stringify(order_list[0]));
// 输出:
// {
// "rcv_time": 1694761372602782700,
// "order_id": "14122189392252567592",
// "source_order_id": "36088540047606776",
// "insert_time": 1694761372602782700,
// "update_time": 1694761372602782700,
// "trading_day": "20230915",
// "instrument_id": "600000",
// "exchange_id": "SSE",
// "account_id": "15003925",
// "client_id": "0",
// "instrument_type": 0,
// "limit_price": 7.12,
// "frozen_price": 7.12,
// "volume": 100,
// "volume_traded": 100,
// "volume_left": 0,
// "tax": 0,
// "commission": 0,
// "status": 5,
// "error_id": 0,
// "error_msg": "",
// "side": 1,
// "offset": 0,
// "price_type": 1,
// "volume_condition": 0,
// "time_condition": 0,
// "parent_order_id": "0",
// "code": "600000.SH",
// "traffic": "alphax",
// "traffic_sub_id": "123",
// "cancel_time": "",
// "order_cancel_client_id": "",
// "order_cancel_xtp_id": "",
// "instrument_name": "浦发银行",
// "trade_amount": 0,
// "xtp_business_type": "XTP_BUSINESS_TYPE_UNKNOWN",
// "xtp_market_type": "XTP_MKT_SH_A",
// "xtp_price_type": "XTP_PRICE_LIMIT",
// "xtp_position_effect_type": "XTP_POSITION_EFFECT_INIT",
// "xtp_side_type": "XTP_SIDE_BUY",
// "xtp_order_status": "XTP_ORDER_STATUS_ALLTRADED",
// "exchange_id_name": "上交所",
// "instrument_type_name": "未知",
// "status_name": "全部成交",
// "side_name": "买",
// "offset_name": "开",
// "price_type_name": "限价",
// "xtp_business_type_name": "未知类型",
// "xtp_market_name": "沪A",
// "xtp_price_type_name": "限价",
// "xtp_position_effect_type_name": "初始值",
// "xtp_side_type_name": "买",
// "xtp_order_status_name": "全部成交",
// "volume_condition_name": "任何数量",
// "time_condition_name": "",
// "traffic_name": "功夫策略",
// "business_type": ""
// }
} catch(e) {
console.log(e);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 获取策略成交列表
smart.on_init(async function () {
console.log("onInit");
try {
const strategy_map = smart.current_account.strategy_map;
let strategy = strategy_map["123_alphax"];
let trade_list = strategy.strategy_trade_list; // Trade对象数组
console.log("trade_list[0]为", JSON.stringify(trade_list[0]));
// 输出:
// {
// "rcv_time": 1694761372603000000,
// "order_id": "14122189392252567592",
// "parent_order_id": 0,
// "trade_time": 1694761372603000000,
// "trading_day": "20230915",
// "instrument_id": "600000",
// "exchange_id": "SSE",
// "account_id": "15003925",
// "client_id": 0,
// "instrument_type": 1,
// "side": 1,
// "offset": 0,
// "price": 7.12,
// "volume": 50,
// "tax": 0,
// "commission": 0,
// "code": "600000.SH",
// "traffic": "alphax",
// "traffic_sub_id": "123",
// "instrument_name": "浦发银行",
// "trade_amount": 356,
// "xtp_business_type": "XTP_BUSINESS_TYPE_UNKNOWN",
// "xtp_market_type": "XTP_MKT_UNKNOWN",
// "xtp_exec_id": "",
// "xtp_report_index": "",
// "xtp_order_exch_id": "",
// "xtp_trade_type": "",
// "xtp_branch_pbu": "",
// "xtp_position_effect_type": "XTP_POSITION_EFFECT_INIT",
// "xtp_side_type": "XTP_SIDE_UNKNOWN",
// "exchange_id_name": "上交所",
// "instrument_type_name": "股票",
// "side_name": "买",
// "offset_name": "开",
// "xtp_business_type_name": "未知类型",
// "xtp_market_name": "未知",
// "xtp_position_effect_type_name": "初始值",
// "xtp_side_type_name": "未知",
// "traffic_name": "功夫策略",
// "xtp_trade_type_name": "",
// "business_type": "",
// "_rowid": "14122189392252567603"
// }
} catch(e) {
console.log(e);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 获取策略持仓列表
smart.on_init(async function () {
console.log("onInit");
try {
const strategy_map = smart.current_account.strategy_map;
let strategy = strategy_map["123_alphax"];
let position_list = strategy.strategy_position_list; // Position对象数组
console.log("position_list[0]为", JSON.stringify(position_list[0]));
// 输出:
// {
// "instrument_id": "000001",
// "instrument_name": "平安银行",
// "instrument_type": 1,
// "exchange_id": "SZE",
// "exchange_id_name": "深交所",
// "direction": 0,
// "direction_name": "多",
// "name_py": "payh",
// "volume": 3000,
// "sellable_volume": 3000,
// "position_cost_price": 11.673333333333334,
// "last_price": 11.27,
// "market_value": 0,
// "unrealized_pnl": -1210.0000000000027,
// "yesterday_volume": 3000,
// "purchase_redeemable_qty": 3000,
// "executable_option": 3000,
// "lockable_position": 0,
// "executable_underlying": 0,
// "locked_position": 0,
// "usable_locked_position": 0,
// "xtp_market_type": "XTP_EXCHANGE_UNKNOWN",
// "xtp_market_name": "",
// "_instrument_id_direction": "000001_0",
// "code": "000001.SZ"
// }
} catch(e) {
console.log(e);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 停止服务端功夫策略
smart.on_init(async function () {
console.log("onInit");
try {
const strategy_map = smart.current_account.strategy_map;
let strategy = strategy_map["123_alphax"];
setTimeout(async function(){
try {
let result = await strategy.stopStrategy();
console.log("result为", JSON.stringify(result));
// 输出:
// {
// "strategy_platform_type": "alphax",
// "process_name": "123",
// "process_type": "strategy",
// "status": "Stopped",
// "status_name": "已停止",
// "strategy_id": "123"
// }
} catch(e) {
console.log(e);
}
}, 3000);
} catch(e) {
console.log(e);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29