Skip to content

Commit 426ebb6

Browse files
committed
Merge branch 'feat_overnight_quote' into 'master'
Feat overnight quote See merge request server/openapi/openapi-python-sdk!232
2 parents 07163a6 + 21cb2cc commit 426ebb6

File tree

9 files changed

+78
-4
lines changed

9 files changed

+78
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 3.3.3 (2025-03-05)
2+
### New
3+
- `QuoteClient.get_quote_overnight` 获取夜盘行情
4+
### Mod
5+
- Contract 添加属性 `support_overnight_trading`
6+
7+
18
## 3.3.2 (2025-02-25)
29
### New
310
- `QuoteClient.get_trade_rank` 热门交易榜

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__ = '3.3.2'
7+
__VERSION__ = '3.3.3'

tigeropen/common/consts/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ class TradingSession(Enum):
3434
PreMarket = 'PreMarket' # 盘前
3535
Regular = 'Regular' # 盘中
3636
AfterHours = 'AfterHours' # 盘后
37-
OverNight = 'OverNight' # 夜盘
37+
OverNight = 'OverNight'
3838

3939

40+
@unique
41+
class TradingSessionType(Enum):
42+
PRE_RTH_POST = 'PRE_RTH_POST'
43+
OVERNIGHT ='OVERNIGHT' # 夜盘
44+
RTH = 'RTH' # 盘中
45+
FULL ='FULL' # 全时段
46+
4047

4148
@unique
4249
class SecurityType(Enum):
@@ -239,3 +246,11 @@ class OptionRankingIndicator(Enum):
239246
Volume = "volume"
240247
Amount = "amount"
241248
OpenInt = "openInt"
249+
250+
class AssetQuoteType(Enum):
251+
# Includes pre-market, intra-day, and after-hours trading data. For night session, the closing price of the previous after-hours trading is used for calculation.
252+
ETH = "ETH"
253+
# Only intra-day trading data. For pre-market, after-hours, and night session, the intra-day closing price is used for calculation.
254+
RTH = "RTH"
255+
# Includes night session trading data. For night session, the night session trading data is used for calculation.
256+
OVERNIGHT = "OVERNIGHT"

tigeropen/common/consts/service_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
KLINE_QUOTA = "kline_quota" # 历史k线额度
7474
STOCK_FUNDAMENTAL = "stock_fundamental"
7575
TRADE_RANK = "trade_rank"
76+
QUOTE_OVERNIGHT = "quote_overnight"
7677

7778
# 期权行情
7879
OPTION_EXPIRATION = "option_expiration"

tigeropen/quote/quote_client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
OPTION_KLINE, OPTION_TRADE_TICK, FUTURE_KLINE, FUTURE_TICK, FUTURE_CONTRACT_BY_EXCHANGE_CODE, \
2525
FUTURE_TRADING_DATE, QUOTE_SHORTABLE_STOCKS, FUTURE_REAL_TIME_QUOTE, \
2626
FUTURE_CURRENT_CONTRACT, QUOTE_REAL_TIME, QUOTE_STOCK_TRADE, FINANCIAL_DAILY, FINANCIAL_REPORT, CORPORATE_ACTION, \
27-
QUOTE_DEPTH, INDUSTRY_LIST, INDUSTRY_STOCKS, STOCK_INDUSTRY, STOCK_DETAIL, FUTURE_CONTINUOUS_CONTRACTS
27+
QUOTE_DEPTH, INDUSTRY_LIST, INDUSTRY_STOCKS, STOCK_INDUSTRY, STOCK_DETAIL, FUTURE_CONTINUOUS_CONTRACTS, \
28+
QUOTE_OVERNIGHT
2829
from tigeropen.common.exceptions import ApiException
2930
from tigeropen.common.request import OpenApiRequest
3031
from tigeropen.common.util.common_utils import eastern, get_enum_value, date_str_to_timestamp
@@ -83,6 +84,7 @@
8384
from tigeropen.quote.response.trading_calendar_response import TradingCalendarResponse
8485
from tigeropen.quote.response.warrant_briefs_response import WarrantBriefsResponse
8586
from tigeropen.quote.response.warrant_filter_response import WarrantFilterResponse
87+
from tigeropen.quote.response.quote_overnight_response import QuoteOvernightResponse
8688
from tigeropen.tiger_open_client import TigerOpenClient
8789
from tigeropen.tiger_open_config import LANGUAGE
8890

