Skip to content

Commit 85b890b

Browse files
committed
Merge branch 'feat_fund_trade' into 'dev'
Feat fund trade See merge request server/openapi/openapi-python-sdk!192
2 parents a719040 + f838f6b commit 85b890b

23 files changed

Lines changed: 236 additions & 49 deletions

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 3.0.7 (2023-08-11)
2+
### New
3+
- 新增基金相关接口
4+
`QuoteClient.get_fund_symbols` 基金代码列表
5+
`QuoteClient.get_fund_quote` 基金行情
6+
`QuoteClient.get_fund_history_quote` 基金历史行情
7+
`QuoteClient.get_fund_contracts` 基金合约
8+
- 订单数据推送中新增字段 `totalCashAmount`, `filledCashAmount`
9+
- PushClient 可自定义心跳回调方法
10+
111
## 3.0.6 (2023-07-31)
212
### Modify
313
- 长链接添加统一异常处理

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.0.6'
7+
__VERSION__ = '3.0.7'

tigeropen/common/consts/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class SecurityType(Enum):
4848
FUT = 'FUT' # 期货
4949
FOP = 'FOP' # 期货期权
5050
CASH = 'CASH' # 外汇
51-
MLEG = 'MLEG'
51+
MLEG = 'MLEG' # 期权组合
52+
FUND = 'FUND' # 基金
5253

5354
@unique
5455
class SegmentType(Enum):

tigeropen/common/consts/service_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@
9090
FUTURE_TICK = "future_tick"
9191
FUTURE_TRADING_DATE = "future_trading_date"
9292

93+
# 基金行情
94+
FUND_ALL_SYMBOLS = "fund_all_symbols"
95+
FUND_CONTRACTS = "fund_contracts"
96+
FUND_QUOTE = "fund_quote"
97+
FUND_HISTORY_QUOTE = "fund_history_quote"
98+
9399
# 公司行动, 财务数据
94100
FINANCIAL_DAILY = 'financial_daily'
95101
FINANCIAL_REPORT = 'financial_report'

tigeropen/common/util/contract_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def cash_contract(symbol, currency, local_symbol=None):
4545
return Contract(symbol, currency, sec_type='CASH', local_symbol=local_symbol)
4646

4747

48+
def fund_contract(symbol):
49+
return Contract(symbol, sec_type=SecurityType.FUND.value)
50+
4851
def war_contract_by_symbol(symbol, expiry, strike, put_call, local_symbol, multiplier=100, currency='HKD',
4952
contract_id=None):
5053
"""港股窝轮"""

tigeropen/common/util/order_utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ def market_order(account, contract, action, quantity):
2121
return Order(account, contract, action, 'MKT', quantity)
2222

2323

