Skip to content

Commit 4470da5

Browse files
committed
delay quote api; option chain filter
1 parent 444af12 commit 4470da5

File tree

17 files changed

+355
-67
lines changed

17 files changed

+355
-67
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,6 @@ dmypy.json
136136

137137
# Cython debug symbols
138138
cython_debug/
139+
140+
# other
141+
.DS_Store

CHANGELOG.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
## 2.0.3 (2021-12-01)
2+
### New
3+
- 期权链查询接口支持过滤 QuoteClient.get_option_chain
4+
- 新增延迟行情接口 QuoteClient.get_stock_delay_briefs
5+
6+
## 2.0.2 (2021-11-01)
7+
### Changed
8+
- 移除 client_config 中不常用的属性
9+
- 长链接订阅优化
10+
11+
## 2.0.1 (2021-09-18)
12+
### Breaking
13+
- 移除 python2 的兼容
14+
15+
## 1.4.0 (2021-06-28)
16+
### New
17+
- 新增深度行情查询及订阅
18+
- 新增行情权限抢占接口
19+
20+
## 1.2.0 (2020-04-02)
21+
### New
22+
- 新增行业接口
23+
24+
## 1.1.10 (2020-01-19)
25+
### New
26+
- 新增公司行动日历数据
27+
- 新增附加订单(仅环球账户)
28+
29+
## 1.1.9 (2019-10-28)
30+
### Fixed
31+
- 修复 1.1.8 的安装问题
32+
33+
## 1.1.8 (2019-10-27)
34+
### New
35+
- 持仓、订单相关接口中增加identifier,做为相关标的的唯一识别符。
36+
- 期权增增加 underlying asset 的历史波动率
37+
38+
## 1.1.7 (2019-08-02)
39+
### New
40+
- 期货行情的推送价格默认处理为小数
41+
- 订单与持仓推送中增加 symbol 字段(请注意标准账户与环球账户的差异)
42+
- 账户资产(asset)推送中新增 segment ,表示推送的账户类型。
43+
- 股票合约中增加保证金交易相关数据
44+
- example 中增加了一个示例策略
45+
- 新增一个生成 client_config 的方法
46+
47+
48+
## 1.1.6 (2019-07-12)
49+
### New
50+
- 支持按照 account 订阅持仓、订单、资产信息
51+
52+
## 1.1.5 (2019-06-27)
53+
### New
54+
- get_contracts 支持批量获取合约
55+
- PushClient 中的行情支持按照成交与报价分类订阅
56+
- PushClient 修复盘前成交推送的bug
57+
- PushClient 中的时间戳改为按需推送,不再需要单独订阅
58+
- 重新梳理了get_assets接口,股票与期货交易使用更加清晰
59+
### Documentation
60+
- SDK 中补全了文档,方便在IDE中快速查看
61+
62+
63+
## 1.1.4 (2019-06-06)
64+
### New
65+
- 创建订单不再需要联网请求合约数据和申请订单号, 减少为 place_order 一个请求
66+
- 获取订单列表,订单列表支持一次查询股票和期货订单
67+
- 行情订阅的 focus_key 订阅逻辑修复, 支持订阅指定字段的推送
68+
- get_order 支持按照 id 查询订单
69+
- get_trade_ticks 返回多只股票
70+
- 新增公司行动数据 API, 含分红以及拆合股数据
71+
- 添加基本面 API,含日级别的估值数据以及财报级别的三大报表及衍生因子
72+
- 增加已成交、待撤销和已撤销的订单列表
73+
- push_client 中新增加分钟分时的推送
74+
- push_client 中的订单状态改为 OrderStatus 对象
75+
- push_client 中增加心跳,减少链接断开的可能
76+
- 期货增加 3min、45min 等周期行情的查询, 修复期货 1min 周期的查询
77+
### Fixed
78+
- 修复 get_orders 的 sec_type 无效的问题