@@ -1902,4 +1904,18 @@ def get_trade_rank(self, market, lang=Language.en_US):
19021904
else:
19031905
raise ApiException(response.code, response.message)
19041906

1907+
def get_quote_overnight(self, symbols, lang=Language.en_US):
1908+
params = MultipleQuoteParams()
1909+
params.symbols = symbols if isinstance(symbols, list) else [symbols]
1910+
params.lang = get_enum_value(lang)
1911+
request = OpenApiRequest(QUOTE_OVERNIGHT, biz_model=params)
1912+
response_content = self.__fetch_data(request)
1913+
if response_content:
1914+
response = QuoteOvernightResponse()
1915+
response.parse_response_content(response_content)
1916+
if response.is_success():
1917+
return response.result
1918+
else:
1919+
raise ApiException(response.code, response.message)
1920+
19051921

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import pandas as pd
4+
5+
from tigeropen.common.response import TigerResponse
6+
from tigeropen.common.util.string_utils import camel_to_underline_obj
7+
8+
9+
class QuoteOvernightResponse(TigerResponse):
10+
def __init__(self):
11+
super(QuoteOvernightResponse, self).__init__()
12+
self.result = None
13+
14+
def parse_response_content(self, response_content):
15+
response = super(QuoteOvernightResponse, self).parse_response_content(response_content)
16+
if 'data' in response:
17+
data = camel_to_underline_obj(response['data'])
18+
self.result = pd.DataFrame(data)
19+
return response

tigeropen/trade/domain/contract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def __init__(self, symbol=None, currency=None, contract_id=None, sec_type=None,
9090
self.discounted_end_at = kwargs.get('discounted_end_at')
9191
self.categories = kwargs.get('categories')
9292
self.lot_size = kwargs.get('lot_size')
93+
self.support_overnight_trading = kwargs.get('support_overnight_trading')
9394

9495
@property
9596
def right(self):

tigeropen/trade/request/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def __init__(self):
145145
self._expiry = None
146146
self._strike = None
147147
self._right = None
148+
self._asset_quote_type = None
148149

149150
@property
150151
def account(self):
@@ -226,6 +227,14 @@ def right(self):
226227
def right(self, value):
227228
self._right = value
228229

230+
@property
231+
def asset_quote_type(self):
232+
return self._asset_quote_type
233+
234+
@asset_quote_type.setter
235+
def asset_quote_type(self, value):
236+
self._asset_quote_type = value
237+
229238
def to_openapi_dict(self):
230239
params = super().to_openapi_dict()
231240
if self.account:
@@ -258,6 +267,9 @@ def to_openapi_dict(self):
258267
if self.right:
259268
params['right'] = self.right
260269

270+
if self.asset_quote_type:
271+
params['asset_quote_type'] = self.asset_quote_type
272+
261273
return params
262274

263275

tigeropen/trade/trade_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def get_derivative_contracts(self, symbol, sec_type, expiry, lang=None):
192192
return None
193193

194194
def get_positions(self, account=None, sec_type=SecurityType.STK, currency=Currency.ALL, market=Market.ALL,
195-
symbol=None, sub_accounts=None, expiry=None, strike=None, put_call=None):
195+
symbol=None, sub_accounts=None, expiry=None, strike=None, put_call=None, asset_quote_type=None):
196196
"""
197197
获取持仓数据
198198
:param account:
@@ -201,6 +201,7 @@ def get_positions(self, account=None, sec_type=SecurityType.STK, currency=Curren
201201
:param market:
202202
:param symbol:
203203
:param sub_accounts:
204+
:param asset_quote_type: 资产行情模式
204205
:return: 由 Position 对象构成的列表. Position 对象有如下属性:
205206
account: 所属账户
206207
contract: 合约对象
@@ -225,6 +226,8 @@ def get_positions(self, account=None, sec_type=SecurityType.STK, currency=Curren
225226
params.strike = strike
226227
if put_call:
227228
params.right = put_call
229+
if asset_quote_type:
230+
params.asset_quote_type = get_enum_value(asset_quote_type)
228231
params.lang = get_enum_value(self._lang)
229232
request = OpenApiRequest(POSITIONS, biz_model=params)
230233
response_content = self.__fetch_data(request)

0 commit comments

Comments
 (0)