[关闭]
@liaoliaopro 2017-07-08T06:27:03.000000Z 字数 20433 阅读 1083

掘金3策略API定义


修改日志:


设计原则与目标:

约定

典型场景

下面通过一些典型场景来说明api如何使用。

场景1:策略每日定时执行,无需数据事件驱动

典型如选股交易策略。比如,策略每日收盘前10分钟执行:选股->决策逻辑->交易->退出。可能无需订阅实时数据。实现如下

  1. def init(context):
  2. schedule(algo, date_rule=daily, time_rule='14:50:00')
  3. def algo(context):
  4. f = get_fundmentals(fields='revenue,pe_ratio', filter='pe_ratio>55 and pe_ratio<60', order_by='-revenue', count=10)
  5. context.symbols = f.columns.values
  6. # 全仓平均买入每一个标的
  7. percent = 1.0/len(context.symbols)
  8. for stock in context.symbols:
  9. order_target_percent(stock, percent, position_side=PositionSide.Long)
场景2:策略由订阅代码的单个数据事件驱动

同掘金2的事件模式。策略订阅的每个代码的每一个bar,都会触发策略逻辑

  1. def init(context):
  2. subscribe('SHSE.600000', '1m')
  3. def on_bar(context, bars)
  4. # print current bar
  5. print bars
场景3:策略由单个代码的时间序列数据事件驱动

策略订阅代码时指定数据窗口大小与周期,平台创建数据滑动窗口,加载初始数据,并在新的bar到来时自动刷新数据。bar事件触发时,策略可以取到订阅代码的准备好的时间序列数据。

  1. def init(context):
  2. subscribe('SHSE.600000', '1m', count=50)
  3. def on_bar(context, bars)
  4. # print current bar.
  5. print bars
  6. # print 'close' field of last 50 bars
  7. print context.data('SHSE.600000', '1m', count=50, fields='close')
场景4:策略由多个代码的时间序列数据事件驱动

同场景3, 区别是策略订阅多个代码,并且要求同一频度的数据到齐后,再触发事件。

  1. def init(context):
  2. subscribe('SHSE.600000,SZSE.000001', '1m', count=50, wait_group=True)
  3. def on_bar(context, bars)
  4. # print current bar of SHSE.600000, SZSE.000001.
  5. print bars
  6. # print last 50 bars. both series are updated with latest bars.
  7. print context.data('SHSE.600000', '1m', count=50, fields='close')
  8. print context.data('SZSE.000001', '1m', count=50, fields='close')
场景5:策略在默认账户交易,无需指定交易账户

如果策略只关联一个账户,该账户是策略的默认账户。

  1. def init(context):
  2. subscribe('SHSE.600000,SZSE.000001', '1m')
  3. def on_bar(context, bars)
  4. order_volume(bars[0].symbol, 10000)
场景6:策略在多个账户交易,显式指定交易账户
  1. def init(context):
  2. subscribe('SHSE.600000,SZSE.000001', '1m')
  3. def on_bar(context, bars)
  4. order_volume(bars[0].symbol, 10000, account=account('account_1'))
  5. order_volume(bars[1].symbol, 10000, account=account('account_2'))
场景7:回测模式与实时模式,策略如何启动。

掘金3策略只有两种模式,回测模式(backtest)与实时模式(live)。在加载策略时指定mode参数。

  1. # for backtest mode
  2. run('strategy.py', mode=backtest, config, token)
  3. # for live mode
  4. run('strategy.py', mode=live, config, token)
场景8:只提取数据研究

无需实时数据驱动策略,无需交易下单,只是提取数据的场景。比如,在shell交互环境提取数据。
token用户函数调用的身份验证,token不正确,函数调用会抛出异常

  1. from gmsdk import set_token, history
  2. set_token('xxxx')
  3. history('SHSE.600000', '1d', 'open,high,low,close', '2015-01-01','2015-12-31')
场景9:一个均线突破策略示例

13行代码完成一个均线突破策略.

  1. def init(context):
  2. context.FAST = 30
  3. context.SLOW= 60
  4. context.symbol = 'SHSE.600000'
  5. subscribe(context.symbol, '1m', count=context.SLOW)
  6. def on_bar(context, bars)
  7. prices = context.data('SHSE.600000', '1m', context.SLOW, fields='close')
  8. fast_avg = talib.SMA(prices, context.FAST)
  9. slow_avg = talib.SMA(prices, context.SLOW)
  10. # 均线下穿,清仓
  11. if cross(slow_avg, fast_avg):
  12. order_target_percent(context.symbol, 0)
  13. # 均线上穿,满仓
  14. if cross(fast_avg, slow_avg):
  15. order_target_percent(context.symbol, 1)

