• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ricequant / rqalpha / 15158008555

21 May 2025 09:00AM UTC coverage: 65.116%. Remained the same
15158008555

push

github

Lin-Dongzhao
update version

6761 of 10383 relevant lines covered (65.12%)

3.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.5
/rqalpha/interface.py
1
# -*- coding: utf-8 -*-
2
# 版权所有 2019 深圳米筐科技有限公司(下称“米筐科技”)
3
#
4
# 除非遵守当前许可,否则不得使用本软件。
5
#
6
#     * 非商业用途(非商业用途指个人出于非商业目的使用本软件,或者高校、研究所等非营利机构出于教育、科研等目的使用本软件):
7
#         遵守 Apache License 2.0(下称“Apache 2.0 许可”),
8
#         您可以在以下位置获得 Apache 2.0 许可的副本:http://www.apache.org/licenses/LICENSE-2.0。
9
#         除非法律有要求或以书面形式达成协议,否则本软件分发时需保持当前许可“原样”不变,且不得附加任何条件。
10
#
11
#     * 商业用途(商业用途指个人出于任何商业目的使用本软件,或者法人或其他组织出于任何目的使用本软件):
12
#         未经米筐科技授权,任何个人不得出于任何商业目的使用本软件(包括但不限于向第三方提供、销售、出租、出借、转让本软件、
13
#         本软件的衍生产品、引用或借鉴了本软件功能或源代码的产品或服务),任何法人或其他组织不得出于任何目的使用本软件,
14
#         否则米筐科技有权追究相应的知识产权侵权责任。
15
#         在此前提下,对本软件的使用同样需要遵守 Apache 2.0 许可,Apache 2.0 许可与本许可冲突之处,以本许可为准。
16
#         详细的授权流程,请联系 public@ricequant.com 获取。
17

18
import abc
6✔
19
from datetime import datetime, date
6✔
20
from typing import Any, Union, Optional, Iterable, Dict, List, Sequence, TYPE_CHECKING
6✔
21
if TYPE_CHECKING:
6✔
22
    from rqalpha.portfolio.account import Account
×
23

24
import numpy
6✔
25
from six import with_metaclass
6✔
26
import pandas
6✔
27

28
from rqalpha.utils.typing import DateLike
6✔
29
from rqalpha.model.tick import TickObject
6✔
30
from rqalpha.model.order import Order
6✔
31
from rqalpha.model.trade import Trade
6✔
32
from rqalpha.model.instrument import Instrument
6✔
33
from rqalpha.const import POSITION_DIRECTION, TRADING_CALENDAR_TYPE, INSTRUMENT_TYPE, SIDE
6✔
34

35

36
class AbstractPosition(with_metaclass(abc.ABCMeta)):
6✔
37
    """
38
    仓位接口,主要用于构建仓位信息
39

40
    您可以在 Mod 的 start_up 阶段通过 Portfolio.register_instrument_type 来注册 Position 类型
41
    """
42

43
    @abc.abstractmethod
6✔
44
    def get_state(self):
5✔
45
        # type: () -> Any
46
        """
47
        主要用于进行持久化时候,提供对应需要持久化的数据
48
        """
49
        raise NotImplementedError
×
50

51
    @abc.abstractmethod
6✔
52
    def set_state(self, state):
5✔
53
        # type: (Any) -> None
54
        """
55
        主要用于持久化恢复时,根据提供的持久化数据进行恢复 Position 的实现
56
        """
57
        raise NotImplementedError
×
58

59
    @property
6✔
60
    @abc.abstractmethod
6✔
61
    def order_book_id(self):
5✔
62
        # type: () -> str
63
        """
64
        返回当前持仓的 order_book_id
65
        """
66
        raise NotImplementedError
×
67

68
    @property
6✔
69
    def direction(self):
5✔
70
        # type: () -> POSITION_DIRECTION
71
        """
72
        返回当前持仓的方向
73
        """
74
        raise NotImplementedError
×
75

76
    @property
6✔
77
    @abc.abstractmethod
6✔
78
    def market_value(self):
5✔
79
        # type: () -> Union[int, float]
80
        """
81
        返回当前持仓的市值
82
        """
83
        raise NotImplementedError
×
84

85
    @property
6✔
86
    @abc.abstractmethod
6✔
87
    def transaction_cost(self):
5✔
88
        # type: () -> Union[int, float]
89
        # 返回当前持仓的当日交易费用
90
        raise NotImplementedError
×
91

92
    @property
6✔
93
    @abc.abstractmethod
6✔
94
    def position_pnl(self):
5✔
95
        # type: () -> Union[int, float]
96
        """
97
        返回当前持仓当日的持仓盈亏
98
        """
99
        raise NotImplementedError
×
100

101
    @property
6✔
102
    @abc.abstractmethod
6✔
103
    def trading_pnl(self):
5✔
104
        # type: () -> Union[int, float]
105
        """
106
        返回当前持仓当日的交易盈亏
107
        """
108
        raise NotImplementedError
×
109

110
    @property
6✔
111
    @abc.abstractmethod
6✔
112
    def closable(self):
5✔
113
        # type: () -> Union[int, float]
114
        """
115
        返回可平仓位
116
        """
117
        raise NotImplementedError
×
118

119
    @property
6✔
120
    @abc.abstractmethod
6✔
121
    def today_closable(self):
5✔
122
        # type: () -> Union[int, float]
123
        """
124
        返回今仓中的可平仓位
125
        """
126
        raise NotImplementedError
×
127

128
    @property
6✔
129
    @abc.abstractmethod
6✔
130
    def quantity(self):
5✔
131
        # type: () -> Union[int, float]
132
        """
133
        返回当前持仓量
134
        """
135
        raise NotImplementedError
×
136

137
    @property
6✔
138
    @abc.abstractmethod
6✔
139
    def avg_price(self):
5✔
140
        # type: () -> Union[int, float]
141
        """
142
        开仓均价
143
        """
144
        raise NotImplementedError
×
145

146
    @property
6✔
147
    @abc.abstractmethod
6✔
148
    def pnl(self):
5✔
149
        # type: () -> float
150
        """
151
        该持仓的累计盈亏
152
        """
153
        raise NotImplementedError
×
154

155
    @property
6✔
156
    @abc.abstractmethod
6✔
157
    def equity(self):
5✔
158
        # type: () -> float
159
        """
160
        当前持仓市值
161
        """
162
        raise NotImplementedError
×
163

164
    @property
6✔
165
    @abc.abstractmethod
6✔
166
    def prev_close(self):
5✔
167
        # type: () -> float
168
        """
169
        昨日收盘价
170
        """
171
        raise NotImplementedError
×
172

173
    @property
6✔
174
    @abc.abstractmethod
6✔
175
    def last_price(self):
5✔
176
        # type: () -> float
177
        """
178
        当前最新价
179
        """
180
        raise NotImplementedError
×
181

182

183
class AbstractStrategyLoader(with_metaclass(abc.ABCMeta)):
6✔
184
    """
185
    策略加载器,其主要作用是加载策略,并将策略运行所需要的域环境传递给策略执行代码。
186

187
    在扩展模块中,可以通过调用 ``env.set_strategy_loader`` 来替换默认的策略加载器。
188
    """
189
    @abc.abstractmethod
6✔
190
    def load(self, scope):
5✔
191
        """
192
        [Required]
193

194
        load 函数负责组装策略代码和策略代码所在的域,并输出最终组装好的可执行域。
195

196
        :param dict scope: 策略代码运行环境,在传入时,包含了所有基础API。
197
            通过在 scope 中添加函数可以实现自定义API;通过覆盖 scope 中相应的函数,可以覆盖原API。
198

199
        :return: scope,其中应包含策略相应函数,如 ``init``, ``before_trading`` 等
200
        """
201
        raise NotImplementedError
×
202

203

204
class AbstractEventSource(with_metaclass(abc.ABCMeta)):
6✔
205
    """
206
    事件源接口。RQAlpha 从此对象中获取事件,驱动整个事件循环。
207

208
    在扩展模块中,可以通过调用 ``env.set_event_source`` 来替换默认的事件源。
209
    """
210
    @abc.abstractmethod
6✔
211
    def events(self, start_date, end_date, frequency):
5✔
212
        """
213
        [Required]
214

215
        扩展 EventSource 必须实现 events 函数。
216

217
        events 是一个 event generator, 在相应事件的时候需要以如下格式来传递事件
218

219
        .. code-block:: python
220

221
            yield trading_datetime, calendar_datetime, EventEnum
222

223
        其中 trading_datetime 为基于交易日的 datetime, calendar_datetime 为基于自然日的 datetime (因为夜盘的存在,交易日和自然日未必相同)
224

225
        EventEnum 为 :class:`~Events`
226

227
        :param datetime.date start_date: 起始日期, 系统会将 `config.base.start_date` 传递 events 函数
228
        :param datetime.date end_date: 结束日期,系统会将 `config.base.end_date` 传递给 events 函数
229
        :param str frequency: 周期频率,`1d` 表示日周期, `1m` 表示分钟周期
230

231
        :return: None
232
        """
