rgo-trading-api

rgo-trading-api

Enables AI assistants to read positions, deals, and orders from the RGO trading platform via natural language, with optional trading capabilities when explicitly enabled.

Category
访问服务器

README

RGO Trading API — Python client, CLI & MCP server

A Python toolkit for the RGO Client API and Dealer API (a trading order/position system). It ships three layers so you can use it however you like:

Layer Entry point Use it for
Library rgo_api/ Import in your own Python code
CLI cli.py Explicit commands (python cli.py positions)
MCP server mcp_server.py Ask an AI assistant in plain English (Claude CLI, etc.)

⚠️ This places REAL trades. Order placement/update/deletion is gated behind a config flag (RGO_ALLOW_TRADING) and is off by default. Reads are always safe. See Safety.


Features

  • Dealer reads: executed deals, pending orders, all positions.
  • Order writes on both the Client and Dealer APIs: place, update, delete (opt-in).
  • Realtime deals via WebSocket (DealerApi.ws_stream).
  • Natural-language access through the Model Context Protocol (MCP): ask "show my open positions" and let your AI client call the right tool.
  • Typed, validated requests (Pydantic v2), a single shared HTTP layer, and a test suite that mocks all network calls (no real trades in CI).

See docs/API.md for the full endpoint reference and docs/MCP.md for AI-assistant setup.


Requirements

  • Python 3.10+
  • An RGO account with API access (credentials + your broker's endpoints)

Install

git clone https://github.com/bhdhiman/rgo-trading-api.git
cd rgo-trading-api

python -m venv .venv
# Windows:
.venv\Scripts\python -m pip install -r requirements.txt
# macOS/Linux:
# .venv/bin/python -m pip install -r requirements.txt

Configure

cp .env.example .env      # then edit .env with your real values

.env is gitignored — your credentials never get committed.

Variable Meaning
RGO_LICENSE_ID Your license id
RGO_DEALER_USERNAME / RGO_DEALER_PASSWORD Dealer login (for the read JWT)
RGO_API_USERNAME / RGO_API_PASSWORD Header credentials for order writes
RGO_CLIENT_BASE Client API base URL, e.g. https://api.YOUR_DOMAIN:6017/clientapi
RGO_DEALER_BASE_READ Dealer read base URL (e.g. port 9016)
RGO_DEALER_BASE_WRITE Dealer write base URL (may use a different port, e.g. 6016)
RGO_WS_URL Realtime WebSocket URL
RGO_ALLOW_TRADING false by default — set true to enable REAL orders

Usage — CLI

# Reads (safe)
python cli.py positions
python cli.py deals
python cli.py orders

# Writes (need RGO_ALLOW_TRADING=true AND --yes)
python cli.py place --api dealer --user <ACCOUNT> --type BuyLimit \
    --side BID --price 1 --volume 1 --current 94000 --symbol GOLDOCT --yes
python cli.py delete --api dealer --position <POSITION_ID> --yes

Usage — library

from rgo_api import DealerApi, load_settings

with DealerApi(load_settings()) as api:
    positions = api.get_positions()
    deals = api.get_deals()
    pending = api.get_pending_orders()

Usage — AI assistant (MCP)

Register the server with your MCP-capable client (e.g. the Claude CLI), then ask in plain English:

  • "show my open positions"
  • "list today's deals"
  • "what orders are pending?"

Full setup (registration + generic MCP client) is in docs/MCP.md.


Safety

This software can place real financial orders. Guardrails:

  • Credentials live only in .env (gitignored). Nothing is hardcoded.
  • Trading is opt-in. Place/update/delete refuse to run unless RGO_ALLOW_TRADING=true; the CLI additionally requires --yes.
  • Inputs are validated (side, order type, positive price/volume) before any request is sent.

You are responsible for any orders you place. No warranty — see LICENSE.


Tests

python -m pytest --cov=rgo_api

All HTTP is mocked with respx; tests never contact a live server or place trades.

Project structure

rgo_api/        # client library
  config.py     # settings from .env
  models.py     # request models + response-envelope parsing
  _http.py      # shared httpx transport
  dealer_api.py # dealer reads + writes + websocket
  client_api.py # client order writes
cli.py          # Typer command-line interface
mcp_server.py   # FastMCP server (AI-assistant tools)
docs/           # API + MCP documentation
tests/          # pytest suite (network mocked)

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选