Skip to main content

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())

Metadata

Release files for yufuquantsdk 0.1.1

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

Source distribution (sdist)

Source distribution for yufuquantsdk 0.1.1
File Size Uploaded
yufuquantsdk-0.1.1.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yufuquantsdk 0.1.1
File Interpreter ABI Platform
yufuquantsdk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / yufuquantsdk-0.1.1.tar.gz

Download URL yufuquantsdk-0.1.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
685d97df1170d110dbae6c8d6134d660333de01530418a030c96063aaa93015d
BLAKE2b-256 checksum
How to use checksums
a695a9313a60cd2069e7a4087efc0beab781229352e2c4253b343058dd740ffc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.8.5 Darwin/19.6.0

Release files / yufuquantsdk-0.1.1-py3-none-any.whl

Download URL yufuquantsdk-0.1.1-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9caddb0c6a1918ed096e4903b27334f91c229ad5022854d0c6563c6ae82e07ab
BLAKE2b-256 checksum
How to use checksums
75c04fb85cabf494626a7d9d4236c3ca65365448d604b4e0f9a82be81826c374
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.8.5 Darwin/19.6.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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