tigeropen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
55
@author: gaoan
66
"""
7-
__VERSION__ = '2.0.2'
7+
__VERSION__ = '2.0.3'

tigeropen/common/consts/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
Leverage, Profitability
1212
from .quote_keys import QuoteChangeKey, QuoteKeyType
1313

14-
OPEN_API_SDK_VERSION = "2.0"
14+
OPEN_API_SERVICE_VERSION = "2.0"
15+
OPEN_API_SERVICE_VERSION_V3 = "3.0"
1516

1617
THREAD_LOCAL = threading.local()
1718

tigeropen/common/consts/service_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
KLINE = "kline"
4141
TRADE_TICK = "trade_tick"
4242
QUOTE_REAL_TIME = "quote_real_time"
43+
QUOTE_DELAY = "quote_delay"
4344
QUOTE_SHORTABLE_STOCKS = "quote_shortable_stocks"
4445
QUOTE_STOCK_TRADE = "quote_stock_trade"
4546
QUOTE_DEPTH = "quote_depth" # level2 深度行情

tigeropen/common/model.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2021/11/12
4+
# @Author : sukai
5+
6+
class BaseParams:
7+
def __init__(self):
8+
self._version = None # api版本
9+
10+
@property
11+
def version(self):
12+
return self._version
13+
14+
@version.setter
15+
def version(self, value):
16+
self._version = value

tigeropen/common/util/string_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"""
77
import re
88

9+
CAMEL_PATTERN = re.compile(r'([a-z]|\d)([A-Z])')
10+
911

1012
def add_start_end(key, start_marker, end_marker):
1113
if key.find(start_marker) < 0:
@@ -16,8 +18,4 @@ def add_start_end(key, start_marker, end_marker):
1618

1719

1820
def camel_to_underline(hunp_str):
19-
p = re.compile(r'([a-z]|\d)([A-Z])')
20-
sub = re.sub(p, r'\1_\2', hunp_str).lower()
21-
return sub
22-
23-
21+
return re.sub(CAMEL_PATTERN, r'\1_\2', hunp_str).lower()

tigeropen/examples/quote_client_demo.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pandas as pd
99
from tigeropen.common.consts import Market, QuoteRight, FinancialReportPeriodType, Valuation, \
1010
Income, Balance, CashFlow, BalanceSheetRatio, Growth, Leverage, Profitability, IndustryLevel
11+
from tigeropen.quote.domain.filter import OptionFilter
1112

1213
from tigeropen.quote.quote_client import QuoteClient
1314

@@ -50,6 +51,10 @@ def get_quote():
5051
stock_details = openapi_client.get_stock_details(['AAPL', '03690'])
5152
print(stock_details)
5253

54+
# 获取延迟行情
55+
delay_brief = openapi_client.get_stock_delay_briefs(['AAPL', 'GOOG'])
56+
print(delay_brief)
57+
5358

5459
def get_option_quote():
5560
symbol = 'AAPL'
@@ -66,6 +71,19 @@ def get_option_quote():
6671
ticks = openapi_client.get_option_trade_ticks(['AAPL 190104P00134000'])
6772
print(ticks)
6873

74+
# option chain filter
75+
option_filter = OptionFilter(implied_volatility_min=0.5, implied_volatility_max=0.9, delta_min=0, delta_max=1,
76+
open_interest_min=100, gamma_min=0.005, theta_max=-0.05, in_the_money=True)
77+
chains = openapi_client.get_option_chain('AAPL', '2023-01-20', option_filter=option_filter)
78+
print(chains)
79+
# or
80+
chains = openapi_client.get_option_chain('AAPL', '2023-01-20', implied_volatility_min=0.5, open_interest_min=200,
81+
vega_min=0.1, rho_max=0.9)
82+
# convert expiry date to US/Eastern
83+
chains['expiry_date'] = pd.to_datetime(chains['expiry'], unit='ms').dt.tz_localize('UTC').dt.tz_convert('US/Eastern')
84+
print(chains)
85+
86+
6987

7088
def get_future_quote():
7189
exchanges = openapi_client.get_future_exchanges()

tigeropen/fundamental/request/model.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
from tigeropen.common.model import BaseParams
23

34

4-
class FinancialDailyParams:
5+
class FinancialDailyParams(BaseParams):
56
def __init__(self):
7+
super(FinancialDailyParams, self).__init__()
68
self._symbols = None
79
self._market = None
810
self._period_type = None
@@ -82,8 +84,9 @@ def to_openapi_dict(self):
8284
return params
8385

8486

85-
class FinancialReportParams:
87+
class FinancialReportParams(BaseParams):
8688
def __init__(self):
89+
super(FinancialReportParams, self).__init__()
8790
self._symbols = None
8891
self._market = None
8992
self._fields = None
@@ -139,8 +142,9 @@ def to_openapi_dict(self):
139142
return params
140143

141144

142-
class CorporateActionParams:
145+
class CorporateActionParams(BaseParams):
143146
def __init__(self):
147+
super(CorporateActionParams, self).__init__()
144148
self._symbols = None
145149
self._market = None
146150
self._action_type = None
@@ -208,8 +212,9 @@ def to_openapi_dict(self):
208212
return params
209213

210214

211-
class IndustryParams:
215+
class IndustryParams(BaseParams):
212216
def __init__(self):
217+
super(IndustryParams, self).__init__()
213218
self._industry_level = None
214219
self._industry_id = None
215220
self._market = None

tigeropen/quote/domain/filter.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2021/11/15
4+
# @Author : sukai
5+
6+
GREEKS = ['delta', 'gamma', 'theta', 'vega', 'rho']
7+
8+
9+
class OptionFilter:
10+
def __init__(self, implied_volatility_min=None, implied_volatility_max=None, open_interest_min=None,
11+
open_interest_max=None, delta_min=None, delta_max=None, gamma_min=None, gamma_max=None,
12+
theta_min=None, theta_max=None, vega_min=None, vega_max=None, rho_min=None, rho_max=None,
13+
in_the_money=None):
14+
"""
15+
option filter
16+
:param implied_volatility_min:
17+
:param implied_volatility_max:
18+
:param open_interest_min:
19+
:param open_interest_max:
20+
:param delta_min:
21+
:param delta_max:
22+
:param gamma_min:
23+
:param gamma_max:
24+
:param theta_min:
25+
:param theta_max:
26+
:param vega_min:
27+
:param vega_max:
28+
:param rho_min:
29+
:param rho_max:
30+
:param in_the_money:
31+
"""
32+
self.implied_volatility_min = implied_volatility_min
33+
self.implied_volatility_max = implied_volatility_max
34+
self.open_interest_min = open_interest_min
35+
self.open_interest_max = open_interest_max
36+
self.delta_min = delta_min
37+
self.delta_max = delta_max
38+
self.gamma_min = gamma_min
39+
self.gamma_max = gamma_max
40+
self.theta_min = theta_min
41+
self.theta_max = theta_max
42+
self.vega_min = vega_min
43+
self.vega_max = vega_max
44+
self.rho_min = rho_min
45+
self.rho_max = rho_max
46+
self.in_the_money = in_the_money
47+
48+
def to_dict(self):
49+
return {'greeks': self._get_greeks(),
50+
'implied_volatility': self._min_max('implied_volatility'),
51+
'open_interest': self._min_max('open_interest'),
52+
'in_the_money': self.in_the_money}
53+
54+
def _get_greeks(self):
55+
return {greek: self._min_max(greek) for greek in GREEKS}
56+
57+
def _min_max(self, k):
58+
return {'min': getattr(self, k + '_min'), 'max': getattr(self, k + '_max')}

0 commit comments

Comments
 (0)