233
        raise NotImplementedError
×
234

235

236
class AbstractPriceBoard(with_metaclass(abc.ABCMeta)):
6✔
237
    """
238
    RQAlpha多个地方需要使用最新「行情」,不同的数据源其最新价格获取的方式不尽相同
239

240
    因此抽离出 `AbstractPriceBoard`, 您可以自行进行扩展并替换默认 PriceBoard
241
    """
242
    @abc.abstractmethod
6✔
243
    def get_last_price(self, order_book_id):
5✔
244
        # type: (str) -> float
245
        """
246
        获取合约的最新价
247
        """
248
        raise NotImplementedError
×
249

250
    @abc.abstractmethod
6✔
251
    def get_limit_up(self, order_book_id):
5✔
252
        # type: (str) -> float
253
        """
254
        获取合约的涨停价
255
        """
256
        raise NotImplementedError
×
257

258
    @abc.abstractmethod
6✔
259
    def get_limit_down(self, order_book_id):
5✔
260
        # type: (str) -> float
261
        """
262
        获取合约的跌停价
263
        """
264
        raise NotImplementedError
×
265

266
    def get_a1(self, order_book_id):
6✔
267
        # type: (str) -> Union[float, numpy.nan]
268
        """
269
        获取合约的卖一价
270
        """
271
        raise NotImplementedError
×
272

273
    def get_b1(self, order_book_id):
6✔
274
        # type: (str) -> Union[float, numpy.nan]
275
        """
276
        获取合约的买一价
277
        """
278
        raise NotImplementedError
×
279

280

281
class AbstractDataSource(object):
6✔
282
    """
283
    数据源接口。RQAlpha 中通过 :class:`DataProxy` 进一步进行了封装,向上层提供更易用的接口。
284

285
    在扩展模块中,可以通过调用 ``env.set_data_source`` 来替换默认的数据源。可参考 :class:`BaseDataSource`。
286
    """
287

288
    def get_instruments(self, id_or_syms=None, types=None):
6✔
289
        # type: (Optional[Iterable[str]], Optional[Iterable[INSTRUMENT_TYPE]]) -> Iterable[Instrument]
290
        """
291
        获取 instrument,
292
        可指定 order_book_id 或 symbol 或 instrument type,id_or_syms 优先级高于 types,
293
        id_or_syms 和 types 均为 None 时返回全部 instruments
294
        """
295
        raise NotImplementedError
×
296

297
    def get_trading_calendars(self):
6✔
298
        # type: () -> Dict[TRADING_CALENDAR_TYPE, pandas.DatetimeIndex]
299
        """
300
        获取交易日历,DataSource 应返回所有支持的交易日历种类
301
        """
302
        raise NotImplementedError
×
303

304
    def get_yield_curve(self, start_date, end_date, tenor=None):
6✔
305
        """
306
        获取国债利率
307

308
        :param pandas.Timestamp str start_date: 开始日期
309
        :param pandas.Timestamp end_date: 结束日期
310
        :param str tenor: 利率期限
311

312
        :return: pandas.DataFrame, [start_date, end_date]
313
        """
314
        raise NotImplementedError
×
315

316
    def get_dividend(self, instrument):
6✔
317
        # type: (Instrument) -> numpy.ndarray
318
        """
319
        获取股票/基金分红信息
320
        """
321
        raise NotImplementedError
×
322

323
    def get_split(self, instrument):
6✔
324
        # type: (Instrument) -> numpy.ndarray
325
        """
326
        获取拆股信息
327
        """
328
        raise NotImplementedError
×
329

330
    def get_bar(self, instrument, dt, frequency):
6✔
331
        """
332
        根据 dt 来获取对应的 Bar 数据
333

334
        :param instrument: 合约对象
335
        :type instrument: :class:`~Instrument`
336

337
        :param datetime.datetime dt: calendar_datetime
338

339
        :param str frequency: 周期频率,`1d` 表示日周期, `1m` 表示分钟周期
340

341
        :return: `numpy.ndarray` | `dict`
342
        """
343
        raise NotImplementedError
×
344

345
    def get_open_auction_bar(self, instrument, dt):
