Skip to content

Commit e36a4d9

Browse files
committed
扩展支持的市场类型、增加扩展市场类型的功能
1 parent b88696f commit e36a4d9

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.5.0(2023-01-08)
4+
5+
### Added
6+
7+
- 增加获取 广期所 期货行情的功能
8+
- 添加扩展市场类型的函数
9+
310
## v0.4.9(2022-07-29)
411

512
### Added

efinance/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = 'efinance'
2-
__version__ = '0.4.9'
2+
__version__ = '0.5.0'
33
__author__ = 'micro sheep'
44
__url__ = 'https://github.com/Micro-sheep/efinance'
55
__author_email__ = '[email protected]'

efinance/common/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class MagicConfig:
2323
'8': '中金所',
2424
'142': '上海能源期货交易所',
2525
'155': '英股',
26-
'90': '板块'
26+
'90': '板块',
27+
'225': '广期所',
2728

2829
}
2930
# ! Powerful
@@ -39,8 +40,8 @@ class MagicConfig:
3940
'北证A股': 'm:0 t:81 s:2048',
4041
'北A': 'm:0 t:81 s:2048',
4142
# 期货
42-
'futures': 'm:113,m:114,m:115,m:8,m:142',
43-
'期货': 'm:113,m:114,m:115,m:8,m:142',
43+
'futures': 'm:113,m:114,m:115,m:8,m:142,m:225',
44+
'期货': 'm:113,m:114,m:115,m:8,m:142,m:225',
4445

4546
'上证A股': 'm:1 t:2,m:1 t:23',
4647
'沪A': 'm:1 t:2,m:1 t:23',

efinance/common/getter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_realtime_quotes_by_fs(fs: str,
5252
df = pd.DataFrame(json_response['data']['diff'])
5353
df = df.rename(columns=columns)
5454
df: pd.DataFrame = df[columns.values()]
55-
df['行情ID'] = df['市场编号'].astype(str)+'.'+df['代码'].astype(str)
55+
df['行情ID'] = df['市场编号'].astype(str) + '.' + df['代码'].astype(str)
5656
df['市场类型'] = df['市场编号'].astype(str).apply(
5757
lambda x: MARKET_NUMBER_DICT.get(x))
5858
df['更新时间'] = df['更新时间戳'].apply(lambda x: str(datetime.fromtimestamp(x)))
@@ -382,7 +382,7 @@ def get_deal_detail(quote_id: str,
382382
df = pd.DataFrame(columns=columns, index=range(len(rows)))
383383
df.loc[:, '代码'] = code
384384
df.loc[:, '名称'] = name
385-
detail_df = pd.DataFrame(rows, columns=['时间', '成交价', '成交量', '单数'])
385+
detail_df = pd.DataFrame(rows, columns=['时间', '成交价', '成交量', '单数'])
386386
detail_df.insert(1, '昨收', js['data']['prePrice'])
387387
df.loc[:, detail_df.columns] = detail_df.values
388388
return df

efinance/utils/__init__.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections import OrderedDict
2+
from ..common.config import MARKET_NUMBER_DICT, FS_DICT
13
from typing import Any
24
import time
35
import json
@@ -154,10 +156,10 @@ def search_quote_locally(keyword: str) -> Union[Quote, None]:
154156
return None
155157
last_time: float = q['last_time']
156158
# 缓存过期秒数
157-
max_ts = 3600*24*3
159+
max_ts = 3600 * 24 * 3
158160
now = time.time()
159161
# 缓存过期,在线搜索
160-
if (now-last_time) > max_ts:
162+
if (now - last_time) > max_ts:
161163
return None
162164
# NOTE 一定要拷贝 否则改变源对象
163165
_q = q.copy()
@@ -294,4 +296,32 @@ def to_type(f: Callable[[str], T],
294296
return default
295297

296298

299+
def add_market(category: str,
300+
market_number: str,
301+
market_name: str,
302+
drop_duplicate: bool = True
303+
) -> None:
304+
"""
305+
添加市场
306+
307+
Parameters
308+
----------
309+
category : str
310+
市场类别
311+
market_number : str
312+
市场编号
313+
market_name : str
314+
市场名称
315+
drop_duplicate : bool, optional
316+
是否去重, 默认为 ``True``
317+
"""
318+
MARKET_NUMBER_DICT[market_number] = market_name
319+
old = FS_DICT.get(category, '')
320+
new = f'{old},m:{market_number}'
321+
if drop_duplicate:
322+
FS_DICT[category] = ','.join(OrderedDict.fromkeys(new.split(',')))
323+
else:
324+
FS_DICT[category] = new
325+
326+
297327
__all__ = []

0 commit comments

Comments
 (0)