zillionare-core-types


Namezillionare-core-types JSON
Version 0.6.3 PyPI version JSON
download
home_pagehttps://github.com/zillionare/zillionare_core_types
Summarycore types definition shared by zillionare.
upload_time2023-11-19 02:53:39
maintainer
docs_urlNone
authorAaron Yang
requires_python>=3.8,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
<p align="center">
<a href="https://pypi.python.org/pypi/zillionare_core_types">
    <img src="https://img.shields.io/pypi/v/zillionare_core_types.svg"
        alt = "Release Status">
</a>
<a href="#">
    <img src="https://github.com/zillionare/core-types/actions/workflows/release.yml/badge.svg" alt="CI status"/>
</a>
</p>

## 1. Usage
To use zillionare core types in a project

```
    from coretypes import Frame, FrameType
```

## 2. Features

本模块提供了在 Zillionare 中的核心类型定义。主要有:

1. 基础数据结构类的定义,比如时间帧类型 FrameType (对应于其它框架中可能使用的字符串 '1m', '1d'之类的定义), 时间日期类型 Frame, 证券类型定义 FrameType 等。在几乎所有需要使用行情数据的地方,您都应该使用这些类型定义。
2. 交易错误类型,比如 NocashError (现金不足以完成交易错误)等等。
3. QuotesFetcher 接口定义。如果您要将其它数据源接入到 zillionare 中,就需要实现这个接口,按照定义返回相应的数据。一旦实现了此接口,就可以在 zillionare-omega 配置文件中配置接口,以例 omega 可以自动启用这个 adaptor 来获取数据。

### 2.1. 基础数据结构定义

基础数据结构定义中,共有两种类型。一种是用以静态类型检查使用的,通常 IDE,mypy 这样一些工具会利用它,以检测编码错误,或者提供自动完成。比如, BarsArray 就是这样一个类型,我们可以用它来声明一个行情函数的返回值类型。它的特点时,以目前的 Python 版本(截止到 Python3.8) 来看,类型信息无法在运行时访问到。

另一类则是运行时类型,比如 FrameType 等。

#### 2.1.1. FrameType
行情数据都是按帧进行封装的,比如,每 1 分钟为一个单位,封装了高开低收、成交量等信息。这样的单位常常还有 5 分钟,15 分钟,日线等等。 FrameType 列举了在 Zillionare 中常用的帧类型。在其它软件中,您可能看到`unit`或者`peroid`、周期等说法。当然,可能 FrameType 是最精准的一个词。

Zillionare 提供了以下对应帧类型:

| 周期      | 字符串 | 类型              | 数值 |
| --------- | ------ | ----------------- | ---- |
| 年线      | 1Y     | FrameType.YEAR    | 10   |
| 季线      | 1Q     | FrameType.QUARTER | 9    |
| 月线      | 1M     | FrameType.MONTH   | 8    |
| 周线      | 1W     | FrameType.WEEK    | 7    |
| 日线      | 1D     | FrameType.DAY     | 6    |
| 60 分钟线 | 60m    | FrameType.MIN60   | 5    |
| 30 分钟线 | 30m    | FrameType.MIN30   | 4    |
| 15 分钟线 | 15m    | FrameType.MIN15   | 3    |
| 5 分钟线  | 5m     | FrameType.MIN5    | 2    |
| 分钟线    | 1m     | FrameType.MIN1    | 1    |


FrameType还提供了 `<`, `<=`, `>=`, `>`等比较运算。

#### 2.1.2. SecurityType
常见的证券交易品种定义。

| 类型                 | 值           | 说明      |
| -------------------- | ------------ | --------- |
| SecurityType.STOCK   | stock        | 股票类型  |
| SecurityType.INDEX   | index        | 指数类型  |
| SecurityType.ETF     | etf          | ETF基金   |
| SecurityType.FUND    | fund         | 基金      |
| SecurityType.LOF     | lof,LOF基金 |           |
| SecurityType.FJA     | fja          | 分级A基金 |
| SecurityType.FJB     | fjb          | 分级B基金 |
| SecurityType.BOND    | bond         | 债券基金  |
| SecurityType.STOCK_B | stock_b      | B股       |
| SecurityType.UNKNOWN | unknown      | 未知品种  |

它的一个用法是,在我们查询证券列表中,有哪些股票类型的代码时:

```python
secs = await Security.select().types(SecurityType.STOCK).eval()
print(secs)
```

#### 2.1.3. MarketType

市场类型。Zillionare支持的类型为上交所`XSHG`和`XSHE`

| 类型            | 值   | 说明   |
| --------------- | ---- | ------ |
| MarketType.XSHG | XSHG | 上交所 |
| MarketType.XSHE | XSHE | 深交所 |

#### 2.1.4. bars_dtype
在zillionare中,我们一般使用 Numpy Structured Array来存储行情数据,以使用numpy的许多性能算法进行运算。同时,它也比pandas.DataFrame更省内存,在小数据集(<50万条)时,多数运算(但不是每一种运算)会有更高的性能。

要使用 Numpy Structured Array来表示行情数据,就需要定义定段列表。 [bars_dtype](api/#coretypes.types.bars_dtype)就是这样的列表,它包括了字段(frame, open, high, low, close, volume, amount, factor)。

```python
bars_dtype = np.dtype(
    [
        ("frame", "datetime64[s]"),
        ("open", "f4"),
        ("high", "f4"),
        ("low", "f4"),
        ("close", "f4"),
        ("volume", "f8"),
        ("amount", "f8"),
        ("factor", "f4"),
    ]
)
```

#### 2.1.5. bars_dtype_with_code

在 `bars_dtype`基础上增加了`code`字段,以用于同时存取多个证券的行情的情况。

```python
bars_dtype_with_code = np.dtype(
    [
        ("code", "O"),
        ("frame", "datetime64[s]"),
        ("open", "f4"),
        ("high", "f4"),
        ("low", "f4"),
        ("close", "f4"),
        ("volume", "f8"),
        ("amount", "f8"),
        ("factor", "f4"),
    ]
)
```

#### 2.1.6. bars_cols、bars_with_limit_dtype, bars_with_limit_cols

即定义在`bars_dtype`中的字段列表。有时候我们需要在numpy与pandas dataframe之间进行转换时,往往需要这个变量的值。

`bars_with_limit_dtype`提供了带涨跌停报价的行情数据类型。

`bars_with_limit_cols`提供了定义在`bars_with_limit_dtype`中的字段名列表。

#### 2.1.7. BarsArray
可用此静态类型作为行情数据(常用变量名 `bars`)的type hint,对应于`bars_dtype`。

#### 2.1.8. BarsWithLimitArray
同`BarsArray`,但带涨跌停报价,对应于`bars_with_limit_array`。

#### 2.1.9. BarsPanel
对应于`bars_dtype_with_code`的type hint类型。

#### 2.1.10. xrxd_info_dtype
除权除息信息类型

#### 2.1.11. security_info_dtype
定义了证券列表的字段

### 2.2. Trade Errors

在coretypes.errors.trade中,定义了交易中常常可能出现的异常类型。在TradeClient, TraderServer和Backtesting Server间常常都需要使用它。

我们把Trade Errors分为客户端错误 `coretypes.errors.trade.client.*`, `coretypes.errors.trade.server.*`, `coretypes.errors.trade.entrust.*`三种类型,分别表明客户端编码、传参错误;服务器内部错误和交易类型错误。

!!! Tips
    对开发者而言,如果需要将此类异常传入到客户端,需要通过 [TraderError.as_json](api/#coretypes.errors.trade.base.TradeError.as_json)将其串行化后再通过网络发送,在客户端则可以通过[TraderError.from_json](api/#coretypes.errors.trade.base.TradeError.from_json)将其恢复。

    为方便查错,服务器在生成TradeError时,可以传入`with_stack=True`,这样生成的TraderError(及子类)中,将包含调用栈信息(在`stack`属性中),以方便查错。

```python
def foo():
    try:
        raise TraderError("mock error", with_stack=True)
    except TradeError as e:
        print(e.stack)
```

### 2.3. QuotesFetcher

Zillionare目前只适配了聚宽的数据源,但我们通过 QuotesFetcher 让您可以自行适配其它数据源。

你需要实现定义在 [QuotesFetcher](/api/#coretypes.quote_fetcher.QuotesFetcher)中的接口,然后在omega的配置文件中,加载您的实现。

具体实现可以参考 [omega-jqadaptor](https://github.com/zillionare/omega_jqadaptor)

配置可以参见[omega-config](https://github.com/zillionare/omega/blob/master/omega/config/defaults.yaml)

```yaml
# defaults.yaml

quotes_fetchers:
  - impl: jqadaptor    # there must be a create_instance method in this module
    account: ${JQ_ACCOUNT}
    password: ${JQ_PASSWORD}
```

## 3. Credits

本项目使用[ppw](https://zillionare.github.io/python-project-wizard/)创建,并遵循ppw定义的代码风格和质量规范。

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zillionare/zillionare_core_types",
    "name": "zillionare-core-types",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Aaron Yang",
    "author_email": "code@jieyu.ai",
    "download_url": "https://files.pythonhosted.org/packages/d1/9b/42b3feb12c43c74aa048d645fec075e3a4356fd8530db536d7979b7e6d41/zillionare_core_types-0.6.3.tar.gz",
    "platform": null,
    "description": "\n<p align=\"center\">\n<a href=\"https://pypi.python.org/pypi/zillionare_core_types\">\n    <img src=\"https://img.shields.io/pypi/v/zillionare_core_types.svg\"\n        alt = \"Release Status\">\n</a>\n<a href=\"#\">\n    <img src=\"https://github.com/zillionare/core-types/actions/workflows/release.yml/badge.svg\" alt=\"CI status\"/>\n</a>\n</p>\n\n## 1. Usage\nTo use zillionare core types in a project\n\n```\n    from coretypes import Frame, FrameType\n```\n\n## 2. Features\n\n\u672c\u6a21\u5757\u63d0\u4f9b\u4e86\u5728 Zillionare \u4e2d\u7684\u6838\u5fc3\u7c7b\u578b\u5b9a\u4e49\u3002\u4e3b\u8981\u6709\uff1a\n\n1. \u57fa\u7840\u6570\u636e\u7ed3\u6784\u7c7b\u7684\u5b9a\u4e49\uff0c\u6bd4\u5982\u65f6\u95f4\u5e27\u7c7b\u578b FrameType \uff08\u5bf9\u5e94\u4e8e\u5176\u5b83\u6846\u67b6\u4e2d\u53ef\u80fd\u4f7f\u7528\u7684\u5b57\u7b26\u4e32 '1m', '1d'\u4e4b\u7c7b\u7684\u5b9a\u4e49\uff09\uff0c \u65f6\u95f4\u65e5\u671f\u7c7b\u578b Frame\uff0c \u8bc1\u5238\u7c7b\u578b\u5b9a\u4e49 FrameType \u7b49\u3002\u5728\u51e0\u4e4e\u6240\u6709\u9700\u8981\u4f7f\u7528\u884c\u60c5\u6570\u636e\u7684\u5730\u65b9\uff0c\u60a8\u90fd\u5e94\u8be5\u4f7f\u7528\u8fd9\u4e9b\u7c7b\u578b\u5b9a\u4e49\u3002\n2. \u4ea4\u6613\u9519\u8bef\u7c7b\u578b\uff0c\u6bd4\u5982 NocashError \uff08\u73b0\u91d1\u4e0d\u8db3\u4ee5\u5b8c\u6210\u4ea4\u6613\u9519\u8bef\uff09\u7b49\u7b49\u3002\n3. QuotesFetcher \u63a5\u53e3\u5b9a\u4e49\u3002\u5982\u679c\u60a8\u8981\u5c06\u5176\u5b83\u6570\u636e\u6e90\u63a5\u5165\u5230 zillionare \u4e2d\uff0c\u5c31\u9700\u8981\u5b9e\u73b0\u8fd9\u4e2a\u63a5\u53e3\uff0c\u6309\u7167\u5b9a\u4e49\u8fd4\u56de\u76f8\u5e94\u7684\u6570\u636e\u3002\u4e00\u65e6\u5b9e\u73b0\u4e86\u6b64\u63a5\u53e3\uff0c\u5c31\u53ef\u4ee5\u5728 zillionare-omega \u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6e\u63a5\u53e3\uff0c\u4ee5\u4f8b omega \u53ef\u4ee5\u81ea\u52a8\u542f\u7528\u8fd9\u4e2a adaptor \u6765\u83b7\u53d6\u6570\u636e\u3002\n\n### 2.1. \u57fa\u7840\u6570\u636e\u7ed3\u6784\u5b9a\u4e49\n\n\u57fa\u7840\u6570\u636e\u7ed3\u6784\u5b9a\u4e49\u4e2d\uff0c\u5171\u6709\u4e24\u79cd\u7c7b\u578b\u3002\u4e00\u79cd\u662f\u7528\u4ee5\u9759\u6001\u7c7b\u578b\u68c0\u67e5\u4f7f\u7528\u7684\uff0c\u901a\u5e38 IDE\uff0cmypy \u8fd9\u6837\u4e00\u4e9b\u5de5\u5177\u4f1a\u5229\u7528\u5b83\uff0c\u4ee5\u68c0\u6d4b\u7f16\u7801\u9519\u8bef\uff0c\u6216\u8005\u63d0\u4f9b\u81ea\u52a8\u5b8c\u6210\u3002\u6bd4\u5982\uff0c BarsArray \u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u7c7b\u578b\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u6765\u58f0\u660e\u4e00\u4e2a\u884c\u60c5\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u3002\u5b83\u7684\u7279\u70b9\u65f6\uff0c\u4ee5\u76ee\u524d\u7684 Python \u7248\u672c\uff08\u622a\u6b62\u5230 Python3.8) \u6765\u770b\uff0c\u7c7b\u578b\u4fe1\u606f\u65e0\u6cd5\u5728\u8fd0\u884c\u65f6\u8bbf\u95ee\u5230\u3002\n\n\u53e6\u4e00\u7c7b\u5219\u662f\u8fd0\u884c\u65f6\u7c7b\u578b\uff0c\u6bd4\u5982 FrameType \u7b49\u3002\n\n#### 2.1.1. FrameType\n\u884c\u60c5\u6570\u636e\u90fd\u662f\u6309\u5e27\u8fdb\u884c\u5c01\u88c5\u7684\uff0c\u6bd4\u5982\uff0c\u6bcf 1 \u5206\u949f\u4e3a\u4e00\u4e2a\u5355\u4f4d\uff0c\u5c01\u88c5\u4e86\u9ad8\u5f00\u4f4e\u6536\u3001\u6210\u4ea4\u91cf\u7b49\u4fe1\u606f\u3002\u8fd9\u6837\u7684\u5355\u4f4d\u5e38\u5e38\u8fd8\u6709 5 \u5206\u949f\uff0c15 \u5206\u949f\uff0c\u65e5\u7ebf\u7b49\u7b49\u3002 FrameType \u5217\u4e3e\u4e86\u5728 Zillionare \u4e2d\u5e38\u7528\u7684\u5e27\u7c7b\u578b\u3002\u5728\u5176\u5b83\u8f6f\u4ef6\u4e2d\uff0c\u60a8\u53ef\u80fd\u770b\u5230`unit`\u6216\u8005`peroid`\u3001\u5468\u671f\u7b49\u8bf4\u6cd5\u3002\u5f53\u7136\uff0c\u53ef\u80fd FrameType \u662f\u6700\u7cbe\u51c6\u7684\u4e00\u4e2a\u8bcd\u3002\n\nZillionare \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u5bf9\u5e94\u5e27\u7c7b\u578b\uff1a\n\n| \u5468\u671f      | \u5b57\u7b26\u4e32 | \u7c7b\u578b              | \u6570\u503c |\n| --------- | ------ | ----------------- | ---- |\n| \u5e74\u7ebf      | 1Y     | FrameType.YEAR    | 10   |\n| \u5b63\u7ebf      | 1Q     | FrameType.QUARTER | 9    |\n| \u6708\u7ebf      | 1M     | FrameType.MONTH   | 8    |\n| \u5468\u7ebf      | 1W     | FrameType.WEEK    | 7    |\n| \u65e5\u7ebf      | 1D     | FrameType.DAY     | 6    |\n| 60 \u5206\u949f\u7ebf | 60m    | FrameType.MIN60   | 5    |\n| 30 \u5206\u949f\u7ebf | 30m    | FrameType.MIN30   | 4    |\n| 15 \u5206\u949f\u7ebf | 15m    | FrameType.MIN15   | 3    |\n| 5 \u5206\u949f\u7ebf  | 5m     | FrameType.MIN5    | 2    |\n| \u5206\u949f\u7ebf    | 1m     | FrameType.MIN1    | 1    |\n\n\nFrameType\u8fd8\u63d0\u4f9b\u4e86 `<`, `<=`, `>=`, `>`\u7b49\u6bd4\u8f83\u8fd0\u7b97\u3002\n\n#### 2.1.2. SecurityType\n\u5e38\u89c1\u7684\u8bc1\u5238\u4ea4\u6613\u54c1\u79cd\u5b9a\u4e49\u3002\n\n| \u7c7b\u578b                 | \u503c           | \u8bf4\u660e      |\n| -------------------- | ------------ | --------- |\n| SecurityType.STOCK   | stock        | \u80a1\u7968\u7c7b\u578b  |\n| SecurityType.INDEX   | index        | \u6307\u6570\u7c7b\u578b  |\n| SecurityType.ETF     | etf          | ETF\u57fa\u91d1   |\n| SecurityType.FUND    | fund         | \u57fa\u91d1      |\n| SecurityType.LOF     | lof\uff0cLOF\u57fa\u91d1 |           |\n| SecurityType.FJA     | fja          | \u5206\u7ea7A\u57fa\u91d1 |\n| SecurityType.FJB     | fjb          | \u5206\u7ea7B\u57fa\u91d1 |\n| SecurityType.BOND    | bond         | \u503a\u5238\u57fa\u91d1  |\n| SecurityType.STOCK_B | stock_b      | B\u80a1       |\n| SecurityType.UNKNOWN | unknown      | \u672a\u77e5\u54c1\u79cd  |\n\n\u5b83\u7684\u4e00\u4e2a\u7528\u6cd5\u662f\uff0c\u5728\u6211\u4eec\u67e5\u8be2\u8bc1\u5238\u5217\u8868\u4e2d\uff0c\u6709\u54ea\u4e9b\u80a1\u7968\u7c7b\u578b\u7684\u4ee3\u7801\u65f6\uff1a\n\n```python\nsecs = await Security.select().types(SecurityType.STOCK).eval()\nprint(secs)\n```\n\n#### 2.1.3. MarketType\n\n\u5e02\u573a\u7c7b\u578b\u3002Zillionare\u652f\u6301\u7684\u7c7b\u578b\u4e3a\u4e0a\u4ea4\u6240`XSHG`\u548c`XSHE`\n\n| \u7c7b\u578b            | \u503c   | \u8bf4\u660e   |\n| --------------- | ---- | ------ |\n| MarketType.XSHG | XSHG | \u4e0a\u4ea4\u6240 |\n| MarketType.XSHE | XSHE | \u6df1\u4ea4\u6240 |\n\n#### 2.1.4. bars_dtype\n\u5728zillionare\u4e2d\uff0c\u6211\u4eec\u4e00\u822c\u4f7f\u7528 Numpy Structured Array\u6765\u5b58\u50a8\u884c\u60c5\u6570\u636e\uff0c\u4ee5\u4f7f\u7528numpy\u7684\u8bb8\u591a\u6027\u80fd\u7b97\u6cd5\u8fdb\u884c\u8fd0\u7b97\u3002\u540c\u65f6\uff0c\u5b83\u4e5f\u6bd4pandas.DataFrame\u66f4\u7701\u5185\u5b58\uff0c\u5728\u5c0f\u6570\u636e\u96c6\uff08<50\u4e07\u6761\uff09\u65f6\uff0c\u591a\u6570\u8fd0\u7b97\uff08\u4f46\u4e0d\u662f\u6bcf\u4e00\u79cd\u8fd0\u7b97\uff09\u4f1a\u6709\u66f4\u9ad8\u7684\u6027\u80fd\u3002\n\n\u8981\u4f7f\u7528 Numpy Structured Array\u6765\u8868\u793a\u884c\u60c5\u6570\u636e\uff0c\u5c31\u9700\u8981\u5b9a\u4e49\u5b9a\u6bb5\u5217\u8868\u3002 [bars_dtype](api/#coretypes.types.bars_dtype)\u5c31\u662f\u8fd9\u6837\u7684\u5217\u8868\uff0c\u5b83\u5305\u62ec\u4e86\u5b57\u6bb5\uff08frame, open, high, low, close, volume, amount, factor)\u3002\n\n```python\nbars_dtype = np.dtype(\n    [\n        (\"frame\", \"datetime64[s]\"),\n        (\"open\", \"f4\"),\n        (\"high\", \"f4\"),\n        (\"low\", \"f4\"),\n        (\"close\", \"f4\"),\n        (\"volume\", \"f8\"),\n        (\"amount\", \"f8\"),\n        (\"factor\", \"f4\"),\n    ]\n)\n```\n\n#### 2.1.5. bars_dtype_with_code\n\n\u5728 `bars_dtype`\u57fa\u7840\u4e0a\u589e\u52a0\u4e86`code`\u5b57\u6bb5\uff0c\u4ee5\u7528\u4e8e\u540c\u65f6\u5b58\u53d6\u591a\u4e2a\u8bc1\u5238\u7684\u884c\u60c5\u7684\u60c5\u51b5\u3002\n\n```python\nbars_dtype_with_code = np.dtype(\n    [\n        (\"code\", \"O\"),\n        (\"frame\", \"datetime64[s]\"),\n        (\"open\", \"f4\"),\n        (\"high\", \"f4\"),\n        (\"low\", \"f4\"),\n        (\"close\", \"f4\"),\n        (\"volume\", \"f8\"),\n        (\"amount\", \"f8\"),\n        (\"factor\", \"f4\"),\n    ]\n)\n```\n\n#### 2.1.6. bars_cols\u3001bars_with_limit_dtype, bars_with_limit_cols\n\n\u5373\u5b9a\u4e49\u5728`bars_dtype`\u4e2d\u7684\u5b57\u6bb5\u5217\u8868\u3002\u6709\u65f6\u5019\u6211\u4eec\u9700\u8981\u5728numpy\u4e0epandas dataframe\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362\u65f6\uff0c\u5f80\u5f80\u9700\u8981\u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u3002\n\n`bars_with_limit_dtype`\u63d0\u4f9b\u4e86\u5e26\u6da8\u8dcc\u505c\u62a5\u4ef7\u7684\u884c\u60c5\u6570\u636e\u7c7b\u578b\u3002\n\n`bars_with_limit_cols`\u63d0\u4f9b\u4e86\u5b9a\u4e49\u5728`bars_with_limit_dtype`\u4e2d\u7684\u5b57\u6bb5\u540d\u5217\u8868\u3002\n\n#### 2.1.7. BarsArray\n\u53ef\u7528\u6b64\u9759\u6001\u7c7b\u578b\u4f5c\u4e3a\u884c\u60c5\u6570\u636e\uff08\u5e38\u7528\u53d8\u91cf\u540d `bars`)\u7684type hint\uff0c\u5bf9\u5e94\u4e8e`bars_dtype`\u3002\n\n#### 2.1.8. BarsWithLimitArray\n\u540c`BarsArray`\uff0c\u4f46\u5e26\u6da8\u8dcc\u505c\u62a5\u4ef7\uff0c\u5bf9\u5e94\u4e8e`bars_with_limit_array`\u3002\n\n#### 2.1.9. BarsPanel\n\u5bf9\u5e94\u4e8e`bars_dtype_with_code`\u7684type hint\u7c7b\u578b\u3002\n\n#### 2.1.10. xrxd_info_dtype\n\u9664\u6743\u9664\u606f\u4fe1\u606f\u7c7b\u578b\n\n#### 2.1.11. security_info_dtype\n\u5b9a\u4e49\u4e86\u8bc1\u5238\u5217\u8868\u7684\u5b57\u6bb5\n\n### 2.2. Trade Errors\n\n\u5728coretypes.errors.trade\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4ea4\u6613\u4e2d\u5e38\u5e38\u53ef\u80fd\u51fa\u73b0\u7684\u5f02\u5e38\u7c7b\u578b\u3002\u5728TradeClient, TraderServer\u548cBacktesting Server\u95f4\u5e38\u5e38\u90fd\u9700\u8981\u4f7f\u7528\u5b83\u3002\n\n\u6211\u4eec\u628aTrade Errors\u5206\u4e3a\u5ba2\u6237\u7aef\u9519\u8bef `coretypes.errors.trade.client.*`, `coretypes.errors.trade.server.*`, `coretypes.errors.trade.entrust.*`\u4e09\u79cd\u7c7b\u578b\uff0c\u5206\u522b\u8868\u660e\u5ba2\u6237\u7aef\u7f16\u7801\u3001\u4f20\u53c2\u9519\u8bef\uff1b\u670d\u52a1\u5668\u5185\u90e8\u9519\u8bef\u548c\u4ea4\u6613\u7c7b\u578b\u9519\u8bef\u3002\n\n!!! Tips\n    \u5bf9\u5f00\u53d1\u8005\u800c\u8a00\uff0c\u5982\u679c\u9700\u8981\u5c06\u6b64\u7c7b\u5f02\u5e38\u4f20\u5165\u5230\u5ba2\u6237\u7aef\uff0c\u9700\u8981\u901a\u8fc7 [TraderError.as_json](api/#coretypes.errors.trade.base.TradeError.as_json)\u5c06\u5176\u4e32\u884c\u5316\u540e\u518d\u901a\u8fc7\u7f51\u7edc\u53d1\u9001\uff0c\u5728\u5ba2\u6237\u7aef\u5219\u53ef\u4ee5\u901a\u8fc7[TraderError.from_json](api/#coretypes.errors.trade.base.TradeError.from_json)\u5c06\u5176\u6062\u590d\u3002\n\n    \u4e3a\u65b9\u4fbf\u67e5\u9519\uff0c\u670d\u52a1\u5668\u5728\u751f\u6210TradeError\u65f6\uff0c\u53ef\u4ee5\u4f20\u5165`with_stack=True`\uff0c\u8fd9\u6837\u751f\u6210\u7684TraderError(\u53ca\u5b50\u7c7b)\u4e2d\uff0c\u5c06\u5305\u542b\u8c03\u7528\u6808\u4fe1\u606f\uff08\u5728`stack`\u5c5e\u6027\u4e2d\uff09\uff0c\u4ee5\u65b9\u4fbf\u67e5\u9519\u3002\n\n```python\ndef foo():\n    try:\n        raise TraderError(\"mock error\", with_stack=True)\n    except TradeError as e:\n        print(e.stack)\n```\n\n### 2.3. QuotesFetcher\n\nZillionare\u76ee\u524d\u53ea\u9002\u914d\u4e86\u805a\u5bbd\u7684\u6570\u636e\u6e90\uff0c\u4f46\u6211\u4eec\u901a\u8fc7 QuotesFetcher \u8ba9\u60a8\u53ef\u4ee5\u81ea\u884c\u9002\u914d\u5176\u5b83\u6570\u636e\u6e90\u3002\n\n\u4f60\u9700\u8981\u5b9e\u73b0\u5b9a\u4e49\u5728 [QuotesFetcher](/api/#coretypes.quote_fetcher.QuotesFetcher)\u4e2d\u7684\u63a5\u53e3\uff0c\u7136\u540e\u5728omega\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u52a0\u8f7d\u60a8\u7684\u5b9e\u73b0\u3002\n\n\u5177\u4f53\u5b9e\u73b0\u53ef\u4ee5\u53c2\u8003 [omega-jqadaptor](https://github.com/zillionare/omega_jqadaptor)\n\n\u914d\u7f6e\u53ef\u4ee5\u53c2\u89c1[omega-config](https://github.com/zillionare/omega/blob/master/omega/config/defaults.yaml)\n\n```yaml\n# defaults.yaml\n\nquotes_fetchers:\n  - impl: jqadaptor    # there must be a create_instance method in this module\n    account: ${JQ_ACCOUNT}\n    password: ${JQ_PASSWORD}\n```\n\n## 3. Credits\n\n\u672c\u9879\u76ee\u4f7f\u7528[ppw](https://zillionare.github.io/python-project-wizard/)\u521b\u5efa\uff0c\u5e76\u9075\u5faappw\u5b9a\u4e49\u7684\u4ee3\u7801\u98ce\u683c\u548c\u8d28\u91cf\u89c4\u8303\u3002\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "core types definition shared by zillionare.",
    "version": "0.6.3",
    "project_urls": {
        "Homepage": "https://github.com/zillionare/zillionare_core_types"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cb6bc6b9b167cb3b917202c735ce765379ca4ff7230fad7504df2cde8a43e9f",
                "md5": "2456f293f16503c1d2a666d0bf34e399",
                "sha256": "111d6ccde14ce16281f7d655841160848fe828bb6d3a34c4d26287466531aa34"
            },
            "downloads": -1,
            "filename": "zillionare_core_types-0.6.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2456f293f16503c1d2a666d0bf34e399",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 15512,
            "upload_time": "2023-11-19T02:53:36",
            "upload_time_iso_8601": "2023-11-19T02:53:36.794648Z",
            "url": "https://files.pythonhosted.org/packages/6c/b6/bc6b9b167cb3b917202c735ce765379ca4ff7230fad7504df2cde8a43e9f/zillionare_core_types-0.6.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d19b42b3feb12c43c74aa048d645fec075e3a4356fd8530db536d7979b7e6d41",
                "md5": "7de788bf6574995c0d200d8ae6040dda",
                "sha256": "1d05d2ec15c085e5b519952eca787e0a74d49d362c3afe98f019d59b4f436838"
            },
            "downloads": -1,
            "filename": "zillionare_core_types-0.6.3.tar.gz",
            "has_sig": false,
            "md5_digest": "7de788bf6574995c0d200d8ae6040dda",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 17411,
            "upload_time": "2023-11-19T02:53:39",
            "upload_time_iso_8601": "2023-11-19T02:53:39.203644Z",
            "url": "https://files.pythonhosted.org/packages/d1/9b/42b3feb12c43c74aa048d645fec075e3a4356fd8530db536d7979b7e6d41/zillionare_core_types-0.6.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-19 02:53:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zillionare",
    "github_project": "zillionare_core_types",
    "github_not_found": true,
    "lcname": "zillionare-core-types"
}
        
Elapsed time: 0.16098s