@startuml inline_umlgraph_1.png
skinparam style strictuml
skinparam sequenceMessageAlign center
hide footbox

participant "用户线程" as User
participant "XLTTradeApi" as API
participant "Xlight柜台" as Server
participant "XLTTradeSpi" as Spi

User -> API : get_init_assets()
API --> User : 日初资金
User -> API : get_init_positions()
API --> User : 日初持仓

User -> API : subscribe_trade_message(\n  REPORT, QUICK)
API -> Server : 订阅请求
Server --> Spi : on_subscribe_trade_message()

== 委托 ==

User -> API : insert_order()
API --> User : xid
API -> Server : 委托请求

Server --> Spi : on_order_response()\n申报成功
note right : 更新本地订单状态

Server --> Spi : on_trade_report()\n成交回报
note right : 更新成交/资金/持仓

Server --> Spi : on_order_end()\n订单结束

== 撤单 ==

User -> API : cancel_order(xid)
API --> User : cancel_xid
API -> Server : 撤单请求

Server --> Spi : on_cancel_response()\n撤单成功
note right : 更新订单状态

Server --> Spi : on_order_end()\n订单结束

== 委托失败 ==

Server --> Spi : on_order_error_response()\n拒单/废单/撤单失败
note right : 处理错误
@enduml
@startuml inline_umlgraph_2.png
skinparam style strictuml
skinparam sequenceMessageAlign center
hide footbox

participant "用户线程" as User
participant "XLTTradeApi" as API
participant "Xlight柜台" as Server
participant "XLTTradeSpi" as Spi

User -> API : get_init_assets()
API --> User : 日初资金
User -> API : get_init_positions()
API --> User : 日初持仓

User -> API : subscribe_trade_message(\n  ORDER_BOOK, QUICK)
API -> Server : 订阅请求
Server --> Spi : on_subscribe_trade_message()

== 委托 ==

User -> API : insert_order()
API --> User : xid
API -> Server : 委托请求

Server --> Spi : on_order_book_insert()\n新订单明细
note right : 记录订单

Server --> Spi : on_asset()\n资金变动
note right : 直接更新资金\n订单导致的资金变动会在订单变动通知之前推送\n以便用户及时更新可用资金

Server --> Spi : on_position()\n持仓变动
note right : 直接更新持仓\n订单导致的持仓变动会在订单变动通知之前推送\n以便用户及时更新可用持仓

Server --> Spi : on_order_book_update()\n订单变动（申报成功/成交等）
note right : 直接用推送数据\n更新订单状态

== 委托失败 ==
Server --> Spi : on_order_book_insert()\n新订单明细
note right : 记录订单

Server --> Spi : on_order_book_error()\n订单错误
note right : 处理错误
@enduml
