Skip to main content

exsdk · 易行量化

面向期货、期权策略开发的 Python SDK,提供合约查询、实时行情、期货 K 线和直连 CTP 交易。 通过简洁的同步接口,策略可以持续读取行情、计算指标并响应数据变化。

快速开始

安装:

pip install exsdk

在 官网 获取 Token 后,连接行情和 K 线。

连接示例:

from exsdk import ExApi

with ExApi("YOUR_TOKEN") as api:
    symbol = "SHFE.au9999"  # 黄金主连,不复权,按服务更新自动换月。
    quote = api.watch_quote(symbol)
    klines = api.watch_kline(symbol, "1m", data_length=200)

    while api.wait_update():
        if quote.is_changing("last_price"):
            print("最新价", quote.data().last_price)

        if klines.is_changing("timestamp"):
            print("新 K 线", klines.data().iloc[-1].to_dict())

连接交易账户并读取资金(资金账号须与 官网 绑定的期货账号一致):

from exsdk import ExApi, CtpAccount

ctp_account = CtpAccount(
    broker_id="期货公司代码",
    user_id="资金账号",
    password="交易密码",
    front_url="tcp://期货公司提供的地址:端口",
    app_id="期货公司提供的 AppID",
    auth_code="期货公司提供的授权码",
)

with ExApi("YOUR_TOKEN", ctp_account) as api:
    account = api.watch_account()
    while api.wait_update():
        if api.trading_status() == "READY" and account.is_changing("available"):
            print("柜台可用资金", account.data().available)

交易账户同步完成后才进入 READY。行情或交易连接中断时,data() 保留最近一次快照;策略使用前应检查交易状态和行情时间戳。

系统架构

flowchart TD
    Broker[期货公司交易柜台]
    Market[官方期货、期权行情系统]
    SDK[exsdk]

    Broker <-->|直连 CTP| SDK
    Market -->|行情接口| SDK

    classDef source fill:#f3f4f6,stroke:#9ca3af,color:#111;
    classDef sdk fill:#dbeafe,stroke:#598bea,stroke-width:2px,color:#111;

    class Broker,Market source;
    class SDK sdk;
  • 策略始终运行在用户本地环境中,策略代码与交易信号计算均保留在本地。
  • 交易连接由本地 SDK 直接建立到期货公司柜台,交易账号、密码和委托不经过行情服务。

主要功能

  • 合约查询:按交易所、品种、期货/期权和是否主力筛选合约,获取合约详细信息。
  • 主力连续:以 9999 结尾的主连行情与 K 线,查询当前标的和历史换月记录;交易使用具体合约。
  • 实时行情:通过 Quote 对象读取期货、期权的最新价格、成交量、持仓量和盘口。
  • 期货 K 线序列:通过 pandas DataFrame 获取历史与实时 K 线,支持多种周期;期权暂不提供 K 线。
  • CTP 交易:读取账户资金及期货、期权的持仓、订单与成交,支持普通投机限价下单与撤单。
  • 统一更新:使用 wait_update() 推进更新,通过观察句柄的 is_changing() 判断变化、data() 读取快照。
  • 连接管理:自动连接官方数据服务,支持断线重连和订阅恢复。

完整接口、周期取值、数据字段和使用约定见 SDK 使用指南。使用前请阅读免责声明。

Metadata

Release files for exsdk 1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for exsdk 1.8
File Actions
exsdk-1.8-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for exsdk-1.8-cp314-cp314-win_amd64.whl
exsdk-1.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for exsdk-1.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
exsdk-1.8-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for exsdk-1.8-cp314-cp314-macosx_11_0_arm64.whl
exsdk-1.8-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for exsdk-1.8-cp313-cp313-win_amd64.whl
exsdk-1.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for exsdk-1.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
exsdk-1.8-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for exsdk-1.8-cp313-cp313-macosx_11_0_arm64.whl
exsdk-1.8-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for exsdk-1.8-cp312-cp312-win_amd64.whl
exsdk-1.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for exsdk-1.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
exsdk-1.8-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for exsdk-1.8-cp312-cp312-macosx_11_0_arm64.whl

Total release size: 42.0 MB

Release files / exsdk-1.8-cp314-cp314-win_amd64.whl

Download URL exsdk-1.8-cp314-cp314-win_amd64.whl
Size 2.2 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
1d6a7d52fc832cdf24c9390b04261802ed81f7b88c22748e8f4ca2dd5975b8be
BLAKE2b-256 checksum
How to use checksums
ce8a66fa8474d428c2426d73001b25a373a9236480603f478b04b2c635638c97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / exsdk-1.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL exsdk-1.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 6.7 MB
Tags CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
0e8f41b4545c89bd07839fd419fa2e7128fabc2f7d844eea3e222b5c21ee9cb2
BLAKE2b-256 checksum
How to use checksums
70ff5a88e9c00538573f37cbb26b3fcaa74bd528a67c2809750e59f2d990b66c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / exsdk-1.8-cp314-cp314-macosx_11_0_arm64.whl

Download URL exsdk-1.8-cp314-cp314-macosx_11_0_arm64.whl
Size 5.1 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6792bc1029da77530150dad47131258b666528190647161960fb9686e0fa5d6f
BLAKE2b-256 checksum
How to use checksums
88b85492508aa6d4c731e4334339c3861819513584b4ebb46c7f6c51a839af9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / exsdk-1.8-cp313-cp313-win_amd64.whl

Download URL exsdk-1.8-cp313-cp313-win_amd64.whl
Size 2.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
f9ca139580d53f23de54377086d71608e9022ef91b1187782b847a08c11a3db7
BLAKE2b-256 checksum
How to use checksums
710914f491933f5e73d580c0355e2066186586429bc3203400b2e930423eb0e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / exsdk-1.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL exsdk-1.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 6.8 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
636effe694fc0c684fd4ace23fc8fa14386ba64798bd3d08a56a67c5a975e0ae
BLAKE2b-256 checksum
How to use checksums
9579d2dd6d5e1fd874329fbd5e17000dc1726b176be76f2a2b13f8a6761ca56f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / exsdk-1.8-cp313-cp313-macosx_11_0_arm64.whl

Download URL exsdk-1.8-cp313-cp313-macosx_11_0_arm64.whl
Size 5.1 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b334b317b1c1b32322ffdb6c49da5ba5d30a719236e668a93f709216a683abea
BLAKE2b-256 checksum
How to use checksums
bc3df7064b434e150c115bb81817c1e8daffc8e1db12e855a93cd4f200b6cc16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / exsdk-1.8-cp312-cp312-win_amd64.whl

Download URL exsdk-1.8-cp312-cp312-win_amd64.whl
Size 2.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
56a47c3e6ba085e182c0ed8405fdd7554a5332a820718fbd462068f32f689050
BLAKE2b-256 checksum
How to use checksums
dd23878dc7d2cb28a4465e1dc4b3d22b03e034fb33a869d8e6374b7aa381410c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / exsdk-1.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL exsdk-1.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 6.8 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
43e6a9088b8034854dbf8e709d15a07308b03d2e43c3790373709c42743c022e
BLAKE2b-256 checksum
How to use checksums
133067e5cc39b7db5ee2361c42bf95243c44b7722ec52eab02c0399db45bfe69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / exsdk-1.8-cp312-cp312-macosx_11_0_arm64.whl

Download URL exsdk-1.8-cp312-cp312-macosx_11_0_arm64.whl
Size 5.1 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2e9f121227b8dc99ca65735563c2f58ff5090ed086b350b75703f683df25469a
BLAKE2b-256 checksum
How to use checksums
8bf29b36f1fb9cf5b52854d9a27e81cef1ab5ea2e55bd9b334d4908fc60852cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for exsdk 1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for exsdk-1.8-cp314-cp314-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page