基本API

init - 策略初始化

初始化策略,策略启动时自动执行。可以在这里初始化策略配置参数。

  1. init(context)
schedule - 策略定时执行

在自动时间执行策略算法,通常用于选股类型策略

  1. schedule(algo_func, date_rule=daily | weekly | monthly, time_rule)

数据订阅API

subscribe - 订阅行情

订阅行情,可以指定symbol, 数据滑窗大小,以及是否需要等待全部代码的数据到齐再触发事件。

  1. subscribe(symbols=[symbol_1...symbol_n], frequency='1d', count=1, wait_group=False, unsubscribe_previous=False)

wait_group: 是否等待全部相同频度订阅的symbol到齐再触发on_bar事件。
unsubscribe_previous: 是否取消过去订阅的symbols

unsubscribe - 取消行情订阅

取消行情订阅,默认取消所有已订阅行情

  1. unsubscribe(symbols='*', frequency='1d')

数据事件

on_bar - bar数据推送事件
  1. on_bar(context, bar)
on_tick - tick数据推送事件
  1. on_tick(context, tick)
on_bod - 开市事件

市场开市时触发本事件,可以在这里执行盘前初始化逻辑

  1. on_bod(context, exchange, time)
on_eod - 收市事件

市场收市时触发本事件,可以在这里执行盘后清理逻辑

  1. on_eod(context, exchange, time)

数据查询API

current - 查询当前行情快照

查询当前行情快照,返回tick数据。回测时,返回回测时间点的tick数据(注:可能用当前数据bar模拟,基于效率考虑)。

  1. current(symbol)
history- 查询历史行情
  1. history(symbol, frequency, start_time, end_time, fields=None, skip_suspended=True, fill_missing=None | NaN | Last, adjust='pre' | 'post' | None, df=False)
  2. history_n(symbol, frequency, count, date=now(), fields=None, skip_suspended=True, fill_missing=None | NaN | Last, adjust='pre' | 'post' | None, df=False)
get_fundmentals - 查询基本面数据
  1. get_fundmentals(table, fields, filter, order_by=None, count=None, group_by=None, having=None)
get_instruments - 查询交易标的Instrument
  1. get_instruments(exchange, sec_type, name=None, skip_suspended=True, skip_st=True, fields=None, start_date=None, end_date=None)
get_constituents - 查询指数成分股
  1. get_constituents(index, fields='symbol, weight', start_date=None, end_date=None)
get_sector - 查询板块股票列表
  1. get_sector(code, start_date=None, end_date=None)
get_industry - 查询行业股票列表
  1. get_industry(code, start_date=None, end_date=None)
get_concept - 查询概念股票列表
  1. get_concept(code, start_date=None, end_date=None)
get_trading_dates - 查询交易日列表
  1. get_trading_dates(exchange, start_date, end_date)
get_previous_trading_date - 查询上一个交易日
  1. get_previous_trading_date(exchange, date)
get_next_trading_date - 查询下一个交易日
  1. get_next_trading_date(exchange, date)
get_divident - 查询分红送配
  1. get_divident(symbl, start_date, end_date)
get_benchmark_return - 查询标的指定期间的基准收益率
  1. get_benchmark_return(symbol, start_time, end_time, frequency='1d')
... - 待扩展的其他函数

交易API

order_volume - 按指定量委托
  1. order_volume(symbol, volume, price=0, side=OrderSide, style=OrderType, position_effect=PositionEffect, account=account())
order_value - 按指定价值委托
  1. order_value(symbol, value, price=0, side=OrderSide, style=OrderType, position_effect=PositionEffect, account=account())
order_percent - 按指定比例委托
  1. order_percent(symbol, percent, price=0, side=OrderSide, style=OrderType, position_effect=PositionEffect, account=account())
order_target_volume - 调仓到目标持仓量
  1. order_target_volume(symbol, volume, price=0, side=PositionSide, style=OrderType, account=account())
order_target_value - 调仓到目标持仓额
  1. order_target_value(symbol, value, price=0, side=PositionSide, style=OrderType, account=account())
order_target_percent - 调仓到目标持仓比例
  1. order_target_percent(symbol, percent, price=0, side=PositionSide, style=OrderType, account=account())
order_batch - 批量委托接口
  1. order_batch([order_1...order_n], combine=False, account=account())
order_cancel - 撤销委托
  1. order_cancel([order_1...order_n])
order_cancel_all - 撤销所有委托
  1. order_cancel_all()
order_close_all - 平当前所有可平持仓
  1. order_close_all()
get_unfinished_orders - 查询日内全部未结委托
  1. get_unfinished_orders()
get_orders - 查询日内全部委托
  1. get_orders()
account - 查询策略关联的交易账户
  1. account(account_id='default', all=False)
set_runtime_config - 设置动态参数
  1. set_runtime_config([config 1...config n])

交易事件

on_order_status - 委托状态更新事件
  1. on_order_status(context, order)
on_execrpt - 委托执行回报事件
  1. on_execrpt(context, execrpt)

其它API

set_token - 设置用户的token,用于身份认证

用户有时只需要提取数据,set_token后就可以直接调用数据函数,无需编写策略结构。
如果token不合法,访问需要身份验证的函数会抛出异常。

  1. set_token(token)
now - 当前时间函数

回测过程中,now返回回测的当前时间点。
实时过程中,now返回wallclock的当前时间点。

  1. now()
log - 日志函数
  1. log(level, messge)
get_strerror - 查询错误码的错误描述信息
  1. get_strerror(code)
get_version - 查询api版本
  1. get_version()

其它事件

on_runtime_config - 运行时参数变更事件
  1. on_runtime_config(context, config)
on_backtest_finished - 回测结束事件
  1. on_backtest_finished(context, backtest_result)
on_error - 错误事件
  1. on_error(context, code, info)
on_shutdown - 策略退出事件
  1. on_shutdown(context, code, info)

工具API

cross - 均线突破检测函数
  1. cross(series1, series2)

基本数据结构定义

Context - 策略运行上下文环境对象
  1. class Context():
  2. now # current timestamp
  3. symbols # subscribed symbols
  4. runtime_configs # runtime configs, dictionary
  5. data(symbol, frequency, count, fields) # sliding window for subscribed bars/ticks
Account - 交易账户对象
  1. class Account():
  2. cash
  3. positions

交易类结构定义

Order - 委托对象
  1. //委托定义
  2. message Order {
  3. string strategy_id = 1; //策略ID
  4. string account_id = 2; //账号ID
  5. string username = 3; //账户登录名
  6. string cl_ord_id = 4; //委托客户端ID
  7. string order_id = 5; //委托柜台ID
  8. string ex_ord_id = 6; //委托交易所ID
  9. string symbol = 7; //symbol
  10. int32 position_effect = 10; //开平标志,取值参考enum PositionEffect
  11. int32 side = 11; //买卖方向,取值参考enum OrderSide
  12. int32 order_type = 12; //委托类型,取值参考enum OrderType
  13. int32 order_duration = 13; //委托类型,取值参考enum OrderDuration
  14. int32 order_qualifier = 14; //委托类型,取值参考enum OrderQualifier
  15. int32 order_src = 15; //委托来源,取值参考enum OrderSrc
  16. int32 status = 16; //委托状态,取值参考enum OrderStatus
  17. int32 ord_rej_reason = 17; //委托拒绝原因,取值参考enum OrderRejectReason
  18. string ord_rej_reason_detail = 18; //委托拒绝原因描述
  19. double price = 19; //委托价格
  20. double stop_price = 20; //委托止损/止盈触发价格
  21. double volume = 21; //委托量
  22. double volume_nav_ratio = 22; //委托量与净值比
  23. double filled_volume = 23; //已成量
  24. double filled_vwap = 24; //已成均价
  25. double filled_amount = 25; //已成金额
  26. google.protobuf.Timestamp created_at = 26[(gogoproto.stdtime) = true]; //委托创建时间
  27. google.protobuf.Timestamp updated_at = 27[(gogoproto.stdtime) = true]; //委托更新时间
  28. }
ExecRpt - 执行回报对象
  1. //委托执行回报定义
  2. message ExecRpt {
  3. string strategy_id = 1; //策略ID
  4. string account_id = 2; //账号ID
  5. string username = 3; //账户登录名
  6. string cl_ord_id = 4; //委托客户端ID
  7. string order_id = 5; //委托柜台ID
  8. string exec_id = 6; //委托回报ID
  9. string symbol = 7; //symbol
  10. int32 position_effect = 10; //开平标志,取值参考enum PositionEffect
  11. int32 side = 11; //买卖方向,取值参考enum OrderSide
  12. int32 ord_rej_reason = 12; //委托拒绝原因,取值参考enum OrderRejectReason
  13. string ord_rej_reason_detail = 13; //委托拒绝原因描述
  14. int32 exec_type = 14; //执行回报类型, 取值参考enum ExecType
  15. double price = 15; //委托成交价格
  16. double volume = 16; //委托成交量
  17. double amount = 17; //委托成交金额
  18. google.protobuf.Timestamp created_at =18[(gogoproto.stdtime) = true]; //回报创建时间
  19. }
