Skip to content

Commit 22d6ac3

Browse files
committed
segment fund transfer
1 parent 23b5f54 commit 22d6ac3

File tree

10 files changed

+495
-7
lines changed

10 files changed

+495
-7
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 2.3.5 (2023-03-28)
2+
### New
3+
- TradeClient 新增不同品种(股票SEC/期货FUT/基金FUND)账户间资金划转接口
4+
`TradeClient.get_segment_fund_available` 获取可划转资金
5+
`TradeClient.transfer_segment_fund` 划转资金
6+
`TradeClient.cancel_segment_fund` 取消划转
7+
`TradeClient.get_segment_fund_history` 获取划转历史
8+
9+
- TradeClient 新增换汇下单接口
10+
`TradeClient.place_forex_order`
11+
12+
- `QuoteClient.get_option_bars` 期权k线接口新增参数 `period`, 支持获取分钟k线
13+
14+
115
## 2.3.4 (2023-03-20)
216
### New
317
- 支持AM/AL(盘前竞价单)

tigeropen/common/consts/service_types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
FILLED_ORDERS = "filled_orders" # 已成交订单
2727
ORDER_TRANSACTIONS = "order_transactions" # 订单成交记录
2828
ANALYTICS_ASSET = "analytics_asset"
29+
SEGMENT_FUND_HISTORY = "segment_fund_history"
30+
SEGMENT_FUND_AVAILABLE = "segment_fund_available"
31+
TRANSFER_SEGMENT_FUND = "transfer_segment_fund"
32+
CANCEL_SEGMENT_FUND = "cancel_segment_fund"
33+
PLACE_FOREX_ORDER = "place_forex_order"
2934

3035
USER_LICENSE = "user_license"
3136

tigeropen/examples/trade_client_demo.py

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

1011
from tigeropen.common.util.price_util import PriceUtil
1112
from tigeropen.trade.domain.order import OrderStatus
@@ -19,14 +20,16 @@
1920
war_contract_by_symbol, iopt_contract_by_symbol
2021
from tigeropen.common.util.order_utils import limit_order, limit_order_with_legs, order_leg, algo_order_params, \
2122
algo_order
22-
from tigeropen.examples.client_config import get_client_config
23+
from tigeropen.tiger_open_config import get_client_config
2324

2425
logging.basicConfig(level=logging.INFO,
2526
format='%(asctime)s %(levelname)s %(message)s',
2627
filemode='a', )
2728
logger = logging.getLogger('TigerOpenApi')
2829

29-
client_config = get_client_config()
30+
client_config = get_client_config(private_key_path='your private key file path',
31+
tiger_id='your tiger id',
32+
account='your account')
3033

3134

3235
def get_contract_apis():
@@ -169,6 +172,33 @@ def get_account_info():
169172
print("%d,%s,%s" % (response.code, response.message, response.data))
170173

171174

175+
class TestTradeClient(unittest.TestCase):
176+
trade_client = TradeClient(client_config)
177+
178+
def test_transfer_segment_fund(self):
179+
"""资金划转"""
180+
# 查看可转资金
181+
available = self.trade_client.get_segment_fund_available()
182+
print(available)
183+
184+
# 划转资金
185+
res = self.trade_client.transfer_segment_fund(from_segment='SEC', to_segment='FUT', amount=100, currency='USD')
186+
print(res)
187+
# 撤销划转
188+
cancelres = self.trade_client.cancel_segment_fund(id=res.id)
189+
print(cancelres)
190+
191+
# 查看资金划转历史
192+
history = self.trade_client.get_segment_fund_history()
193+
print(history)
194+
195+
def test_forex_order(self):
196+
"""换汇"""
197+
order = self.trade_client.place_forex_order(seg_type='FUT', source_currency='USD', target_currency='HKD',
198+
source_amount=50)
199+
print(order)
200+
201+
172202
if __name__ == '__main__':
173203
get_account_apis()
174204
trade_apis()

tigeropen/trade/domain/account.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,32 @@ def market_values(self):
238238
def __repr__(self):
239239
return "PortfolioAccount({0})".format({'account': self.account, 'summary': self.summary,
240240
'segments': self.segments, 'market_values': self.market_values})
241+
242+
243+
class SegmentFundAvailableItem:
244+
def __init__(self, from_segment=None, currency=None, amount=None):
245+
self.from_segment = from_segment
246+
self.currency = currency
247+
self.amount = amount
248+
249+
def __repr__(self):
250+
return "SegmentFundAvailableItem({0})".format(self.__dict__)
251+
252+
253+
class SegmentFundItem:
254+
def __init__(self, id=None, from_segment=None, to_segment=None, currency=None, amount=None, status=None,
255+
status_desc=None, message=None, settled_at=None, updated_at=None, created_at=None):
256+
self.id = id
257+
self.from_segment = from_segment
258+
self.to_segment = to_segment
259+
self.currency = currency
260+
self.amount = amount
261+
self.status = status
262+
self.status_desc = status_desc
263+
self.message = message
264+
self.settled_at = settled_at
265+
self.updated_at = updated_at
266+
self.created_at = created_at
267+
268+
def __repr__(self):
269+
return "SegmentFundItem({0})".format(self.__dict__)

tigeropen/trade/domain/order.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Order:
1717
"trail_stop_price", "limit_price", "aux_price", "trailing_percent", "percent_offset", "action",
1818
"order_type", "time_in_force", "outside_rth", "order_legs", "algo_params", "algo_strategy",
1919
"secret_key", "liquidation", "discount", "attr_desc", "source", 'adjust_limit', 'sub_ids', "user_mark",
20-
"update_time", "expire_time"]
20+
"update_time", "expire_time", "can_modify"]
2121

2222
def __init__(self, account, contract, action, order_type, quantity, limit_price=None, aux_price=None,
2323
trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None,
@@ -100,6 +100,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
100100
self.sub_ids = kwargs.get('sub_ids')
101101
self.user_mark = kwargs.get('user_mark')
102102
self.expire_time = kwargs.get('expire_time')
103+
self.can_modify = kwargs.get('can_modify')
103104

104105
def to_dict(self):
105106
dct = {name: getattr(self, name) for name in self.__slots__ if name not in ORDER_FIELDS_TO_IGNORE}

tigeropen/trade/request/model.py

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,4 +1032,198 @@ def to_openapi_dict(self):
10321032

10331033
if self.end_date:
10341034
params['end_date'] = self.end_date
1035+
return params
1036+
1037+
1038+
class SegmentFundParams(BaseParams):
1039+
def __init__(self):
1040+
super().__init__()
1041+
self._id = None
1042+
self._account = None
1043+
self._secret_key = None
1044+
self._from_segment = None
1045+
self._to_segment = None
1046+
self._currency = None
1047+
self._amount = None
1048+
self._limit = None
1049+
1050+
@property
1051+
def id(self):
1052+
return self._id
1053+
1054+
@id.setter
1055+
def id(self, value):
1056+
self._id = value
1057+
1058+
@property
1059+
def account(self):
1060+
return self._account
1061+
1062+
@account.setter
1063+
def account(self, value):
1064+
self._account = value
1065+
1066+
@property
1067+
def secret_key(self):
1068+
return self._secret_key
1069+
1070+
@secret_key.setter
1071+
def secret_key(self, value):
1072+
self._secret_key = value
1073+
1074+
@property
1075+
def from_segment(self):
1076+
return self._from_segment
1077+
1078+
@from_segment.setter
1079+
def from_segment(self, value):
1080+
self._from_segment = value
1081+
1082+
@property
1083+
def to_segment(self):
1084+
return self._to_segment
1085+
1086+
@to_segment.setter
1087+
def to_segment(self, value):
1088+
self._to_segment = value
1089+
1090+
@property
1091+
def currency(self):
1092+
return self._currency
1093+
1094+
@currency.setter
1095+
def currency(self, value):
1096+
self._currency = value
1097+
1098+
@property
1099+
def amount(self):
1100+
return self._amount
1101+
1102+
@amount.setter
1103+
def amount(self, value):
1104+
self._amount = value
1105+
1106+
@property
1107+
def limit(self):
1108+
return self._limit
1109+
1110+
@limit.setter
1111+
def limit(self, value):
1112+
self._limit = value
1113+
1114+
def to_openapi_dict(self):
1115+
params = super().to_openapi_dict()
1116+
if self._id:
1117+
params['id'] = self._id
1118+
if self._account:
1119+
params['account'] = self._account
1120+
if self._secret_key:
1121+
params['secret_key'] = self._secret_key
1122+
if self._from_segment:
1123+
params['from_segment'] = self._from_segment
1124+
if self._to_segment:
1125+
params['to_segment'] = self._to_segment
1126+
if self._currency:
1127+
params['currency'] = self._currency
1128+
if self._amount:
1129+
params['amount'] = self._amount
1130+
if self._limit:
1131+
params['limit'] = self._limit
1132+
return params
1133+
1134+
1135+
class ForexTradeOrderParams(BaseParams):
1136+
def __init__(self):
1137+
super().__init__()
1138+
self._account = None
1139+
self._secret_key = None
1140+
self._source_currency = None
1141+
self._source_amount = None
1142+
self._target_currency = None
1143+
self._seg_type = None
1144+
self._external_id = None
1145+
self._time_in_force = None
1146+
1147+
@property
1148+
def account(self):
1149+
return self._account
1150+
1151+
@account.setter
1152+
def account(self, value):
1153+
self._account = value
1154+
1155+
@property
1156+
def secret_key(self):
1157+
return self._secret_key
1158+
1159+
@secret_key.setter
1160+
def secret_key(self, value):
1161+
self._secret_key = value
1162+
1163+
@property
1164+
def source_currency(self):
1165+
return self._source_currency
1166+
1167+
@source_currency.setter
1168+
def source_currency(self, value):
1169+
self._source_currency = value
1170+
1171+
@property
1172+
def source_amount(self):
1173+
return self._source_amount
1174+
1175+
@source_amount.setter
1176+
def source_amount(self, value):
1177+
self._source_amount = value
1178+
1179+
@property
1180+
def target_currency(self):
1181+
return self._target_currency
1182+
1183+
@target_currency.setter
1184+
def target_currency(self, value):
1185+
self._target_currency = value
1186+
1187+
@property
1188+
def seg_type(self):
1189+
return self._seg_type
1190+
1191+
@seg_type.setter
1192+
def seg_type(self, value):
1193+
self._seg_type = value
1194+
1195+
@property
1196+
def external_id(self):
1197+
return self._external_id
1198+
1199+
@external_id.setter
1200+
def external_id(self, value):
1201+
self._external_id = value
1202+
1203+
@property
1204+
def time_in_force(self):
1205+
return self._time_in_force
1206+
1207+
@time_in_force.setter
1208+
def time_in_force(self, value):
1209+
self._time_in_force = value
1210+
1211+
def to_openapi_dict(self):
1212+
params = super().to_openapi_dict()
1213+
if self.account:
1214+
params['account'] = self.account
1215+
if self.secret_key:
1216+
params['secret_key'] = self.secret_key
1217+
if self.source_currency:
1218+
params['source_currency'] = self.source_currency
1219+
if self.source_amount:
1220+
params['source_amount'] = self.source_amount
1221+
if self.target_currency:
1222+
params['target_currency'] = self.target_currency
1223+
if self.seg_type:
1224+
params['seg_type'] = self.seg_type
1225+
if self.external_id:
1226+
params['external_id'] = self.external_id
1227+
if self.time_in_force:
1228+
params['time_in_force'] = self.time_in_force
10351229
return params
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2023/3/28
4+
# @Author : sukai
5+
from tigeropen.common.response import TigerResponse
6+
from tigeropen.trade.response.orders_response import OrdersResponse
7+
8+
9+
class ForexOrderResponse(TigerResponse):
10+
def __init__(self):
11+
super(ForexOrderResponse, self).__init__()
12+
self._is_success = None
13+
14+
def parse_response_content(self, response_content):
15+
response = super(ForexOrderResponse, self).parse_response_content(response_content)
16+
if 'is_success' in response:
17+
self._is_success = response['is_success']
18+
if self.data:
19+
self.data = OrdersResponse.parse_order(self.data)
20+

tigeropen/trade/response/orders_response.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
'contractId': 'contract_id', 'algoStrategy': 'algo_strategy',
2323
'trailStopPrice': 'trail_stop_price', 'trailingPercent': 'trailing_percent',
2424
'percentOffset': 'percent_offset', 'identifier': 'identifier', 'algoParameters': 'algo_params',
25-
'userMark': 'user_mark', 'updateTime': 'update_time', 'expireTime': 'expire_time'
25+
'userMark': 'user_mark', 'updateTime': 'update_time', 'expireTime': 'expire_time',
26+
'canModify': 'can_modify'
2627
}
2728

2829

@@ -104,14 +105,16 @@ def parse_order(item, secret_key=None):
104105
attr_desc = order_fields.get('attr_desc')
105106
source = order_fields.get('source')
106107
user_mark = order_fields.get('user_mark')
108+
can_modify = order_fields.get('can_modify')
107109

108110
order = Order(account, contract, action, order_type, quantity, limit_price=limit_price, aux_price=aux_price,
109111
trail_stop_price=trail_stop_price, trailing_percent=trailing_percent,
110112
percent_offset=percent_offset, time_in_force=time_in_force, outside_rth=outside_rth,
111113
filled=filled, avg_fill_price=avg_fill_price, commission=commission,
112114
realized_pnl=realized_pnl, id=id_, order_id=order_id, parent_id=parent_id,
113115
algo_params=algo_params, liquidation=liquidation, algo_strategy=algo_strategy, discount=discount,
114-
attr_desc=attr_desc, source=source, user_mark=user_mark, expire_time=expire_time)
116+
attr_desc=attr_desc, source=source, user_mark=user_mark, expire_time=expire_time,
117+
can_modify=can_modify)
115118
if 'order_time' in order_fields:
116119
order.order_time = order_fields.get('order_time')
117120
if 'trade_time' in order_fields:

0 commit comments

Comments
 (0)