6✔
346
        # type: (Instrument, Union[datetime, date]) -> Dict
347
        """
348
        获取指定资产当日的集合竞价 Bar 数据,该 Bar 数据应包含的字段有:
349
            datetime, open, limit_up, limit_down, volume, total_turnover
350
        """
351
        raise NotImplementedError
×
352
    
353
    def get_open_auction_volume(self, instrument, dt):
6✔
354
        """
355
        获取指定资产当日的集合竞价成交量
356

357
        :param instrument: 合约对象
358
        :type instrument: class:`~Instrument`
359

360
        :param dt: 集合竞价时间
361
        :type dt: datetime.datetime
362

363
        :return: `float`
364
        """
365
        raise NotImplementedError
×
366

367
    def get_settle_price(self, instrument, date):
6✔
368
        """
369
        获取期货品种在 date 的结算价
370

371
        :param instrument: 合约对象
372
        :type instrument: :class:`~Instrument`
373

374
        :param datetime.date date: 结算日期
375

376
        :return: `str`
377
        """
378
        raise NotImplementedError
×
379

380
    def history_bars(self, instrument, bar_count, frequency, fields, dt, skip_suspended=True,
6✔
381
                     include_now=False, adjust_type='pre', adjust_orig=None):
382
        """
383
        获取历史数据
384

385
        :param instrument: 合约对象
386
        :type instrument: :class:`~Instrument`
387

388
        :param int bar_count: 获取的历史数据数量
389
        :param str frequency: 周期频率,`1d` 表示日周期, `1m` 表示分钟周期
390
        :param str fields: 返回数据字段
391

392
        =========================   ===================================================
393
        fields                      字段名
394
        =========================   ===================================================
395
        datetime                    时间戳
396
        open                        开盘价
397
        high                        最高价
398
        low                         最低价
399
        close                       收盘价
400
        volume                      成交量
401
        total_turnover              成交额
402
        datetime                    int类型时间戳
403
        open_interest               持仓量(期货专用)
404
        basis_spread                期现差(股指期货专用)
405
        settlement                  结算价(期货日线专用)
406
        prev_settlement             结算价(期货日线专用)
407
        =========================   ===================================================
408

409
        :param datetime.datetime dt: 时间
410
        :param bool skip_suspended: 是否跳过停牌日
411
        :param bool include_now: 是否包含当天最新数据
412
        :param str adjust_type: 复权类型,'pre', 'none', 'post'
413
        :param datetime.datetime adjust_orig: 复权起点;
414

415
        :return: `Optional[numpy.ndarray]`, fields 不合法时返回 None
416

417
        """
418
        raise NotImplementedError
×
419

420
    def history_ticks(self, instrument, count, dt):
6✔
421
        # type: (Instrument, int, datetime) -> List[TickObject]
422
        """
423
        获取指定合约历史 tick 对象
424

425
        :param instrument: 合约对象
426
        :param int count: 获取的 tick 数量
427
        :param dt: 时间
428

429
        """
430
        raise NotImplementedError
×
431

432
    def current_snapshot(self, instrument, frequency, dt):
6✔
433
        """
434
        获得当前市场快照数据。只能在日内交易阶段调用,获取当日调用时点的市场快照数据。
435
        市场快照数据记录了每日从开盘到当前的数据信息,可以理解为一个动态的day bar数据。
436
        在目前分钟回测中,快照数据为当日所有分钟线累积而成,一般情况下,最后一个分钟线获取到的快照数据应当与当日的日线行情保持一致。
437
        需要注意,在实盘模拟中,该函数返回的是调用当时的市场快照情况,所以在同一个handle_bar中不同时点调用可能返回的数据不同。
438
        如果当日截止到调用时候对应股票没有任何成交,那么snapshot中的close, high, low, last几个价格水平都将以0表示。
439

440
        :param instrument: 合约对象
441
        :type instrument: :class:`~Instrument`
442

443
        :param str frequency: 周期频率,`1d` 表示日周期, `1m` 表示分钟周期
444
        :param datetime.datetime dt: 时间
445

446
        :return: :class:`~Snapshot`
447
        """
448
        raise NotImplementedError
×
449

450
    def get_trading_minutes_for(self, instrument, trading_dt):
6✔
451
        """
452
        获取证券某天的交易时段,用于期货回测
453

454
        :param instrument: 合约对象
455
        :type instrument: :class:`~Instrument`
456

457
        :param datetime.datetime trading_dt: 交易日。注意期货夜盘所属交易日规则。
458

459
        :return: list[`datetime.datetime`]
460
        """