Cash - 资金对象
  1. //资金定义
  2. message Cash {
  3. string account_id = 1; //账号ID
  4. string username = 2; //账户登录名
  5. int32 currency = 3; //币种
  6. double nav = 4; //净值(cum_inout + cum_pnl + fpnl - cum_commission)
  7. double pnl = 5; //净收益(nav-cum_inout)
  8. double fpnl = 6; //浮动盈亏(sum(each position fpnl))
  9. double frozen = 7; //持仓占用资金
  10. double order_frozen = 8; //挂单冻结资金
  11. double available = 9; //可用资金
  12. //no leverage: available=(cum_inout + cum_pnl - cum_commission - frozen - order_frozen)
  13. //has leverage: fpnl =(fpnl>0 ? fpnl : (frozen < |fpnl|) ? (frozenr-|fpnl|) : 0)
  14. // available=(cum_inout + cum_pnl - cum_commission - frozen - order_frozen + fpnl)
  15. double cum_inout = 10; //累计出入金
  16. double cum_trade = 11; //累计交易额
  17. double cum_pnl = 12; //累计平仓收益(没扣除手续费)
  18. double cum_commission = 13; //累计手续费
  19. double last_trade = 14; //上一次交易额
  20. double last_pnl = 15; //上一次收益
  21. double last_commission = 16; //上一次手续费
  22. double last_inout = 17; //上一次出入金
  23. int32 change_reason = 18; //资金变更原因,取值参考enum CashPositionChangeReason
  24. string change_event_id = 19; //触发资金变更事件的ID
  25. google.protobuf.Timestamp created_at = 20[(gogoproto.stdtime) = true]; //资金初始时间
  26. google.protobuf.Timestamp updated_at = 21[(gogoproto.stdtime) = true]; //资金变更时间
  27. }
Position - 持仓对象
  1. //持仓定义
  2. message Position{
  3. string account_id = 1; //账号ID
  4. string username = 2; //账户登录名
  5. string symbol = 3; //symbol
  6. int32 side = 6; //持仓方向,取值参考enum PositionSide
  7. double volume = 7; //总持仓量; 昨持仓量(volume-volume_today)
  8. double volume_today = 8; //今日持仓量
  9. double vwap = 9; //持仓均价
  10. double amount = 10; //持仓额(volume*vwap*multiplier)
  11. double price = 11; //当前行情价格
  12. double fpnl = 12; //持仓浮动盈亏((price-vwap)*volume*multiplier)
  13. double cost = 13; //持仓成本(vwap*volume*multiplier*margin_ratio)
  14. double order_frozen = 14; //挂单冻结仓位
  15. double order_frozen_today = 15; //挂单冻结今仓仓位
  16. double available = 16; //可平总仓位(volume-order_frozen); 可平昨仓位(available-available_today)
  17. double available_today = 17; //可平今仓位(volume_today-order_frozen_today)
  18. double last_price = 18; //上一次成交价
  19. double last_volume = 19; //上一次成交量
  20. double last_inout = 20; //上一次出入持仓量
  21. int32 change_reason = 21; //仓位变更原因,取值参考enum CashPositionChangeReason
  22. string change_event_id = 22; //触发资金变更事件的ID
  23. google.protobuf.Timestamp created_at = 23[(gogoproto.stdtime) = true]; //建仓时间
  24. google.protobuf.Timestamp updated_at = 24[(gogoproto.stdtime) = true]; //仓位变更时间
  25. }
Indicator - 绩效指标对象
  1. //绩效指标定义
  2. message Indicator{
  3. string account_id = 1; //账号ID
  4. double pnl_ratio = 2; //累计收益率(pnl/cum_inout)
  5. double pnl_ratio_annual = 3; //年化收益率
  6. double sharp_ratio = 4; //夏普比率
  7. double max_drawdown = 5; //最大回撤
  8. double risk_ratio = 6; //风险比率
  9. int32 open_count = 7; //开仓次数
  10. int32 close_count = 8; //平仓次数
  11. int32 win_count = 9; //盈利次数
  12. int32 lose_count = 10; //亏损次数
  13. double win_ratio = 11; //胜率
  14. google.protobuf.Timestamp created_at = 12[(gogoproto.stdtime) = true]; //指标创建时间
  15. google.protobuf.Timestamp updated_at = 13[(gogoproto.stdtime) = true]; //指标变更时间
  16. }
