Skip to content

Commit f8efc09

Browse files
authored
Merge pull request #36 from tigerfintech/feature_grab_quote_permission
feature grab quote permission and depth quote
2 parents 377899e + a451818 commit f8efc09

28 files changed

+831
-125
lines changed

.gitignore

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
101+
celerybeat-schedule
102+
celerybeat.pid
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# mkdocs documentation
124+
/site
125+
126+
# mypy
127+
.mypy_cache/
128+
.dmypy.json
129+
dmypy.json
130+
131+
# Pyre type checker
132+
.pyre/
133+
134+
# pytype static type analyzer
135+
.pytype/
136+
137+
# Cython debug symbols
138+
cython_debug/

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include requirements.txt
1+
include requirements.txt

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,52 @@ def get_quote_apis():
8989
client_config = get_client_config()
9090
quote_client = QuoteClient(client_config)
9191
quote_client.get_market_status(Market.US)
92-
92+
quote_client.get_briefs(symbols=['AAPL', '00700', '600519'], include_ask_bid=True, right=QuoteRight.BR)
93+
quote_client.get_timeline(['AAPL'], period=TimelinePeriod.DAY, include_hour_trading=True)
94+
quote_client.get_bars(['AAPL'])
9395
96+
def get_option_quote():
97+
client_config = get_client_config()
98+
quote_client = QuoteClient(client_config)
99+
symbol = 'AAPL'
100+
expirations = quote_client.get_option_expirations(symbols=[symbol])
101+
if len(expirations) > 1:
102+
expiry = int(expirations[expirations['symbol'] == symbol].at[0, 'timestamp'])
103+
quote_client.get_option_chain(symbol, expiry)
104+
105+
quote_client.get_option_briefs(['AAPL 190104C00121000'])
106+
quote_client.get_option_bars(['AAPL 190104P00134000'])
107+
quote_client.get_option_trade_ticks(['AAPL 190104P00134000'])
108+
109+
110+
def get_future_quote():
111+
client_config = get_client_config()
112+
quote_client = QuoteClient(client_config)
113+
exchanges = quote_client.get_future_exchanges()
114+
print(exchanges)
115+
quote_client.get_future_bars(['CN1901'], begin_time=-1, end_time=1545105097358)
116+
quote_client.get_future_trade_ticks(['CN1901'])
117+
quote_client.get_future_contracts('CME')
118+
quote_client.get_future_trading_times('CN1901', trading_date=1545049282852)
119+
quote_client.get_future_brief(['ES1906', 'CN1901'])
120+
94121
```
95122

96-
- 交易信息推送
123+
- 行情和交易信息推送
97124
```
98125
from tigeropen.common.consts import Language
99126
from tigeropen.common.util.signature_utils import read_private_key
100127
from tigeropen.push.push_client import PushClient
101128
from tigeropen.tiger_open_config import TigerOpenClientConfig
102129
103130
131+
def on_query_subscribed_quote(symbols, focus_keys, limit, used):
132+
print(symbols, focus_keys, limit, used)
133+
134+
135+
def on_quote_changed(symbol, items, hour_trading):
136+
print(symbol, items, hour_trading)
137+
104138
105139
is_sandbox = False
106140
client_config = TigerOpenClientConfig(sandbox_debug=is_sandbox)
@@ -111,7 +145,11 @@ client_config.account = 'your account'
111145
client_config.language = Language.en_US
112146
protocol, host, port = client_config.socket_host_port
113147
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'))
148+
push_client.quote_changed = on_quote_changed
149+
push_client.subscribed_symbols = on_query_subscribed_quote
114150
push_client.connect(client_config.tiger_id, client_config.private_key)
151+
push_client.query_subscribed_quote()
152+
push_client.subscribe_quote(['AAPL', 'GOOG'])
115153
push_client.subscribe_asset()
116154
117155
time.sleep(600)
@@ -140,4 +178,4 @@ push_client.disconnect()
140178
* 使用新版本时请先仔细阅读接口文档,大部分问题都可以在接口文档中找到你想要的答案。
141179
* 欢迎大家提出建议、也可以提出各种需求,我们一定会尽量满足大家的需求。
142180

143-
---
181+
---

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
six==1.13.0
22
simplejson==3.17.0
33
delorean==1.0.0
4-
pandas==0.24.2
4+
pandas==0.25.3
55
python-dateutil==2.8.1
66
pytz==2019.3
77
pyasn1==0.4.2
88
rsa==4.0
99
stomp.py==4.1.22
10-
enum34==1.1.6
10+
enum34==1.1.6
11+
getmac==0.8.2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='tigeropen',
15-
version='1.2.0',
15+
version='1.4.0',
1616
description='TigerBrokers Open API',
1717
packages=find_packages(exclude=[]),
1818
author='TigerBrokers',

tigeropen/common/consts/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Market(Enum):
3131
US = 'US' # 美股
3232
HK = 'HK' # 港股
3333
CN = 'CN' # A股
34+
SG = 'SG' # 新加坡
3435

3536

3637
@unique
@@ -62,6 +63,7 @@ class Currency(Enum):
6263
USD = 'USD' # 美元
6364
HKD = 'HKD' # 港币
6465
CNH = 'CNH' # 离岸人民币
66+
SGD = 'SGD' # 新加坡币
6567

6668

6769
@unique

tigeropen/common/consts/fundamental_fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,4 @@ class Profitability(Enum):
590590
levered_free_cash_flow_margin = "levered_free_cash_flow_margin"
591591
unlevered_free_cash_flow_margin = "unlevered_free_cash_flow_margin"
592592
normalized_net_income_margin = "normalized_net_income_margin"
593+

tigeropen/common/consts/params.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
P_TIMESTAMP = "timestamp"
1414
P_VERSION = "version"
1515
P_NOTIFY_URL = "notify_url"
16+
P_DEVICE_ID = "device_id"
1617

17-
COMMON_PARAM_KEYS = set([P_TIGER_ID, P_METHOD, P_CHARSET, P_SIGN_TYPE, P_SIGN, P_TIMESTAMP, P_VERSION, P_NOTIFY_URL])
18+
COMMON_PARAM_KEYS = {P_TIGER_ID, P_METHOD, P_CHARSET, P_SIGN_TYPE, P_SIGN, P_TIMESTAMP, P_VERSION, P_NOTIFY_URL,
19+
P_DEVICE_ID}
1820
P_BIZ_CONTENT = "biz_content"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
3+
QUOTE = 'quote'
4+
QUOTE_DEPTH = 'quotedepth'
5+
QUOTE_FUTURE = 'future'
6+
QUOTE_OPTION = 'option'
7+
8+
TRADE_ASSET = 'trade/asset'
9+
TRADE_POSITION = 'trade/position'
10+
TRADE_ORDER = 'trade/order'

tigeropen/common/consts/quote_keys.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class QuoteChangeKey(Enum):
1717
bid_price = 'bidPrice'
1818
bid_size = 'bidSize'
1919
minute = 'mi'
20+
bid_depth = 'bidDepth'
21+
ask_depth = 'askDepth'
2022

2123

2224
@unique

0 commit comments

Comments
 (0)