系统接口

1. 健康检查

GET /system/health

检查系统各个服务(行情、交易、策略)的健康状态,包括服务运行状态、连接状态等。

请求头

名称类型必填描述
Content-Typestring是固定值:“application/json”

请求示例

curl --location --request GET 'http://localhost:8080/system/health' \
--header 'Content-Type: application/json'

响应

响应体
名称类型描述
codeint错误码,0 表示成功
msgstring响应消息
dataobject健康状态数据
timestampint64检查时间戳(秒)
servicesobject各服务状态详情
services.quoteobject行情服务状态
services.quote.runningboolean是否运行中
services.quote.connectedboolean是否已连接
services.quote.healthyboolean是否健康(运行且已连接)
services.tradeobject交易服务状态
services.trade.runningboolean是否运行中
services.trade.connectedboolean是否已连接
services.trade.healthyboolean是否健康(运行且已连接)
services.strategyobject策略服务状态
services.strategy.runningboolean是否运行中
services.strategy.initializedboolean是否已初始化
services.strategy.healthyboolean是否健康(运行且已初始化)
overall_statusstring整体状态,值为 “healthy” 或 “unhealthy”
响应体示例(健康状态)
{
  "code": 0,
  "msg": "success",
  "data": {
    "timestamp": 1699261200,
    "services": {
      "quote": {
        "running": true,
        "connected": true,
        "healthy": true
      },
      "trade": {
        "running": true,
        "connected": true,
        "healthy": true
      },
      "strategy": {
        "running": true,
        "initialized": true,
        "healthy": true
      }
    },
    "overall_status": "healthy"
  }
}
响应体示例(非健康状态)
{
  "code": 0,
  "msg": "success",
  "data": {
    "timestamp": 1699261200,
    "services": {
      "quote": {
        "running": true,
        "connected": false,
        "healthy": false
      },
      "trade": {
        "running": false,
        "connected": false,
        "healthy": false
      },
      "strategy": {
        "running": false,
        "initialized": false,
        "healthy": false
      }
    },
    "overall_status": "unhealthy"
  }
}

2. 启动所有服务

POST /system/start

启动系统的所有服务(行情、交易、策略),按照依赖顺序启动:先启动行情服务,然后交易服务,最后启动策略服务。启动过程会等待各服务就绪并注入必要的依赖指针。

请求头

名称类型必填描述
Content-Typestring是固定值:“application/json”

请求示例

curl --location --request POST 'http://localhost:8080/system/start' \
--header 'Content-Type: application/json'

响应

响应体
名称类型描述
codeint错误码,0 表示成功
msgstring响应消息
dataobject启动结果数据
servicesobject各服务启动详情
services.quoteobject行情服务启动结果
services.quote.attemptedboolean是否尝试启动
services.quote.startedboolean是否启动成功
services.quote.runningboolean当前是否运行中
services.quote.connectedboolean是否已连接
services.tradeobject交易服务启动结果
services.trade.attemptedboolean是否尝试启动
services.trade.startedboolean是否启动成功
services.trade.runningboolean当前是否运行中
services.trade.connectedboolean是否已连接
services.strategyobject策略服务启动结果
services.strategy.attemptedboolean是否尝试启动
services.strategy.startedboolean是否启动成功
services.strategy.runningboolean当前是否运行中
overall_resultstring整体结果,值为 “success” 或 “partial_failure”
messagestring结果描述信息
响应体示例(全部启动成功)
{
  "code": 0,
  "msg": "success",
  "data": {
    "services": {
      "quote": {
        "attempted": true,
        "started": true,
        "running": true,
        "connected": true
      },
      "trade": {
        "attempted": true,
        "started": true,
        "running": true,
        "connected": true
      },
      "strategy": {
        "attempted": true,
        "started": true,
        "running": true
      }
    },
    "overall_result": "success",
    "message": "All services started successfully"
  }
}
响应体示例(部分启动失败)
{
  "code": 0,
  "msg": "success",
  "data": {
    "services": {
      "quote": {
        "attempted": true,
        "started": true,
        "running": true,
        "connected": true
      },
      "trade": {
        "attempted": true,
        "started": false,
        "running": false,
        "connected": false
      },
      "strategy": {
        "attempted": true,
        "started": false,
        "running": false
      }
    },
    "overall_result": "partial_failure",
    "message": "Some services failed to start"
  }
}

3. 停止所有服务

POST /system/stop

停止系统的所有服务(行情、交易、策略),按照逆依赖顺序停止:先停止策略服务,然后交易服务,最后停止行情服务。

请求头

名称类型必填描述
Content-Typestring是固定值:“application/json”

请求示例

curl --location --request POST 'http://localhost:8080/system/stop' \
--header 'Content-Type: application/json'

响应

响应体
名称类型描述
codeint错误码,0 表示成功
msgstring响应消息
dataobject停止结果数据
servicesobject各服务停止详情
services.quoteobject行情服务停止结果
services.quote.attemptedboolean是否尝试停止
services.quote.stoppedboolean是否停止成功
services.quote.runningboolean当前是否仍在运行
services.tradeobject交易服务停止结果
services.trade.attemptedboolean是否尝试停止
services.trade.stoppedboolean是否停止成功
services.trade.runningboolean当前是否仍在运行
services.strategyobject策略服务停止结果
services.strategy.attemptedboolean是否尝试停止
services.strategy.stoppedboolean是否停止成功
services.strategy.runningboolean当前是否仍在运行
overall_resultstring整体结果,值为 “success” 或 “partial_failure”
messagestring结果描述信息
响应体示例(全部停止成功)
{
  "code": 0,
  "msg": "success",
  "data": {
    "services": {
      "strategy": {
        "attempted": true,
        "stopped": true,
        "running": false
      },
      "trade": {
        "attempted": true,
        "stopped": true,
        "running": false
      },
      "quote": {
        "attempted": true,
        "stopped": true,
        "running": false
      }
    },
    "overall_result": "success",
    "message": "All services stopped successfully"
  }
}

4. 查询服务状态

GET /system/status

获取系统各个服务的详细状态信息,包括运行状态、连接状态、错误信息、实例数量等。

请求头

名称类型必填描述
Content-Typestring是固定值:“application/json”

请求示例

curl --location --request GET 'http://localhost:8080/system/status' \
--header 'Content-Type: application/json'

响应

响应体
名称类型描述
codeint错误码,0 表示成功
msgstring响应消息
dataobject状态数据
timestampint64查询时间戳(秒)
servicesobject各服务状态详情
services.quoteobject行情服务状态
services.quote.runningboolean是否运行中
services.quote.connectedboolean是否已连接
services.quote.parser_idstring解析器标识符
services.quote.last_errorstring最后错误信息
services.tradeobject交易服务状态
services.trade.runningboolean是否运行中
services.trade.connectedboolean是否已连接
services.trade.interface_idstring接口标识符
services.trade.logged_in_accountsint已登录账户数量
services.trade.total_accountsint总账户数量
services.trade.last_errorstring最后错误信息
services.strategyobject策略服务状态
services.strategy.runningboolean是否运行中
services.strategy.initializedboolean是否已初始化
services.strategy.active_instancesint活跃实例数量
services.strategy.last_errorstring最后错误信息
响应体示例
{
  "code": 0,
  "msg": "success",
  "data": {
    "timestamp": 1699261200,
    "services": {
      "quote": {
        "running": true,
        "connected": true,
        "parser_id": "SH_PARSER_001",
        "last_error": ""
      },
      "trade": {
        "running": true,
        "connected": true,
        "interface_id": "TRADE_IF_001",
        "logged_in_accounts": 2,
        "total_accounts": 3,
        "last_error": ""
      },
      "strategy": {
        "running": true,
        "initialized": true,
        "active_instances": 5,
        "last_error": ""
      }
    }
  }
}

5. 获取日志

GET /system/logs

获取指定日期和日志类型的日志内容。

请求头

名称类型必填描述
Content-Typestring是固定值:“application/json”

查询参数

名称类型必填描述
datestring是日期,格式为 YYYY-MM-DD
示例值:“2024-01-15”
loggerstring是日志名称:quote(行情)、scheduler(调度器)、server(服务器)、strategy(策略)、trade(交易)

请求示例

curl --location --request GET 'http://localhost:8080/system/logs?date=2024-01-15&logger=trade' \
--header 'Content-Type: application/json'

响应

响应体
名称类型描述
codeint错误码,0 表示成功
msgstring响应消息
dataobject日志数据
datestring请求的日期
loggerstring日志名称
logsstring日志内容(如无日志则为空字符串)
响应体示例(有日志)
{
  "code": 0,
  "msg": "success",
  "data": {
    "date": "2024-01-15",
    "logger": "trade",
    "logs": "[2024-01-15 09:30:01] INFO: 交易服务已启动\n[2024-01-15 09:30:05] INFO: 账户登录成功: 123456\n[2024-01-15 09:31:00] INFO: 订单已提交: order_id=20001"
  }
}
响应体示例(无日志)
{
  "code": 0,
  "msg": "success",
  "data": {
    "date": "2024-01-15",
    "logger": "trade",
    "logs": "No logs found for the specified date"
  }
}

6. 查询所有账户信息

GET /system/accounts

获取系统中所有交易账户的基本信息列表,包括账户 ID、资金账号、登录状态等。

请求头

名称类型必填描述
Content-Typestring是固定值:“application/json”

请求示例

curl --location --request GET 'http://localhost:8080/system/accounts' \
--header 'Content-Type: application/json'

响应

响应体
名称类型描述
codeint错误码,0 表示成功
msgstring响应消息
dataobject账户数据
accountsarray账户信息数组
accounts[].login_idstring登录账号
accounts[].cust_idstring客户编号
accounts[].fund_account_idstring资金账号
accounts[].account_id_shstring上海交易所账户
accounts[].account_id_szstring深圳交易所账户
accounts[].is_logged_inboolean是否已登录
total_countint总账户数量
logged_in_countint已登录账户数量
响应体示例
{
  "code": 0,
  "msg": "success",
  "data": {
    "accounts": [
      {
        "login_id": "user001",
        "cust_id": "CUST123456",
        "fund_account_id": "FUND001",
        "account_id_sh": "A123456789",
        "account_id_sz": "0123456789",
        "is_logged_in": true
      },
      {
        "login_id": "user002",
        "cust_id": "CUST789012",
        "fund_account_id": "FUND002",
        "account_id_sh": "A987654321",
        "account_id_sz": "0987654321",
        "is_logged_in": true
      }
    ],
    "total_count": 2,
    "logged_in_count": 2
  }
}

6. 查询账户详情

GET /system/accounts/detail

获取指定交易账户的详细信息,包括账户基本信息和资金信息(沪市和深市)。

请求头

名称类型必填描述
Content-Typestring是固定值:“application/json”

查询参数

名称类型必填描述
login_idstring是登录账号
示例值:“user001”

请求示例

curl --location --request GET 'http://localhost:8080/system/accounts/detail?login_id=user001' \
--header 'Content-Type: application/json'

响应

响应体
名称类型描述
codeint错误码,0 表示成功
msgstring响应消息
dataobject账户详情数据
accountobject账户信息
account.login_idstring登录账号
account.cust_idstring客户编号
account.fund_account_idstring资金账号
account.account_id_shstring上海交易所账户
account.account_id_szstring深圳交易所账户
account.is_logged_inboolean是否已登录
account.fundsarray资金信息数组(沪市和深市)
account.funds[].marketstring市场(“SH” 或 “SZ”)
account.funds[].account_idstring交易账户
account.funds[].total_assetdouble总资产
account.funds[].available_balancedouble可用余额
account.funds[].frozen_balancedouble冻结资金
account.funds[].fetch_balancedouble可取资金
account.funds[].market_valuedouble市值
account.funds[].total_profitdouble总盈亏
account.funds[].unrealized_profitdouble浮动盈亏
account.funds[].buying_powerdouble购买力
account.funds[].withdraw_quotadouble可提取额度
account.funds[].commissiondouble手续费
account.funds[].stamp_taxdouble印花税
account.funds[].transfer_feedouble过户费
响应体示例
{
  "code": 0,
  "msg": "success",
  "data": {
    "account": {
      "login_id": "user001",
      "cust_id": "CUST123456",
      "fund_account_id": "FUND001",
      "account_id_sh": "A123456789",
      "account_id_sz": "0123456789",
      "is_logged_in": true,
      "funds": [
        {
          "market": "SH",
          "account_id": "A123456789",
          "total_asset": 1000000.00,
          "available_balance": 500000.00,
          "frozen_balance": 50000.00,
          "fetch_balance": 450000.00,
          "market_value": 450000.00,
          "total_profit": 50000.00,
          "unrealized_profit": 20000.00,
          "buying_power": 500000.00,
          "withdraw_quota": 450000.00,
          "commission": 100.50,
          "stamp_tax": 50.25,
          "transfer_fee": 10.00
        },
        {
          "market": "SZ",
          "account_id": "0123456789",
          "total_asset": 800000.00,
          "available_balance": 400000.00,
          "frozen_balance": 40000.00,
          "fetch_balance": 360000.00,
          "market_value": 400000.00,
          "total_profit": 40000.00,
          "unrealized_profit": 15000.00,
          "buying_power": 400000.00,
          "withdraw_quota": 360000.00,
          "commission": 80.50,
          "stamp_tax": 40.25,
          "transfer_fee": 8.00
        }
      ]
    }
  }
}