IndicatorDuration - 按周期统计的绩效指标对象
  1. //按周期统计的指标(目前只有日频和分钟频)
  2. message IndicatorDuration {
  3. string account_id = 1; //账号ID
  4. //周期快照类指标
  5. double pnl_ratio = 2; //收益率快照
  6. double pnl = 3; //收益快照
  7. double cash = 4; //资金快照
  8. double fpnl = 5; //浮盈浮亏快照
  9. double frozen = 6; //持仓冻结快照
  10. repeated core.api.Position positions = 7; //持仓快照
  11. //周期累计类指标
  12. double cum_pnl = 8; //周期累计盈亏
  13. double cum_buy = 9; //周期累计买入额
  14. double cum_sell = 10; //周期累计卖出额
  15. google.protobuf.Duration duration = 11[(gogoproto.stdduration) = true]; //指标统计周期
  16. google.protobuf.Timestamp created_at = 12[(gogoproto.stdtime) = true]; //指标创建时间
  17. google.protobuf.Timestamp updated_at = 13[(gogoproto.stdtime) = true]; //指标创建时间
  18. }
RuntimeConfig - 运行时参数对象
  1. //动态参数
  2. message RuntimeConfig {
  3. string key = 1; //参数键
  4. double value = 2; //参数值
  5. double min = 3; //可设置的最小值
  6. double max = 4; //可设置的最大值
  7. string name = 5; //参数名
  8. string intro = 6; //参数说明
  9. string group = 7; //组名
  10. bool readonly = 8; //是否只读
  11. }

数据类结构定义

Tick- Tick对象

Tick - Tick对象

  1. message Tick {
  2. string symbol = 1;
  3. float open = 2;
  4. float high = 3;
  5. float low = 4;
  6. float price = 5;
  7. repeated Quote quotes = 6;
  8. double cum_volume = 7;
  9. double cum_amount = 8;
  10. int64 cum_position = 9;
  11. double last_amount = 10;
  12. int32 last_volume = 11;
  13. int32 trade_type = 12;
  14. google.protobuf.Timestamp created_at = 13[(gogoproto.stdtime) = true];
  15. }
Bar - Bar对象
  1. message Bar {
  2. string symbol = 1;
  3. uint32 frequency = 2;
  4. float open = 3;
  5. float high = 4;
  6. float low = 5;
  7. float close = 6;
  8. double volume = 7;
  9. double amount = 8;
  10. int64 position = 9;
  11. float pre_close = 10;
  12. google.protobuf.Timestamp bob = 11[(gogoproto.stdtime) = true]; // begin of bar
  13. google.protobuf.Timestamp eob = 12[(gogoproto.stdtime) = true]; // end of bar
  14. }
Quote - 报价对象
  1. message Quote {
  2. float bid_p = 1;
  3. int32 bid_v = 2;
  4. float ask_p = 3;
  5. int32 ask_v = 4;
  6. }
OrderBook - OrderBook对象
  1. message OrderBook {
  2. string symbol = 1;
  3. repeated Quote quotes = 2;
  4. google.protobuf.Timestamp created_at = 3[(gogoproto.stdtime) = true];
  5. }
Trade - Trade对象
  1. message Trade {
  2. string symbol = 1;
  3. float price = 2;
  4. int32 last_volume = 3;
  5. double last_amount = 4;
  6. double cum_volume = 5;
  7. double cum_amount = 6;
  8. int32 trade_type = 7;
  9. google.protobuf.Timestamp created_at = 8[(gogoproto.stdtime) = true];
  10. }
InstrumentInfo - 标的基本信息对象
  1. message InstrumentInfo {
  2. string symbol = 1;
  3. int32 sec_type = 2;
  4. string exchange = 3;
  5. string sec_id = 4;
  6. string sec_name = 5;
  7. string sec_abbr = 6;
  8. google.protobuf.Timestamp listed_date = 7[(gogoproto.stdtime) = true];
  9. google.protobuf.Timestamp delisted_date = 8[(gogoproto.stdtime) = true];
  10. }
