SDK for yufuquant development.
Project description
yufuquant SDK
yufuquant SDK 封装了用于和 yufuquant 后端进行交互的常用方法。
yufuquant SDK 目前只支持 Python,由于大多数 API 都是基于 asyncio 的异步 API,因此要求 Python 的最低版本为 Python 3.7,推荐使用 Python 3.8。
安装
$ pip install yufuquantsdk
REST API 客户端
REST API 客户端用于和 yufuquant 后端的 RESTful API 进行交互。
from yufuquantsdk.clients import RESTAPIClient
base_url="https://yufuquant.cc/api/v1" # 系统后端接口地址
auth_token="xxxxx" # 认证令牌
robot_id = 1 # 机器人 id
rest_api_client = RESTAPIClient(base_url=base_url, auth_token=auth_token)
# 获取机器人配置
await rest_api_client.get_robot_config(robot_id)
# 更新机器人的资产信息
data = {
"total_balance": 5.8
}
await rest_api_client.patch_robot_asset_record(robot_id, data)
# 发送 ping
await rest_api_client.post_robot_ping(robot_id)
以下是一个完整的示例:
import logging
from pprint import pprint
from yufuquantsdk.clients import RESTAPIClient
# 开启日志
logger = logging.getLogger("yufuquantsdk")
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
async def main():
http_client = RESTAPIClient(
base_url="https://yufuquant.cc/api/v1",
auth_token="8g2e470579ba14ea69000859eba6c421b69ff95d",
)
result = await http_client.get_robot_config(robot_id=1)
pprint(result)
result = await http_client.post_robot_ping(robot_id=1)
pprint(result)
result = await http_client.patch_robot_asset_record(
robot_id=1, data={"total_balance": 10000}
)
pprint(result)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Websocket API 客户端
Websocket API 客户端用于和 yufuquant 后端的 Websocket API 进行交互。
from yufuquantsdk.clients import WebsocketAPIClient
uri="wss://yufuquant.cc/ws/v1/streams/" # 系统后端接口地址
auth_token="xxxxx" # 认证令牌
topics = ["robot#1.ping", "robot#1.log"] # 订阅的话题
ws_api_client = WebsocketAPIClient(uri=uri)
# 认证
await ws_api_client.auth(auth_token)
# 订阅话题
await ws_api_client.sub(topics)
# 取消话题订阅
await ws_api_client.unsub(topics)
# 发送机器人 ping
await ws_api_client.robot_ping()
# 发送机器人日志
await ws_api_client.robot_log()
以下是一个完整的示例:
import logging
from yufuquantsdk.clients import WebsocketAPIClient
# 开启日志
logger = logging.getLogger("yufuquantsdk")
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
async def main():
ws_api_client = WebsocketAPIClient(uri="wss://yufuquant.cc/ws/v1/streams/")
await ws_api_client.auth("8d2e470575ba04ea69000859eba6c421a69ff95c")
await ws_api_client.sub(topics=["robot#1.log"])
while True:
await ws_api_client.robot_ping()
await ws_api_client.robot_log("Test robot log...", level="INFO")
await asyncio.sleep(1)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
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
yufuquantsdk-0.1.0.tar.gz
(5.6 kB
view details)
Built Distribution
File details
Details for the file yufuquantsdk-0.1.0.tar.gz
.
File metadata
- Download URL: yufuquantsdk-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.0b2 CPython/3.8.2 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a74a0800adac8bc59cc36e3299d9f345947b202c86ea298c91f587b52682ba6e |
|
MD5 | fbdaaae26559733234f17de3617ffab3 |
|
BLAKE2b-256 | fceaad7bf441278d4a6a6f548f3b42418edac4f49342c5e7211838923d289341 |
File details
Details for the file yufuquantsdk-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: yufuquantsdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.0b2 CPython/3.8.2 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72b7e15b09c0ff95ebef5f34ff8b61f281d8607b693e9d2b286fa987f2406cf3 |
|
MD5 | 1bae90bc8d110a0172a06521f0734558 |
|
BLAKE2b-256 | a667018b66847c1d3faeb0dde4a1d1622fd1be617f0ed006b3ae819e11e265ae |