461
        raise NotImplementedError
×
462

463
    def available_data_range(self, frequency):
6✔
464
        """
465
        此数据源能提供数据的时间范围
466

467
        :param str frequency: 周期频率,`1d` 表示日周期, `1m` 表示分钟周期
468

469
        :return: (earliest, latest)
470
        """
471
        raise NotImplementedError
×
472

473
    def get_futures_trading_parameters(self, instrument, dt):
6✔
474
        """
475
        获取期货合约的时序手续费信息
476
        :param instrument: 合约对象
477
        :type instrument: :class:`~Instrument`
478

479
        :param datetime.datetime dt: 交易日
480
        
481
        :return: :class:`FuturesTradingParameters`
482
        """
483
        raise NotImplementedError
×
484

485
    def get_merge_ticks(self, order_book_id_list, trading_date, last_dt=None):
6✔
486
        """
487
        获取合并的 ticks
488

489
        :param list order_book_id_list: 合约名列表
490
        :param datetime.date trading_date: 交易日
491
        :param datetime.datetime last_dt: 仅返回 last_dt 之后的时间
492

493
        :return: Iterable object of Tick
494
        """
495
        raise NotImplementedError
×
496

497
    def get_share_transformation(self, order_book_id):
6✔
498
        """
499
        获取股票转换信息
500
        :param order_book_id: 合约代码
501
        :return: (successor, conversion_ratio), (转换后的合约代码,换股倍率)
502
        """
503
        raise NotImplementedError
×
504

505
    def is_suspended(self, order_book_id, dates):
6✔
506
        # type: (str, Sequence[DateLike]) -> Sequence[bool]
507
        raise NotImplementedError
×
508

509
    def is_st_stock(self, order_book_id, dates):
6✔
510
        # type: (str, Sequence[DateLike]) -> Sequence[bool]
511
        raise NotImplementedError
×
512

513
    def get_algo_bar(self, id_or_ins, start_min, end_min, dt):
6✔
514
        # type: (Union[str, Instrument], int, int, datetime) -> Optional[numpy.void]
515
        # 格式: (date, VWAP, TWAP, volume) -> 案例 (20200102, 16.79877183, 16.83271429, 144356044)
516
        raise NotImplementedError
×
517

518

519
class AbstractBroker(with_metaclass(abc.ABCMeta)):
6✔
520
    """
521
    券商接口。
522

523
    RQAlpha 将产生的订单提交给此对象,此对象负责对订单进行撮合(不论是自行撮合还是委托给外部的真实交易所),
524
    并通过 ``EVENT.ORDER_*`` 及 ``EVENT.TRADE`` 事件将撮合结果反馈进入 RQAlpha。
525

526
    在扩展模块中,可以通过调用 ``env.set_broker`` 来替换默认的 Broker。
527
    """
528

529
    @abc.abstractmethod
6✔
530
    def submit_order(self, order):
5✔
531
        # type: (Order) -> None
532
        # 提交订单。RQAlpha 会生成 :class:`~Order` 对象,再通过此接口提交到 Broker。
533
        raise NotImplementedError
×
534

535
    @abc.abstractmethod
6✔
536
    def cancel_order(self, order):
5✔
537
        """
538
        [Required]
539

540
        撤单。
541

542
        :param order: 订单
543
        :type order: :class:`~Order`
544
        """
545
        raise NotImplementedError
×
546

547
    @abc.abstractmethod
6✔
548
    def get_open_orders(self, order_book_id=None):
6✔
549
        """
550
        [Required]
551

552
        获得当前未完成的订单。
553

554
        :return: list[:class:`~Order`]
555
        """
556
        raise NotImplementedError
×
557

558

559
class AbstractMod(with_metaclass(abc.ABCMeta)):
6✔
560
    """
561
    扩展模块接口。
562
    """
563
    @abc.abstractmethod
6✔
564
    def start_up(self, env, mod_config):
5✔
565
        """
566
        RQAlpha 在系统启动时会调用此接口;在此接口中,可以通过调用 ``env`` 的相应方法来覆盖系统默认组件。
567

568
        :param env: 系统环境
569
        :type env: :class:`~Environment`
570
        :param mod_config: 模块配置参数
571
        """
572
        raise NotImplementedError
×
573

574
    def tear_down(self, code, exception=None):
6✔
575
        """
576
        RQAlpha 在系统退出前会调用此接口。
577

578
        :param code: 退出代码
579
        :type code: rqalpha.const.EXIT_CODE
580
        :param exception: 如果在策略执行过程中出现错误,此对象为相应的异常对象
581
        """
582
        raise NotImplementedError
×
583

584

585
class AbstractPersistProvider(with_metaclass(abc.ABCMeta)):
6✔
586
    """
587
    持久化服务提供者接口。
588

589
    扩展模块可以通过调用 ``env.set_persist_provider`` 接口来替换默认的持久化方案。
590
    """
591
    @abc.abstractmethod
6✔
592
    def store(self, key, value):
5✔
593
        """
594
        store
595

596
        :param str key:
597
        :param bytes value:
598
        :return:
599
        """
600
        raise NotImplementedError
×
601

602
    @abc.abstractmethod
6✔
603
    def load(self, key):
5✔
604
        """
605
        :param str key:
606
        :return: bytes 如果没有对应的值,返回 None
607
        """
608
        raise NotImplementedError
×
609

610
    @abc.abstractmethod
6✔
611
    def should_resume(self):
5✔
612
        """
613
        是否应该以 resume 模式运行
614
        :return: bool
615
        """
616
        raise NotImplementedError
×
617

618
    @abc.abstractmethod
6✔
619
    def should_run_init(self):
5✔
620
        """
621
        是否应该执行策略的 init 函数
622
        :return: bool
623
        """
624
        raise NotImplementedError
×
625

626

627
class Persistable(with_metaclass(abc.ABCMeta)):
6✔
628
    @abc.abstractmethod
6✔
629
    def get_state(self):
5✔
630
        """
631
        :return: bytes
632
        """
633
        raise NotImplementedError
×
634

635
    @abc.abstractmethod
6✔
636
    def set_state(self, state):
5✔
637
        """
638
        :param state: bytes
639
        :return:
640
        """
641
        raise NotImplementedError
×
642

643
    @classmethod
6✔
644
    def __subclasshook__(cls, C):
5✔
645
        if cls is Persistable:
×
646
            if (any("get_state" in B.__dict__ for B in C.__mro__) and
×
647
                    any("set_state" in B.__dict__ for B in C.__mro__)):
648
                return True
×
649
        return NotImplemented
×
650

651

652
class AbstractFrontendValidator(with_metaclass(abc.ABCMeta)):
6✔
653
    """
654
    前端风控接口,下撤单请求在到达券商代理模块前会经过前端风控。
655

656
    扩展模块可以通过 env.add_frontend_validator 添加自定义的前端风控逻辑
657
    """
658
    @abc.abstractmethod
6✔
659
    def validate_submission(self, order: Order, account: Optional['Account'] = None) -> Optional[str]:
6✔
660
        """
661
        进行下单前的验证,若通过则返回 None
662

663
        :return: `Optional[str]`
664
        """
665
        raise NotImplementedError
×
666
    
667
    @abc.abstractmethod
6✔
668
    def validate_cancellation(self, order: Order, account: Optional['Account'] = None) -> Optional[str]:
6✔
669
        """
670
        进行撤销订单前的验证,若通过则返回 None
671

672
        :return: `Optional[str]`
673
        """
674
        raise NotImplementedError
×
675

676

677
class AbstractTransactionCostDecider((with_metaclass(abc.ABCMeta))):
6✔
678
    """
679
    订单税费计算接口,通过实现次接口可以定义不同市场、不同合约的个性化税费计算逻辑。
680
    """
681
    @abc.abstractmethod
6✔
682
    def get_trade_tax(self, trade: Trade) -> float:
6✔
683
        """
684
        计算指定交易应付的印花税
685
        """
686
        raise NotImplementedError
×
687

688
    @abc.abstractmethod
6✔
689
    def get_trade_commission(self, trade: Trade) -> float:
6✔
690
        """
691
        计算指定交易应付的佣金
692
        """
693
        raise NotImplementedError
×
694

695
    @abc.abstractmethod
6✔
696
    def get_order_transaction_cost(self, order: Order) -> float:
6✔
697
        """
698
        计算指定订单应付的交易成本(税 + 费)
699
        """
700
        raise NotImplementedError
×
701
    
702
    def get_transaction_cost_with_value(self, value: float, side: SIDE) -> float:
6✔
703
        """
704
        计算指定价格交易应付的交易成本(税 + 费)
705
        """
706
        raise NotImplementedError
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc