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.1.tar.gz
(5.7 kB
view details)
Built Distribution
File details
Details for the file yufuquantsdk-0.1.1.tar.gz
.
File metadata
- Download URL: yufuquantsdk-0.1.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.5 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 685d97df1170d110dbae6c8d6134d660333de01530418a030c96063aaa93015d |
|
MD5 | eb119d4725e03895aeb4e2ab23d5ed17 |
|
BLAKE2b-256 | a695a9313a60cd2069e7a4087efc0beab781229352e2c4253b343058dd740ffc |
File details
Details for the file yufuquantsdk-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: yufuquantsdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.5 Darwin/19.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9caddb0c6a1918ed096e4903b27334f91c229ad5022854d0c6563c6ae82e07ab |
|
MD5 | 3ada2f1419d61fade48e993f0704e3b6 |
|
BLAKE2b-256 | 75c04fb85cabf494626a7d9d4236c3ca65365448d604b4e0f9a82be81826c374 |