Instrument - 标的详细信息对象
  1. message Instrument {
  2. string symbol = 1;
  3. int32 is_st = 2;
  4. int32 is_suspended = 3;
  5. double multiplier = 4;
  6. double margin_ratio = 5;
  7. double price_tick = 6;
  8. float settle_price = 7;
  9. int64 position = 8;
  10. float pre_close = 9;
  11. double upper_limit = 10;
  12. double lower_limit = 11;
  13. double adj_factor = 12;
  14. google.protobuf.Timestamp created_at = 13[(gogoproto.stdtime) = true];
  15. }
Divident - 分红送配对象
  1. message Divident {
  2. string symbol = 1;
  3. double cash_div = 2;
  4. double share_div_ratio = 3;
  5. double share_trans_ratio = 4;
  6. double allotment_ratio = 5;
  7. double allotment_price = 6;
  8. google.protobuf.Timestamp created_at = 7[(gogoproto.stdtime) = true];
  9. }
VirtualContract- 连续合约对象
  1. message VirtualContract {
  2. string vsymbol = 1;
  3. string symbol = 2;
  4. google.protobuf.Timestamp created_at = 3[(gogoproto.stdtime) = true];
  5. }

枚举常量定义

OrderStatus - 委托状态
  1. //委托状态
  2. enum OrderStatus {
  3. OrderStatus_Unknown = 0;
  4. OrderStatus_New = 1; //已报
  5. OrderStatus_PartiallyFilled = 2; //部成
  6. OrderStatus_Filled = 3; //已成
  7. OrderStatus_DoneForDay = 4; //
  8. OrderStatus_Canceled = 5; //已撤
  9. OrderStatus_PendingCancel = 6; //待撤
  10. OrderStatus_Stopped = 7; //
  11. OrderStatus_Rejected = 8; //已拒绝
  12. OrderStatus_Suspended = 9; //挂起
  13. OrderStatus_PendingNew = 10; //待报
  14. OrderStatus_Calculated = 11; //
  15. OrderStatus_Expired = 12; //已过期
  16. OrderStatus_AcceptedForBidding = 13; //
  17. OrderStatus_PendingReplace = 14; //
  18. }
OrderSide - 委托方向
  1. //委托方向
  2. enum OrderSide {
  3. OrderSide_Unknown = 0;
  4. OrderSide_Buy = 1; //买入
  5. OrderSide_Sell = 2; //卖出
  6. }
OrderType - 委托类型
  1. //委托类型
  2. enum OrderType {
  3. OrderType_Unknown = 0;
  4. OrderType_count = 1; //限价委托
  5. OrderType_Market = 2; //市价委托
  6. OrderType_Stop = 3; //止损止盈委托
  7. }
OrderDuration - 委托时间属性
  1. //委托时间属性
  2. enum OrderDuration {
  3. OrderDuration_Unknown = 0;
  4. OrderDuration_FAK = 1; //即时成交剩余撤销(fill and kill)
  5. OrderDuration_FOK = 2; //即时全额成交或撤销(fill or kill)
  6. OrderDuration_GFD = 3; //当日有效(good for day)
  7. OrderDuration_GFS = 4; //本节有效(good for section)
  8. OrderDuration_GTD = 5; //指定日期前有效(goodl till date)
  9. OrderDuration_GTC = 6; //撤销前有效(good till cancel)
  10. OrderDuration_GFA = 7; //集合竞价前有效(good for auction)
  11. }
OrderQualifier - 委托成交属性
  1. //委托成交属性
  2. enum OrderQualifier {
  3. OrderQualifier_Unknown = 0;
  4. OrderQualifier_BOC = 1; //对方最优价格(best of counterparty)
  5. OrderQualifier_BOP = 2; //己方最优价格(best of party)
  6. OrderQualifier_B5TC = 3; //最优五档剩余撤销(best 5 then cancel)
  7. OrderQualifier_B5TL = 4; //最优五档剩余转限价(best 5 then count)
  8. }
