Skip to content

Commit

Permalink
add is_st_stock && is_suspended
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWang committed Mar 29, 2017
1 parent e7c63a5 commit a6d6002
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
22 changes: 2 additions & 20 deletions docs/source/api/base_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -630,30 +630,12 @@ get_yield_curve - 收益率曲线
is_suspended - 全天停牌判断
------------------------------------------------------

.. py:function:: is_suspended(order_book_id, count)
判断某只股票是否全天停牌。

:param str order_book_id: 某只股票的代码或股票代码列表,可传入单只股票的order_book_id, symbol

:param int count: 回溯获取的数据个数。默认为当前能够获取到的最近的数据

:return: count为1时 `bool`; count>1时 `pandas.DataFrame`
.. autofunction:: is_suspended(order_book_id)

is_st_stock - ST股判断
------------------------------------------------------

.. py:function:: is_st_stock(order_book_id, count=1)
判断一只或多只股票在一段时间内是否为ST股(包括ST与*ST)。

ST股是有退市风险因此风险比较大的股票,很多时候您也会希望判断自己使用的股票是否是'ST'股来避开这些风险大的股票。另外,我们目前的策略比赛也禁止了使用'ST'股。

:param str order_book_id: 某只股票的代码或股票代码列表,可传入单只股票的order_book_id, symbol

:param int count: 回溯获取的数据个数。默认为当前能够获取到的最近的数据

:return: count为1时 `bool`; count>1时 `pandas.DataFrame`
.. autofunction:: is_st_stock(order_book_id)

其他方法
======================================================
Expand Down
2 changes: 1 addition & 1 deletion rqalpha/api/api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def history_bars(order_book_id, bar_count, frequency, fields=None, skip_suspende
T日handle_bar T日当前minute bar
========================= ===================================================
:param order_book_id: 合约代码或者合约代码列表
:param order_book_id: 合约代码
:type order_book_id: `str`
:param int bar_count: 获取的历史数据数量,必填项
Expand Down
43 changes: 43 additions & 0 deletions rqalpha/api/api_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,49 @@ def order_target_percent(id_or_ins, percent, style=MarketOrder()):
return order_value(order_book_id, account.total_value * percent - position.market_value, style)


@export_as_api
@ExecutionContext.enforce_phase(EXECUTION_PHASE.ON_INIT,
EXECUTION_PHASE.BEFORE_TRADING,
EXECUTION_PHASE.ON_BAR,
EXECUTION_PHASE.AFTER_TRADING,
EXECUTION_PHASE.SCHEDULED)
@apply_rules(verify_that('order_book_id').is_valid_instrument(),
verify_that('count').is_greater_than(0))
def is_suspended(order_book_id):
"""
判断某只股票是否全天停牌。
:param str order_book_id: 某只股票的代码或股票代码,可传入单只股票的order_book_id, symbol
:return: `bool`
"""
dt = Environment.get_instance().calendar_dt.date()
order_book_id = assure_stock_order_book_id(order_book_id)
return Environment.get_instance().data_proxy.is_suspended(order_book_id, dt)


@export_as_api
@ExecutionContext.enforce_phase(EXECUTION_PHASE.ON_INIT,
EXECUTION_PHASE.BEFORE_TRADING,
EXECUTION_PHASE.ON_BAR,
EXECUTION_PHASE.AFTER_TRADING,
EXECUTION_PHASE.SCHEDULED)
@apply_rules(verify_that('order_book_id').is_valid_instrument())
def is_st_stock(order_book_id):
"""
判断股票在一段时间内是否为ST股(包括ST与*ST)。
ST股是有退市风险因此风险比较大的股票,很多时候您也会希望判断自己使用的股票是否是'ST'股来避开这些风险大的股票。另外,我们目前的策略比赛也禁止了使用'ST'股。
:param str order_book_id: 某只股票的代码,可传入单只股票的order_book_id, symbol
:return: `bool`
"""
dt = Environment.get_instance().calendar_dt.date()
order_book_id = assure_stock_order_book_id(order_book_id)
return Environment.get_instance().data_proxy.is_st_stock(order_book_id, dt)


def assure_stock_order_book_id(id_or_symbols):
if isinstance(id_or_symbols, Instrument):
order_book_id = id_or_symbols.order_book_id
Expand Down

0 comments on commit a6d6002

Please sign in to comment.