Configurable Python SDK foundation for EasiCoin exchange integrations.
Project description
EasiFlux SDK
EasiFlux SDK(easiflux_sdk)是为量化交易与桌面客户端准备的 Python SDK,封装 EasiCoin 交易所 REST / WebSocket API。v0.2 起包名、主 Client 类名已统一为 EasiFlux 系列;旧名 easicoin_sdk 仅作兼容 shim。
命名规范
| 用途 | 名称 | 说明 |
|---|---|---|
| PyPI 安装包 | EasiFlux-SDK |
pip install EasiFlux-SDK |
| Python import | easiflux_sdk |
推荐,所有新代码应使用此包名 |
| 同步 Client | EasiFluxSDK |
主入口类 |
| 异步 Client | AsyncEasiFluxSDK |
httpx 驱动 |
| 兼容 import(deprecated) | easicoin_sdk / EasiCoinSDK |
v0.2–v0.3 可用,import 时触发 DeprecationWarning,v1.0 移除 |
# 推荐写法
from easiflux_sdk import EasiFluxSDK, AsyncEasiFluxSDK
# 旧写法(仍可用,不推荐)
from easicoin_sdk import EasiCoinSDK # = EasiFluxSDK
功能概览
当前版本默认配置对齐 EasiCoin 官方规则:
- 已实现统一请求入口和签名请求入口(Sync + Async)
- 已实现合约市场、订单、账户、持仓、资金账户和法币汇率接口
- 已实现异常体系、会话复用、重试和超时控制
- 已内置官方 Base URL、默认端点和认证请求头
v0.2 新增
- Sync + Async:
EasiFluxSDK/AsyncEasiFluxSDK(httpx) - 数据模型:
OrderRequest、OrderSide、OrderType等 dataclass - 统一响应:
SDKResponse[T](response_typed=True时启用) - 主动时间同步:
sync_on_init=True启动时对时 - WebSocket 框架:订阅/重连/事件(
client.ws.subscribe(...)) - 事件系统:
@client.on("order")装饰器(Async Client) - 结构化日志:
configure_logging(debug=True)
官方规则摘要
- REST Base URL:
https://api.easicoin.io - 私有认证请求头:
Access-Key,Access-Sign,Access-Timestamp,Recv-Window,Content-Type: application/json - 签名串规则 GET:
Access-Timestamp + Access-Key + Recv-Window + queryString - 签名串规则 POST:
Access-Timestamp + Access-Key + Recv-Window + jsonBodyString - 签名算法:
HMAC-SHA256 - 默认签名输出: 十六进制字符串
- 响应成功码:
code == 0
说明:认证页表格里对 Access-Sign 的文字描述提到了 base64,但官方 Go/Python/Java 示例全部使用十六进制输出;SDK 默认跟随示例实现为十六进制,同时保留 AuthConfig.signature_encoding 可切换为 base64。
安装
pip install EasiFlux-SDK # PyPI
pip install -e . # 本地开发
pip install -e ".[dev]" # 含测试/ lint 工具
pip install -e ".[dev,websocket]" # 含 WebSocket 依赖
测试前配置
项目根目录已经加入了 .env.dev 模板,你可以直接填入:
EASICOIN_API_KEY=
EASICOIN_API_SECRET=
EASICOIN_BASE_URL=https://api.easicoin.io
EASICOIN_SYMBOL=BTCUSDT
EASICOIN_RECV_WINDOW=5000
示例脚本 examples/basic_usage.py(同步)和 examples/async_usage.py(异步)会自动读取项目根目录下的 .env.dev。
运行方式:
.venv/bin/python examples/basic_usage.py
.venv/bin/python examples/async_usage.py
快速开始
from easiflux_sdk import AuthConfig, EasiFluxSDK, ResponseConfig
sdk = EasiFluxSDK(
api_key="your-api-key",
api_secret="your-api-secret",
auth_config=AuthConfig(
signature_encoding="hex",
),
response_config=ResponseConfig(
code_fields=("code",),
success_codes=(0, "0"),
message_fields=("msg", "message"),
),
)
server_time = sdk.get_server_time()
ticker = sdk.get_ticker(symbol="BTCUSDT")
kline = sdk.get_kline(symbol="BTCUSDT", interval="1", limit=10)
depth = sdk.get_depth(symbol="BTCUSDT", depth=20)
balances = sdk.get_balances()
positions = sdk.get_positions(symbol="BTCUSDT")
order_result = sdk.create_order(
{
"symbol": "BTCUSDT",
"position_idx": 1,
"side": "Buy",
"order_type": "Limit",
"price": "60000",
"qty": "0.001",
"time_in_force": "GoodTillCancel",
"order_link_id": "demo-order-001",
}
)
open_orders = sdk.get_open_orders(symbol="BTCUSDT")
order_history = sdk.get_orders(symbol="BTCUSDT", limit=50)
funding_balances = sdk.get_funding_balances()
fiat_rate = sdk.get_fiat_rate(["EUR", "JPY"])
异步 Client
import asyncio
from easiflux_sdk import AsyncEasiFluxSDK, OrderRequest, OrderSide, OrderType
async def main() -> None:
async with AsyncEasiFluxSDK(api_key="...", api_secret="...") as client:
ticker = await client.get_ticker(symbol="BTCUSDT")
order = OrderRequest(
symbol="BTCUSDT",
side=OrderSide.BUY,
order_type=OrderType.LIMIT,
qty="0.001",
price="50000",
)
result = await client.create_order(order)
asyncio.run(main())
完整示例见 examples/async_usage.py。
类型化下单
from easiflux_sdk import EasiFluxSDK, OrderRequest, OrderSide, OrderType, TimeInForce
order = OrderRequest(
symbol="BTCUSDT",
side=OrderSide.BUY,
order_type=OrderType.LIMIT,
qty="0.001",
price="60000",
time_in_force=TimeInForce.GOOD_TILL_CANCEL,
)
sdk.create_order(order) # 仍支持 dict 入参
设计说明
源码目录:src/easiflux_sdk/(core/、models/、transport/、websocket/ 子包)。
1. 统一请求入口
_request负责 URL 组装、query 编码、JSON 序列化、超时、重试、HTTP 错误处理和响应解析_signed_request按官方文档构造签名串,并将认证字段放入请求头- 私有请求会自动和交易所服务器对时,并在检测到时间戳错误时强制同步后重试一次
2. 交易所特有规则集中配置
AuthConfig控制请求头名称、签名编码等少量兼容项ResponseConfig控制错误码字段、成功码字段和错误消息字段endpoint_map控制各业务方法对应的接口路径
3. 已内置的默认端点
- 合约公共:
/futures/public/v1/market/time/futures/public/v1/market/tickers/futures/public/v1/market/kline/futures/public/v1/market/order-book
- 合约私有:
/futures/private/v1/account/fee-rate/futures/private/v1/account/balance/futures/private/v1/create-order/futures/private/v1/cancel-order/futures/private/v1/trade/activity-orders/futures/private/v1/trade/orders/futures/private/v1/position/list
- 资金:
/asset-api/account/private/v1/get-funding-account-balance/asset-api/account/private/v1/user-account-transfer/asset-api/fiat/public/v1/rate
当前支持的方法
get_server_time()get_ticker()get_kline()get_depth()get_trading_fee_rate()get_balances()get_positions()create_order()cancel_order()get_order()/get_open_orders()get_orders()get_funding_balances()transfer_between_accounts()get_fiat_rate()
CI / Release
- CI 会在 push 和 pull request 上执行
ruff check .、pytest -q和打包冒烟测试 - 发布流程由
vX.X.Xtag 触发,要求 tag 版本和pyproject.toml中的版本完全一致 - Release workflow 会构建 wheel 和 sdist,并同时发布到 PyPI 与 GitHub Release
- 校验文件
SHA256SUMS.txt只会附加到 GitHub Release,不会上传到 PyPI - GitHub 官方当前支持的 GitHub Packages registry 列表不包含 Python registry,因此这里没有对 GitHub Packages 做 Python 包发布;发布成功后你会在 PyPI 页面和 GitHub Releases 页面看到产物,但不会在仓库的 Packages 页面看到 Python 包
未完成部分
- WebSocket 频道报文格式需与官方文档进一步对齐(当前为可配置 adapter 框架)
- 合约分类里还有部分高级仓位接口和订单扩展接口未封装
- 目前没有真实账户联调测试,建议先用只读接口和测试仓位做烟雾验证
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easiflux_sdk-0.2.0.tar.gz.
File metadata
- Download URL: easiflux_sdk-0.2.0.tar.gz
- Upload date:
- Size: 24.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15cfbe75fd862978e13d3811123ef975439dacdfd96bf6e6fe20da31988f0da5
|
|
| MD5 |
4b2813728f5b2e5e456946e17aa03bbf
|
|
| BLAKE2b-256 |
6a48beba02303c549627021d7021bae6c0eb57e1ef56991b41e6030b12d56dcd
|
Provenance
The following attestation bundles were made for easiflux_sdk-0.2.0.tar.gz:
Publisher:
release.yml on Akiyy-dev/EasiFlux-SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easiflux_sdk-0.2.0.tar.gz -
Subject digest:
15cfbe75fd862978e13d3811123ef975439dacdfd96bf6e6fe20da31988f0da5 - Sigstore transparency entry: 1819678719
- Sigstore integration time:
-
Permalink:
Akiyy-dev/EasiFlux-SDK@aa9ad15ffce90afb49bd68f8313fea6f2879e9dc -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Akiyy-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@aa9ad15ffce90afb49bd68f8313fea6f2879e9dc -
Trigger Event:
push
-
Statement type:
File details
Details for the file easiflux_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: easiflux_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de8b5a51f7f9763085f2997a11cc72d2e2ea96129b972d4db9c7087384a63649
|
|
| MD5 |
9b1175e23412f412de00e460ddf700ea
|
|
| BLAKE2b-256 |
35f0a21d03b972f0e504d83095f955ad2955241b7557fd81fa368f63052d7155
|
Provenance
The following attestation bundles were made for easiflux_sdk-0.2.0-py3-none-any.whl:
Publisher:
release.yml on Akiyy-dev/EasiFlux-SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easiflux_sdk-0.2.0-py3-none-any.whl -
Subject digest:
de8b5a51f7f9763085f2997a11cc72d2e2ea96129b972d4db9c7087384a63649 - Sigstore transparency entry: 1819678728
- Sigstore integration time:
-
Permalink:
Akiyy-dev/EasiFlux-SDK@aa9ad15ffce90afb49bd68f8313fea6f2879e9dc -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Akiyy-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@aa9ad15ffce90afb49bd68f8313fea6f2879e9dc -
Trigger Event:
push
-
Statement type: