|
10 | 10 |
|
11 | 11 | from tigeropen.trade.response.contracts_response import ContractsResponse |
12 | 12 | from tigeropen.trade.response.order_id_response import OrderIdResponse |
| 13 | +from tigeropen.trade.response.order_preview_response import PreviewOrderResponse |
13 | 14 | from tigeropen.trade.response.orders_response import OrdersResponse |
14 | 15 | from tigeropen.tiger_open_client import TigerOpenClient, ApiException |
15 | 16 | from tigeropen.trade.request.model import ContractParams, AccountsParams, AssetParams, PositionParams, OrdersParams, \ |
16 | 17 | OrderParams, PlaceModifyOrderParams, CancelOrderParams |
17 | 18 | from tigeropen.quote.request import OpenApiRequest |
18 | 19 | from tigeropen.trade.response.assets_response import AssetsResponse |
19 | 20 | from tigeropen.common.consts.service_types import CONTRACTS, ACCOUNTS, POSITIONS, ASSETS, ORDERS, ORDER_NO, \ |
20 | | - CANCEL_ORDER, MODIFY_ORDER, PLACE_ORDER, ACTIVE_ORDERS, INACTIVE_ORDERS, FILLED_ORDERS, CONTRACT |
| 21 | + CANCEL_ORDER, MODIFY_ORDER, PLACE_ORDER, ACTIVE_ORDERS, INACTIVE_ORDERS, FILLED_ORDERS, CONTRACT, PREVIEW_ORDER |
21 | 22 |
|
22 | 23 | import logging |
23 | 24 |
|
@@ -412,6 +413,49 @@ def create_order(self, account, contract, action, order_type, quantity, limit_pr |
412 | 413 |
|
413 | 414 | return None |
414 | 415 |
|
| 416 | + def preview_order(self, order): |
| 417 | + """ |
| 418 | + 预览订单 |
| 419 | + :param order: Order 对象 |
| 420 | + :return: dict. 字段如下 |
| 421 | + init_margin_before 下单前账户初始保证金 |
| 422 | + init_margin 预计下单后的账户初始保证金 |
| 423 | + maint_margin_before 下单前账户的维持保证金 |
| 424 | + maint_margin 预计下单后的账户维持保证金 |
| 425 | + margin_currency 保证金货币币种 |
| 426 | + equity_with_loan_before 下单前账户的含借贷值股权(含贷款价值资产) |
| 427 | + equity_with_loan 下单后账户的含借贷值股权(含贷款价值资产) |
| 428 | + min_commission 预期最低佣金 |
| 429 | + max_commission 预期最高佣金 |
| 430 | + commission_currency 佣金货币币种 |
| 431 | +
|
| 432 | + 若无法下单, 返回的 dict 中仅有如下字段: |
| 433 | + warning_text 无法下单的原因 |
| 434 | + """ |
| 435 | + params = PlaceModifyOrderParams() |
| 436 | + params.account = order.account |
| 437 | + params.contract = order.contract |
| 438 | + params.action = order.action |
| 439 | + params.order_type = order.order_type |
| 440 | + params.order_id = order.order_id |
| 441 | + params.quantity = order.quantity |
| 442 | + params.limit_price = order.limit_price |
| 443 | + params.aux_price = order.aux_price |
| 444 | + params.trail_stop_price = order.trail_stop_price |
| 445 | + params.trailing_percent = order.trailing_percent |
| 446 | + params.percent_offset = order.percent_offset |
| 447 | + params.time_in_force = order.time_in_force |
| 448 | + params.outside_rth = order.outside_rth |
| 449 | + request = OpenApiRequest(PREVIEW_ORDER, biz_model=params) |
| 450 | + response_content = self.__fetch_data(request) |
| 451 | + if response_content: |
| 452 | + response = PreviewOrderResponse() |
| 453 | + response.parse_response_content(response_content) |
| 454 | + if response.is_success(): |
| 455 | + return response.preview_order |
| 456 | + else: |
| 457 | + raise ApiException(response.code, response.message) |
| 458 | + |
415 | 459 | def place_order(self, order): |
416 | 460 | """ |
417 | 461 | 下单 |
|
0 commit comments