24+
def market_order_by_amount(account, contract, action, amount):
25+
"""
26+
按金额的市价单(用于基金)
27+
:param account:
28+
:param contract:
29+
:param action: BUY/SELL
30+
:param amount:
31+
:return:
32+
"""
33+
return Order(account, contract, action, 'MKT', total_cash_amount=amount)
34+
2435
def limit_order(account, contract, action, quantity, limit_price):
2536
"""
2637
限价单

tigeropen/examples/quote_client_demo.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import logging
88
import time
9+
import unittest
910

1011
import pandas as pd
1112
from tigeropen.common.consts import Market, QuoteRight, FinancialReportPeriodType, Valuation, \
@@ -284,6 +285,31 @@ def test_capital_distribution():
284285
print(result)
285286

286287

288+
class TestQuoteClient(unittest.TestCase):
289+
"""测试QuoteClient"""
290+
291+
def test_get_fund_symbols(self):
292+
result = openapi_client.get_fund_symbols()
293+
print(result)
294+
295+
def test_get_fund_contracts(self):
296+
result = openapi_client.get_fund_contracts(['IE00B11XZ988.USD', 'LU0476943708.HKD', 'SG9999017602.SGD'])
297+
print(result)
298+
print(result.iloc[0]['name'])
299+
300+
def test_get_fund_quote(self):
301+
result = openapi_client.get_fund_quote(['IE00B11XZ988.USD', 'LU0476943708.HKD'])
302+
print(result)
303+
print(result.iloc[0]['close'])
304+
# to python type
305+
close = float(result.iloc[0]['close'])
306+
307+
def test_get_fund_history_quote(self):
308+
result = openapi_client.get_fund_history_quote(['LU0476943708.HKD'], begin_time=1691337600000, end_time=1691596800000)
309+
print(result)
310+
print(result.loc[result['symbol']=='LU0476943708.HKD'].iloc[0]['nav'])
311+
312+
287313
if __name__ == '__main__':
288314
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
289315
get_quote()

tigeropen/push/pb/OrderStatusData.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ message OrderStatusData {
4343
uint64 openTime = 36; // timestamp when the order is placed
4444
uint64 timestamp = 37;
4545
string userMark = 38;
46+
double totalCashAmount = 39;
47+
double filledCashAmount = 40;
4648
}

tigeropen/push/pb/OrderStatusData_pb2.py

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tigeropen/push/pb/OrderStatusData_pb2.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from typing import ClassVar as _ClassVar, Optional as _Optional
55
DESCRIPTOR: _descriptor.FileDescriptor
66

77
class OrderStatusData(_message.Message):
8-
__slots__ = ["account", "action", "attrDesc", "avgFillPrice", "canCancel", "canModify", "cancelStatus", "commissionAndFee", "currency", "errorMsg", "expiry", "filledQuantity", "filledQuantityScale", "id", "identifier", "isLong", "limitPrice", "liquidation", "market", "multiplier", "name", "openTime", "orderType", "outsideRth", "realizedPnl", "replaceStatus", "right", "secType", "segType", "source", "status", "stopPrice", "strike", "symbol", "timestamp", "totalQuantity", "totalQuantityScale", "userMark"]
8+
__slots__ = ["account", "action", "attrDesc", "avgFillPrice", "canCancel", "canModify", "cancelStatus", "commissionAndFee", "currency", "errorMsg", "expiry", "filledCashAmount", "filledQuantity", "filledQuantityScale", "id", "identifier", "isLong", "limitPrice", "liquidation", "market", "multiplier", "name", "openTime", "orderType", "outsideRth", "realizedPnl", "replaceStatus", "right", "secType", "segType", "source", "status", "stopPrice", "strike", "symbol", "timestamp", "totalCashAmount", "totalQuantity", "totalQuantityScale", "userMark"]
99
ACCOUNT_FIELD_NUMBER: _ClassVar[int]
1010
ACTION_FIELD_NUMBER: _ClassVar[int]
1111
ATTRDESC_FIELD_NUMBER: _ClassVar[int]
@@ -17,6 +17,7 @@ class OrderStatusData(_message.Message):
1717
CURRENCY_FIELD_NUMBER: _ClassVar[int]
1818
ERRORMSG_FIELD_NUMBER: _ClassVar[int]
1919
EXPIRY_FIELD_NUMBER: _ClassVar[int]
20+
FILLEDCASHAMOUNT_FIELD_NUMBER: _ClassVar[int]
2021
FILLEDQUANTITYSCALE_FIELD_NUMBER: _ClassVar[int]
2122
FILLEDQUANTITY_FIELD_NUMBER: _ClassVar[int]
2223
IDENTIFIER_FIELD_NUMBER: _ClassVar[int]
@@ -41,6 +42,7 @@ class OrderStatusData(_message.Message):
4142
STRIKE_FIELD_NUMBER: _ClassVar[int]
4243
SYMBOL_FIELD_NUMBER: _ClassVar[int]
4344
TIMESTAMP_FIELD_NUMBER: _ClassVar[int]
45+
TOTALCASHAMOUNT_FIELD_NUMBER: _ClassVar[int]
4446
TOTALQUANTITYSCALE_FIELD_NUMBER: _ClassVar[int]
4547
TOTALQUANTITY_FIELD_NUMBER: _ClassVar[int]
4648
USERMARK_FIELD_NUMBER: _ClassVar[int]
@@ -55,6 +57,7 @@ class OrderStatusData(_message.Message):
5557
currency: str
5658
errorMsg: str
5759
expiry: str
60+
filledCashAmount: float
5861
filledQuantity: int
5962
filledQuantityScale: int
6063
id: int
@@ -79,7 +82,8 @@ class OrderStatusData(_message.Message):
7982
strike: str
8083
symbol: str
8184
timestamp: int
85+
totalCashAmount: float
8286
totalQuantity: int
8387
totalQuantityScale: int
8488
userMark: str
85-
def __init__(self, id: _Optional[int] = ..., account: _Optional[str] = ..., symbol: _Optional[str] = ..., expiry: _Optional[str] = ..., strike: _Optional[str] = ..., right: _Optional[str] = ..., identifier: _Optional[str] = ..., multiplier: _Optional[int] = ..., action: _Optional[str] = ..., market: _Optional[str] = ..., currency: _Optional[str] = ..., segType: _Optional[str] = ..., secType: _Optional[str] = ..., orderType: _Optional[str] = ..., isLong: bool = ..., totalQuantity: _Optional[int] = ..., totalQuantityScale: _Optional[int] = ..., filledQuantity: _Optional[int] = ..., filledQuantityScale: _Optional[int] = ..., avgFillPrice: _Optional[float] = ..., limitPrice: _Optional[float] = ..., stopPrice: _Optional[float] = ..., realizedPnl: _Optional[float] = ..., status: _Optional[str] = ..., replaceStatus: _Optional[str] = ..., cancelStatus: _Optional[str] = ..., outsideRth: bool = ..., canModify: bool = ..., canCancel: bool = ..., liquidation: bool = ..., name: _Optional[str] = ..., source: _Optional[str] = ..., errorMsg: _Optional[str] = ..., attrDesc: _Optional[str] = ..., commissionAndFee: _Optional[float] = ..., openTime: _Optional[int] = ..., timestamp: _Optional[int] = ..., userMark: _Optional[str] = ...) -> None: ...
89+
def __init__(self, id: _Optional[int] = ..., account: _Optional[str] = ..., symbol: _Optional[str] = ..., expiry: _Optional[str] = ..., strike: _Optional[str] = ..., right: _Optional[str] = ..., identifier: _Optional[str] = ..., multiplier: _Optional[int] = ..., action: _Optional[str] = ..., market: _Optional[str] = ..., currency: _Optional[str] = ..., segType: _Optional[str] = ..., secType: _Optional[str] = ..., orderType: _Optional[str] = ..., isLong: bool = ..., totalQuantity: _Optional[int] = ..., totalQuantityScale: _Optional[int] = ..., filledQuantity: _Optional[int] = ..., filledQuantityScale: _Optional[int] = ..., avgFillPrice: _Optional[float] = ..., limitPrice: _Optional[float] = ..., stopPrice: _Optional[float] = ..., realizedPnl: _Optional[float] = ..., status: _Optional[str] = ..., replaceStatus: _Optional[str] = ..., cancelStatus: _Optional[str] = ..., outsideRth: bool = ..., canModify: bool = ..., canCancel: bool = ..., liquidation: bool = ..., name: _Optional[str] = ..., source: _Optional[str] = ..., errorMsg: _Optional[str] = ..., attrDesc: _Optional[str] = ..., commissionAndFee: _Optional[float] = ..., openTime: _Optional[int] = ..., timestamp: _Optional[int] = ..., userMark: _Optional[str] = ..., totalCashAmount: _Optional[float] = ..., filledCashAmount: _Optional[float] = ...) -> None: ...

0 commit comments

Comments
 (0)