交易接口
1. 股票买入
POST /trade/buy
根据指定的总金额买入股票,系统会自动根据当前市场价格计算可买入的股数(自动按手数整理)。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| security_code | string | 是 | 证券代码,6 位数字格式 示例值:“000001” |
| amount | double | 是 | 买入金额(单位:万元) 示例值:1.5 表示 1.5 万元 |
| price | double | 否 | 限价价格,如果传入则以此价格为准,否则以行情实时价格为准 示例值:12.50 |
| chasing_rise_halfway | boolean | 否 | 是否是半路追涨模式,默认为false |
请求示例
curl --location --request POST 'http://localhost:8080/trade/buy' \
--header 'Content-Type: application/json' \
--data-raw '{
"login_id": "123456",
"security_code": "000001",
"amount": 1.5
}'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 订单响应数据 |
| request_id | int64 | 请求ID |
| order_id | int64 | 订单ID |
| exchange_order_id | string | 交易所订单ID |
| batch_id | int64 | 批次ID |
| login_id | string | 登录账号ID |
| security_code | string | 证券代码 |
| market | int | 市场类型 |
| side | int | 买卖方向 |
| order_type | int | 订单类型 |
| price | double | 委托价格 |
| quantity | int64 | 委托数量 |
| amount | double | 订单金额 |
| status | int | 订单状态 |
| status_msg | string | 状态消息 |
| order_time | int64 | 委托时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"request_id": 1001,
"order_id": 20001,
"exchange_order_id": "E123456789",
"batch_id": 0,
"login_id": "123456",
"security_code": "000001",
"market": 1,
"side": 0,
"order_type": 0,
"price": 12.34,
"quantity": 1200,
"amount": 14808.0,
"status": 0,
"status_msg": "order submitted",
"order_time": 1699261200000000,
"timestamp": 1699261200123000
}
}
2. 股票卖出
POST /trade/sell
按指定股数卖出股票,以当前市场价格进行卖出操作。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| security_code | string | 是 | 证券代码,6 位数字格式 示例值:“000001” |
| quantity | int64 | 是 | 卖出股数 示例值:1000 |
| price | double | 否 | 限价价格,如果传入则以此价格为准,否则以行情实时价格为准 示例值:12.30 |
请求示例
curl --location --request POST 'http://localhost:8080/trade/sell' \
--header 'Content-Type: application/json' \
--data-raw '{
"login_id": "123456",
"security_code": "000001",
"quantity": 1000
}'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 订单响应数据 |
| request_id | int64 | 请求ID |
| order_id | int64 | 订单ID |
| exchange_order_id | string | 交易所订单ID |
| batch_id | int64 | 批次ID |
| login_id | string | 登录账号ID |
| security_code | string | 证券代码 |
| market | int | 市场类型 |
| side | int | 买卖方向 |
| order_type | int | 订单类型 |
| price | double | 委托价格 |
| quantity | int64 | 委托数量 |
| amount | double | 订单金额 |
| status | int | 订单状态 |
| status_msg | string | 状态消息 |
| order_time | int64 | 委托时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"request_id": 1002,
"order_id": 20002,
"exchange_order_id": "E123456790",
"batch_id": 0,
"login_id": "123456",
"security_code": "000001",
"market": 1,
"side": 1,
"order_type": 0,
"price": 12.30,
"quantity": 1000,
"amount": 12300.0,
"status": 0,
"status_msg": "order submitted",
"order_time": 1699261300000000,
"timestamp": 1699261300123456
}
}
3. 撤单
POST /trade/cancel
撤销指定的委托订单。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| market | int | 是 | 市场类型 示例值:1 表示深圳,2 表示上海 |
| order_id | int64 | 是 | 订单ID |
| batch_id | int64 | 否 | 批次ID(可选,默认为0) |
请求示例
curl --location --request POST 'http://localhost:8080/trade/cancel' \
--header 'Content-Type: application/json' \
--data-raw '{
"login_id": "123456",
"market": 1,
"order_id": 20001,
"batch_id": 0
}'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 撤单响应数据 |
| request_id | int64 | 请求ID |
| order_id | int64 | 订单ID |
| batch_id | int64 | 批次ID |
| market | int | 市场类型 |
| status | int | 撤单状态 |
| status_msg | string | 状态消息 |
| cancel_time | int64 | 撤单时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"request_id": 1003,
"order_id": 20001,
"batch_id": 0,
"market": 1,
"status": 0,
"status_msg": "cancel submitted",
"cancel_time": 1699261400000000,
"timestamp": 1699261400123000
}
}
4. 银证转账
POST /trade/bank-transfer
进行银行与证券账户之间的资金转账操作。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| direction | int | 是 | 转账方向 0:银行转证券(转入) 1:证券转银行(转出) |
| market | int | 是 | 市场类型 |
| transfer_amount | double | 是 | 转账金额(单位:元) |
| currency | string | 否 | 币种(默认:CNY) |
| bank_password | string | 是 | 银行密码 |
| fund_password | string | 是 | 资金密码 |
| remark | string | 否 | 备注信息 |
请求示例
curl --location --request POST 'http://localhost:8080/trade/bank-transfer' \
--header 'Content-Type: application/json' \
--data-raw '{
"login_id": "123456",
"direction": 0,
"market": 1,
"transfer_amount": 10000.0,
"currency": "CNY",
"bank_password": "******",
"fund_password": "******",
"remark": "transfer in"
}'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 转账响应数据 |
| request_id | int64 | 请求ID |
| transfer_id | string | 转账流水号 |
| direction | int | 转账方向 |
| transfer_amount | double | 转账金额 |
| currency | string | 币种 |
| status | int | 转账状态 |
| status_msg | string | 状态消息 |
| transfer_time | int64 | 转账时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"request_id": 1004,
"transfer_id": "T202401150001",
"direction": 0,
"transfer_amount": 10000.0,
"currency": "CNY",
"status": 0,
"status_msg": "transfer success",
"transfer_time": 1699261500000000,
"timestamp": 1699261500123000
}
}
5. 市场间资金转账
POST /trade/fund-transfer
在不同市场(深圳、上海)之间进行资金划转。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| from_market | int | 是 | 转出市场类型 |
| to_market | int | 是 | 转入市场类型 |
| transfer_amount | double | 是 | 转账金额(单位:元) |
| currency | string | 否 | 币种(默认:CNY) |
请求示例
curl --location --request POST 'http://localhost:8080/trade/fund-transfer' \
--header 'Content-Type: application/json' \
--data-raw '{
"login_id": "123456",
"from_market": 1,
"to_market": 2,
"transfer_amount": 5000.0,
"currency": "CNY"
}'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 转账响应数据 |
| request_id | int64 | 请求ID |
| from_market | int | 转出市场 |
| to_market | int | 转入市场 |
| transfer_amount | double | 转账金额 |
| currency | string | 币种 |
| status | int | 转账状态 |
| status_msg | string | 状态消息 |
| transfer_time | int64 | 转账时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"request_id": 1005,
"from_market": 1,
"to_market": 2,
"transfer_amount": 5000.0,
"currency": "CNY",
"status": 0,
"status_msg": "transfer success",
"transfer_time": 1699261600000000,
"timestamp": 1699261600123000
}
}
6. TWAP拆单卖出
POST /trade/twap-sell
使用 TWAP(时间加权平均价格)算法进行智能拆单卖出,将大单拆分成多个小单在指定时间段内均匀执行。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| security_code | string | 是 | 证券代码,6 位数字格式 |
| quantity | int64 | 是 | 总卖出股数 |
| start_time | string | 否 | 开始时间(ISO8601 格式,如:2024-01-15T09:30:00) 不填则立即开始 |
| end_time | string | 否 | 结束时间(ISO8601 格式,如:2024-01-15T09:40:00) 不填则默认开始时间后 10 分钟 |
| interval_seconds | int | 否 | 拆单间隔时间(秒),默认 10 秒 范围:1-3600 |
| enable_price_threshold | bool | 否 | 是否启用价格阈值保护,默认 false |
| price_threshold_ratio | double | 否 | 价格阈值比例(0.0-1.0),默认 0.05(5%) 当价格偏离超过此比例时暂停交易 |
请求示例
curl --location --request POST 'http://localhost:8080/trade/twap-sell' \
--header 'Content-Type: application/json' \
--data-raw '{
"login_id": "123456",
"security_code": "000001",
"quantity": 10000,
"start_time": "2024-01-15T09:30:00",
"end_time": "2024-01-15T09:40:00",
"interval_seconds": 10,
"enable_price_threshold": true,
"price_threshold_ratio": 0.05
}'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | TWAP 任务响应数据 |
| task_id | int64 | 任务ID(数字格式) |
| task_id_formatted | string | 任务ID(格式化字符串) |
| login_id | string | 登录账号ID |
| security_code | string | 证券代码 |
| market | int | 市场类型 |
| total_quantity | int64 | 总卖出股数 |
| interval_seconds | int | 拆单间隔时间(秒) |
| enable_price_threshold | bool | 是否启用价格阈值保护 |
| price_threshold_ratio | double | 价格阈值比例 |
| task_details | object | 任务详细信息(包括状态、进度等) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"task_id": 1699261700001,
"task_id_formatted": "TWAP-20240115-001",
"login_id": "123456",
"security_code": "000001",
"market": 1,
"total_quantity": 10000,
"interval_seconds": 10,
"enable_price_threshold": true,
"price_threshold_ratio": 0.05,
"task_details": {
"status": "running",
"progress": 0.0,
"executed_quantity": 0,
"remaining_quantity": 10000,
"avg_price": 0.0,
"create_time": 1699261700000,
"start_time": 1699262600000,
"end_time": 1699263200000
}
}
}
7. 查询TWAP任务状态
GET /trade/twap/task
查询指定 TWAP 任务的执行状态和进度信息。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
查询参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| task_id | int64 | 是 | TWAP 任务ID |
请求示例
curl --location --request GET 'http://localhost:8080/trade/twap/task?task_id=1699261700001' \
--header 'Content-Type: application/json'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 任务状态数据 |
| task_id | int64 | 任务ID |
| status | string | 任务状态(pending/running/completed/cancelled/failed) |
| progress | double | 执行进度(0.0-1.0) |
| executed_quantity | int64 | 已执行股数 |
| remaining_quantity | int64 | 剩余股数 |
| total_quantity | int64 | 总股数 |
| avg_price | double | 平均成交价格 |
| executed_orders | int | 已执行订单数 |
| total_orders | int | 总订单数 |
| create_time | int64 | 创建时间(毫秒) |
| start_time | int64 | 开始时间(毫秒) |
| end_time | int64 | 结束时间(毫秒) |
| update_time | int64 | 更新时间(毫秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"task_id": 1699261700001,
"status": "running",
"progress": 0.35,
"executed_quantity": 3500,
"remaining_quantity": 6500,
"total_quantity": 10000,
"avg_price": 12.28,
"executed_orders": 35,
"total_orders": 100,
"create_time": 1699261700000,
"start_time": 1699262600000,
"end_time": 1699263200000,
"update_time": 1699262810000
}
}
8. 取消TWAP任务
POST /trade/twap/cancel
取消指定的 TWAP 任务,停止后续订单的执行。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
查询参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| task_id | int64 | 是 | TWAP 任务ID |
请求示例
curl --location --request POST 'http://localhost:8080/trade/twap/cancel?task_id=1699261700001' \
--header 'Content-Type: application/json'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 取消响应数据 |
| task_id | int64 | 任务ID |
| task_id_formatted | string | 任务ID(格式化字符串) |
| status | string | 任务状态 |
| message | string | 操作消息 |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"task_id": 1699261700001,
"task_id_formatted": "TWAP-20240115-001",
"status": "cancelled",
"message": "TWAP task cancelled successfully"
}
}
9. 查询委托
GET /trade/query/orders
查询指定账户的委托订单信息。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
查询参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| market | int | 是 | 市场类型 |
| security_code | string | 否 | 证券代码(可选,不填则查询所有) |
| order_id | int64 | 否 | 订单ID(可选,查询指定订单) |
| condition | int | 否 | 查询条件(默认查询所有) |
| sort | int | 否 | 排序方式(默认排序) |
| limit | int64 | 否 | 返回记录数限制(默认 100) |
请求示例
curl --location --request GET 'http://localhost:8080/trade/query/orders?login_id=123456&market=1&security_code=000001&limit=50' \
--header 'Content-Type: application/json'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 查询结果数据 |
| login_id | string | 登录账号ID |
| total_count | int | 总记录数 |
| security_code | string | 证券代码(如果指定) |
| order_id | int64 | 订单ID(如果指定) |
| orders | array | 委托订单数组 |
orders 数组元素:
| 名称 | 类型 | 描述 |
|---|---|---|
| cust_id | string | 客户ID |
| fund_account_id | string | 资金账号ID |
| branch_id | string | 营业部ID |
| security_code | string | 证券代码 |
| security_name | string | 证券名称 |
| market | int | 市场类型 |
| request_id | int64 | 请求ID |
| order_id | int64 | 订单ID |
| exchange_order_id | string | 交易所订单ID |
| batch_id | int64 | 批次ID |
| side | int | 买卖方向 |
| sign | int | 开平标志 |
| order_type | int | 订单类型 |
| status | int | 订单状态 |
| status_msg | string | 状态消息 |
| price | double | 委托价格 |
| qty | int64 | 委托数量 |
| leaves_qty | int64 | 剩余数量 |
| cum_qty | int64 | 累计成交数量 |
| avg_price | double | 成交均价 |
| cum_amt | double | 累计成交金额 |
| order_time | int64 | 委托时间(微秒) |
| update_time | int64 | 更新时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
| business_type | string | 业务类型 |
| opu_id | string | OPU ID |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"login_id": "123456",
"total_count": 2,
"security_code": "000001",
"orders": [
{
"cust_id": "C123456",
"fund_account_id": "F123456",
"branch_id": "B001",
"security_code": "000001",
"security_name": "平安银行",
"market": 1,
"request_id": 1001,
"order_id": 20001,
"exchange_order_id": "E123456789",
"batch_id": 0,
"side": 0,
"sign": 0,
"order_type": 0,
"status": 2,
"status_msg": "filled",
"price": 12.34,
"qty": 1200,
"leaves_qty": 0,
"cum_qty": 1200,
"avg_price": 12.33,
"cum_amt": 14796.0,
"order_time": 1699261200000000,
"update_time": 1699261205000000,
"timestamp": 1699261205123000,
"business_type": "normal",
"opu_id": "OPU001"
},
{
"cust_id": "C123456",
"fund_account_id": "F123456",
"branch_id": "B001",
"security_code": "000001",
"security_name": "平安银行",
"market": 1,
"request_id": 1002,
"order_id": 20002,
"exchange_order_id": "E123456790",
"batch_id": 0,
"side": 1,
"sign": 0,
"order_type": 0,
"status": 1,
"status_msg": "partially filled",
"price": 12.30,
"qty": 1000,
"leaves_qty": 300,
"cum_qty": 700,
"avg_price": 12.29,
"cum_amt": 8603.0,
"order_time": 1699261300000000,
"update_time": 1699261310000000,
"timestamp": 1699261310123000,
"business_type": "normal",
"opu_id": "OPU001"
}
]
}
}
10. 查询成交
GET /trade/query/trades
查询指定账户的成交记录信息。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
查询参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| market | int | 是 | 市场类型 |
| security_code | string | 否 | 证券代码(可选,不填则查询所有) |
| order_id | int64 | 否 | 订单ID(可选,查询指定订单的成交) |
| condition | int | 否 | 查询条件(默认使用全局参数) |
| sort | int | 否 | 排序方式(默认排序) |
| limit | int64 | 否 | 返回记录数限制(默认 100) |
请求示例
curl --location --request GET 'http://localhost:8080/trade/query/trades?login_id=123456&market=1&security_code=000001&limit=50' \
--header 'Content-Type: application/json'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 查询结果数据 |
| login_id | string | 登录账号ID |
| total_count | int | 总记录数 |
| security_code | string | 证券代码(如果指定) |
| order_id | int64 | 订单ID(如果指定) |
| trades | array | 成交记录数组 |
trades 数组元素:
| 名称 | 类型 | 描述 |
|---|---|---|
| cust_id | string | 客户ID |
| fund_account_id | string | 资金账号ID |
| branch_id | string | 营业部ID |
| security_code | string | 证券代码 |
| security_name | string | 证券名称 |
| market | int | 市场类型 |
| request_id | int64 | 请求ID |
| trade_id | string | 成交编号 |
| order_id | int64 | 订单ID |
| exchange_order_id | string | 交易所订单ID |
| batch_id | int64 | 批次ID |
| side | int | 买卖方向 |
| order_type | int | 订单类型 |
| business_type | string | 业务类型 |
| price | double | 成交价格 |
| qty | int64 | 成交数量 |
| value | double | 成交金额 |
| fee | double | 交易费用 |
| currency | string | 币种 |
| trade_time | int64 | 成交时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"login_id": "123456",
"total_count": 3,
"security_code": "000001",
"trades": [
{
"cust_id": "C123456",
"fund_account_id": "F123456",
"branch_id": "B001",
"security_code": "000001",
"security_name": "平安银行",
"market": 1,
"request_id": 1001,
"trade_id": "T20240115001",
"order_id": 20001,
"exchange_order_id": "E123456789",
"batch_id": 0,
"side": 0,
"order_type": 0,
"business_type": "normal",
"price": 12.33,
"qty": 800,
"value": 9864.0,
"fee": 5.92,
"currency": "CNY",
"trade_time": 1699261202000000,
"timestamp": 1699261202123000
},
{
"cust_id": "C123456",
"fund_account_id": "F123456",
"branch_id": "B001",
"security_code": "000001",
"security_name": "平安银行",
"market": 1,
"request_id": 1001,
"trade_id": "T20240115002",
"order_id": 20001,
"exchange_order_id": "E123456789",
"batch_id": 0,
"side": 0,
"order_type": 0,
"business_type": "normal",
"price": 12.34,
"qty": 400,
"value": 4936.0,
"fee": 2.96,
"currency": "CNY",
"trade_time": 1699261204000000,
"timestamp": 1699261204123000
},
{
"cust_id": "C123456",
"fund_account_id": "F123456",
"branch_id": "B001",
"security_code": "000001",
"security_name": "平安银行",
"market": 1,
"request_id": 1002,
"trade_id": "T20240115003",
"order_id": 20002,
"exchange_order_id": "E123456790",
"batch_id": 0,
"side": 1,
"order_type": 0,
"business_type": "normal",
"price": 12.29,
"qty": 700,
"value": 8603.0,
"fee": 5.16,
"currency": "CNY",
"trade_time": 1699261310000000,
"timestamp": 16992613101230000
}
]
}
}
11. 查询持仓
GET /trade/query/positions
查询指定账户的持仓信息。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
查询参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| market | int | 是 | 市场类型 |
| security_code | string | 否 | 证券代码(可选,不填则查询所有) |
| limit | int64 | 否 | 返回记录数限制(默认 100) |
请求示例
curl --location --request GET 'http://localhost:8080/trade/query/positions?login_id=123456&market=1&limit=50' \
--header 'Content-Type: application/json'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 查询结果数据 |
| login_id | string | 登录账号ID |
| total_count | int | 总记录数 |
| security_code | string | 证券代码(如果指定) |
| positions | array | 持仓记录数组 |
positions 数组元素:
| 名称 | 类型 | 描述 |
|---|---|---|
| cust_id | string | 客户ID |
| fund_account_id | string | 资金账号ID |
| branch_id | string | 营业部ID |
| security_code | string | 证券代码 |
| security_name | string | 证券名称 |
| market | int | 市场类型 |
| security_type | string | 证券类型 |
| request_id | int64 | 请求ID |
| total_qty | int64 | 总持仓数量 |
| available_qty | int64 | 可用数量 |
| frozen_qty | int64 | 冻结数量 |
| today_buy_qty | int64 | 今日买入数量 |
| today_sell_qty | int64 | 今日卖出数量 |
| cost_price | double | 成本价 |
| market_price | double | 市场价 |
| market_value | double | 市值 |
| profit_loss | double | 盈亏金额 |
| profit_loss_ratio | double | 盈亏比例 |
| update_time | int64 | 更新时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"login_id": "123456",
"total_count": 2,
"positions": [
{
"cust_id": "C123456",
"fund_account_id": "F123456",
"branch_id": "B001",
"security_code": "000001",
"security_name": "平安银行",
"market": 1,
"security_type": "stock",
"request_id": 1001,
"total_qty": 5000,
"available_qty": 5000,
"frozen_qty": 0,
"today_buy_qty": 1200,
"today_sell_qty": 0,
"cost_price": 12.15,
"market_price": 12.34,
"market_value": 61700.0,
"profit_loss": 950.0,
"profit_loss_ratio": 0.0156,
"update_time": 1699261400000000,
"timestamp": 1699261400123000
},
{
"cust_id": "C123456",
"fund_account_id": "F123456",
"branch_id": "B001",
"security_code": "600000",
"security_name": "浦发银行",
"market": 2,
"security_type": "stock",
"request_id": 1002,
"total_qty": 3000,
"available_qty": 2700,
"frozen_qty": 300,
"today_buy_qty": 0,
"today_sell_qty": 300,
"cost_price": 8.56,
"market_price": 8.72,
"market_value": 26160.0,
"profit_loss": 480.0,
"profit_loss_ratio": 0.0187,
"update_time": 1699261400000000,
"timestamp": 1699261400123000
}
]
}
}
12. 查询资金
GET /trade/query/funds
查询指定账户的资金信息。
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | string | 是 | 固定值:“application/json” |
查询参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_id | string | 是 | 登录账号ID |
| market | int | 是 | 市场类型 |
| currency | string | 否 | 币种(默认:CNY) |
请求示例
curl --location --request GET 'http://localhost:8080/trade/query/funds?login_id=123456&market=1¤cy=CNY' \
--header 'Content-Type: application/json'
响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
| code | int | 错误码,0 表示成功 |
| msg | string | 响应消息 |
| data | object | 查询结果数据 |
| login_id | string | 登录账号ID |
| total_count | int | 总记录数 |
| funds | array | 资金记录数组 |
funds 数组元素:
| 名称 | 类型 | 描述 |
|---|---|---|
| cust_id | string | 客户ID |
| fund_account_id | string | 资金账号ID |
| branch_id | string | 营业部ID |
| current_account_id | string | 当前账号ID |
| current_market | int | 当前市场 |
| request_id | int64 | 请求ID |
| currency | string | 币种 |
| total_asset | double | 总资产 |
| cash_balance | double | 现金余额 |
| available_cash | double | 可用资金 |
| frozen_cash | double | 冻结资金 |
| market_value | double | 持仓市值 |
| buying_power | double | 购买力 |
| withdrawal_cash | double | 可取资金 |
| profit_loss | double | 盈亏金额 |
| profit_loss_ratio | double | 盈亏比例 |
| update_time | int64 | 更新时间(微秒) |
| timestamp | int64 | 时间戳(微秒) |
响应体示例
{
"code": 0,
"msg": "success",
"data": {
"login_id": "123456",
"total_count": 1,
"funds": [
{
"cust_id": "C123456",
"fund_account_id": "F123456",
"branch_id": "B001",
"current_account_id": "A123456",
"current_market": 1,
"request_id": 1001,
"currency": "CNY",
"total_asset": 150000.0,
"cash_balance": 62140.0,
"available_cash": 60000.0,
"frozen_cash": 2140.0,
"market_value": 87860.0,
"buying_power": 60000.0,
"withdrawal_cash": 58000.0,
"profit_loss": 1430.0,
"profit_loss_ratio": 0.0096,
"update_time": 1699261400000000,
"timestamp": 1699261400123000
}
]
}
}
本页内容
- 1. 股票买入
- 请求头
- 请求体
- 请求示例
- 响应
- 响应体
- 响应体示例
- 2. 股票卖出
- 请求头
- 请求体
- 请求示例
- 响应
- 响应体
- 响应体示例
- 3. 撤单
- 请求头
- 请求体
- 请求示例
- 响应
- 响应体
- 响应体示例
- 4. 银证转账
- 请求头
- 请求体
- 请求示例
- 响应
- 响应体
- 响应体示例
- 5. 市场间资金转账
- 请求头
- 请求体
- 请求示例
- 响应
- 响应体
- 响应体示例
- 6. TWAP拆单卖出
- 请求头
- 请求体
- 请求示例
- 响应
- 响应体
- 响应体示例
- 7. 查询TWAP任务状态
- 请求头
- 查询参数
- 请求示例
- 响应
- 响应体
- 响应体示例
- 8. 取消TWAP任务
- 请求头
- 查询参数
- 请求示例
- 响应
- 响应体
- 响应体示例
- 9. 查询委托
- 请求头
- 查询参数
- 请求示例
- 响应
- 响应体
- 响应体示例
- 10. 查询成交
- 请求头
- 查询参数
- 请求示例
- 响应
- 响应体
- 响应体示例
- 11. 查询持仓
- 请求头
- 查询参数
- 请求示例
- 响应
- 响应体
- 响应体示例
- 12. 查询资金
- 请求头
- 查询参数
- 请求示例
- 响应
- 响应体
- 响应体示例