ExecType - 执行回报类型
  1. //委托回报类型
  2. enum ExecType {
  3. ExecType_Unknown = 0;
  4. ExecType_New = 1; //已报
  5. ExecType_DoneForDay = 4; //
  6. ExecType_Canceled = 5; //已撤销
  7. ExecType_PendingCancel = 6; //待撤销
  8. ExecType_Stopped = 7; //
  9. ExecType_Rejected = 8; //已拒绝
  10. ExecType_Suspended = 9; //挂起
  11. ExecType_PendingNew = 10; //待报
  12. ExecType_Calculated = 11; //
  13. ExecType_Expired = 12; //过期
  14. ExecType_Restated = 13; //
  15. ExecType_PendingReplace = 14; //
  16. ExecType_Trade = 15; //成交
  17. ExecType_TradeCorrect = 16; //
  18. ExecType_TradeCancel = 17; //
  19. ExecType_OrderStatus = 18; //委托状态
  20. ExecType_CancelRejected = 19; //撤单被拒绝
  21. }
PositionEffect - 开平仓类型
  1. //开平标志
  2. enum PositionEffect {
  3. PositionEffect_Unknown = 0;
  4. PositionEffect_Open = 1; //开仓
  5. PositionEffect_Close = 2; //平仓,具体语义取决于对应的交易所
  6. PositionEffect_CloseToday = 3; //平今仓
  7. PositionEffect_CloseYesterday = 4; //平昨仓
  8. }
PositionSide - 持仓方向
  1. //持仓方向
  2. enum PositionSide {
  3. PositionSide_Unknown = 0;
  4. PositionSide_Long = 1; //多方向
  5. PositionSide_Short = 2; //空方向
  6. }

策略加载

run - 运行策略
  1. run(strategy, mode, config, token)
stop - 停止策略
  1. stop()

指标API

集成ta-lib138个指标函数

  1. 附表:ta-lib支持指标集合
  2. AD Chaikin A/D Line
  3. ADOSC Chaikin A/D Oscillator
  4. ADX Average Directional Movement Index
  5. ADXR Average Directional Movement Index Rating
  6. APO Absolute Price Oscillator
  7. AROON Aroon
  8. AROONOSC Aroon Oscillator
  9. ATR Average True Range
  10. AVGPRICE Average Price
  11. BBANDS Bollinger Bands
  12. BETA Beta
  13. BOP Balance Of Power
  14. CCI Commodity Channel Index
  15. CDL2CROWS Two Crows
  16. CDL3BLACKCROWS Three Black Crows
  17. CDL3INSIDE Three Inside Up/Down
  18. CDL3LINESTRIKE Three-Line Strike
  19. CDL3OUTSIDE Three Outside Up/Down
  20. CDL3STARSINSOUTH Three Stars In The South
  21. CDL3WHITESOLDIERS Three Advancing White Soldiers
  22. CDLABANDONEDBABY Abandoned Baby
  23. CDLADVANCEBLOCK Advance Block
  24. CDLBELTHOLD Belt-hold
  25. CDLBREAKAWAY Breakaway
  26. CDLCLOSINGMARUBOZU Closing Marubozu
  27. CDLCONCEALBABYSWALL Concealing Baby Swallow
  28. CDLCOUNTERATTACK Counterattack
  29. CDLDARKCLOUDCOVER Dark Cloud Cover
  30. CDLDOJI Doji
  31. CDLDOJISTAR Doji Star
  32. CDLDRAGONFLYDOJI Dragonfly Doji
  33. CDLENGULFING Engulfing Pattern
  34. CDLEVENINGDOJISTAR Evening Doji Star
  35. CDLEVENINGSTAR Evening Star
  36. CDLGAPSIDESIDEWHITE Up/Down-gap side-by-side white lines
  37. CDLGRAVESTONEDOJI Gravestone Doji
  38. CDLHAMMER Hammer
  39. CDLHANGINGMAN Hanging Man
  40. CDLHARAMI Harami Pattern
  41. CDLHARAMICROSS Harami Cross Pattern
  42. CDLHIGHWAVE High-Wave Candle
  43. CDLHIKKAKE Hikkake Pattern
  44. CDLHIKKAKEMOD Modified Hikkake Pattern
  45. CDLHOMINGPIGEON Homing Pigeon
  46. CDLIDENTICAL3CROWS Identical Three Crows
  47. CDLINNECK In-Neck Pattern
  48. CDLINVERTEDHAMMER Inverted Hammer
  49. CDLKICKING Kicking
  50. CDLKICKINGBYLENGTH Kicking - bull/bear determined by the longer marubozu
  51. CDLLADDERBOTTOM Ladder Bottom
  52. CDLLONGLEGGEDDOJI Long Legged Doji
  53. CDLLONGLINE Long Line Candle
  54. CDLMARUBOZU Marubozu
  55. CDLMATCHINGLOW Matching Low
  56. CDLMATHOLD Mat Hold
  57. CDLMORNINGDOJISTAR Morning Doji Star
  58. CDLMORNINGSTAR Morning Star
  59. CDLONNECK On-Neck Pattern
  60. CDLPIERCING Piercing Pattern
  61. CDLRICKSHAWMAN Rickshaw Man
  62. CDLRISEFALL3METHODS Rising/Falling Three Methods
  63. CDLSEPARATINGLINES Separating Lines
  64. CDLSHOOTINGSTAR Shooting Star
  65. CDLSHORTLINE Short Line Candle
  66. CDLSPINNINGTOP Spinning Top
  67. CDLSTALLEDPATTERN Stalled Pattern
  68. CDLSTICKSANDWICH Stick Sandwich
  69. CDLTAKURI Takuri (Dragonfly Doji with very long lower shadow)
  70. CDLTASUKIGAP Tasuki Gap
  71. CDLTHRUSTING Thrusting Pattern
  72. CDLTRISTAR Tristar Pattern
  73. CDLUNIQUE3RIVER Unique 3 River
  74. CDLUPSIDEGAP2CROWS Upside Gap Two Crows
  75. CDLXSIDEGAP3METHODS Upside/Downside Gap Three Methods
  76. CMO Chande Momentum Oscillator
  77. CORREL Pearsons Correlation Coefficient (r)
  78. DEMA Double Exponential Moving Average
  79. DX Directional Movement Index
  80. EMA Exponential Moving Average
  81. HT_DCPERIOD Hilbert Transform - Dominant Cycle Period
  82. HT_DCPHASE Hilbert Transform - Dominant Cycle Phase
  83. HT_PHASOR Hilbert Transform - Phasor Components
  84. HT_SINE Hilbert Transform - SineWave
  85. HT_TRENDLINE Hilbert Transform - Instantaneous Trendline
  86. HT_TRENDMODE Hilbert Transform - Trend vs Cycle Mode
  87. KAMA Kaufman Adaptive Moving Average
  88. LINEARREG Linear Regression
  89. LINEARREG_ANGLE Linear Regression Angle
  90. LINEARREG_INTERCEPT Linear Regression Intercept
  91. LINEARREG_SLOPE Linear Regression Slope
  92. MA All Moving Average
  93. MACD Moving Average Convergence/Divergence
  94. MACDEXT MACD with controllable MA type
  95. MACDFIX Moving Average Convergence/Divergence Fix 12/26
  96. MAMA MESA Adaptive Moving Average
  97. MAX Highest value over a specified period
  98. MAXINDEX Index of highest value over a specified period
  99. MEDPRICE Median Price
  100. MFI Money Flow Index
  101. MIDPOINT MidPoint over period
  102. MIDPRICE Midpoint Price over period
  103. MIN Lowest value over a specified period
  104. MININDEX Index of lowest value over a specified period
  105. MINMAX Lowest and highest values over a specified period
  106. MINMAXINDEX Indexes of lowest and highest values over a specified period
  107. MINUS_DI Minus Directional Indicator
  108. MINUS_DM Minus Directional Movement
  109. MOM Momentum
  110. NATR Normalized Average True Range
  111. OBV On Balance Volume
  112. PLUS_DI Plus Directional Indicator
  113. PLUS_DM Plus Directional Movement
  114. PPO Percentage Price Oscillator
  115. ROC Rate of change : ((price/prevPrice)-1)*100
  116. ROCP Rate of change Percentage: (price-prevPrice)/prevPrice
  117. ROCR Rate of change ratio: (price/prevPrice)
  118. ROCR100 Rate of change ratio 100 scale: (price/prevPrice)*100
  119. RSI Relative Strength Index
  120. SAR Parabolic SAR
  121. SAREXT Parabolic SAR - Extended
  122. SMA Simple Moving Average
  123. STDDEV Standard Deviation
  124. STOCH Stochastic
  125. STOCHF Stochastic Fast
  126. STOCHRSI Stochastic Relative Strength Index
  127. SUM Summation
  128. T3 Triple Exponential Moving Average (T3)
  129. TEMA Triple Exponential Moving Average
  130. TRANGE True Range
  131. TRIMA Triangular Moving Average
  132. TRIX 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA
  133. TSF Time Series Forecast
  134. TYPPRICE Typical Price
  135. ULTOSC Ultimate Oscillator
  136. VAR Variance
  137. WCLPRICE Weighted Close Price
  138. WILLR Williams %R
  139. WMA Weighted Moving Average
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注