下单
下单
签名
pub async fn place_order(&self, order: OrderRequest) -> Result<Option<PlaceOrderResult>, TigerError>说明
提交真实订单。需要交易权限和足够购买力。建议先使用 preview_order 验证。
参数
OrderRequest 字段(均为 Option,SDK 在发送时跳过 None 字段):
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| account | Option<String> | 否 | 账户,缺省时 SDK 自动注入 |
| symbol | Option<String> | 是 | 股票代码,如 AAPL |
| sec_type | Option<String> | 是 | 证券类型:STK/OPT/FUT/WAR/IOPT |
| action | Option<String> | 是 | 交易方向:BUY/SELL |
| order_type | Option<String> | 是 | 订单类型:MKT/LMT/STP/STP_LMT/TRAIL |
| total_quantity | Option<i64> | 是 | 下单数量 |
| limit_price | Option<f64> | 条件 | 限价(LMT/STP_LMT 必填) |
| aux_price | Option<f64> | 条件 | 止损触发价(STP/STP_LMT 必填);TRAIL 为跟踪额 |
| trailing_percent | Option<f64> | 否 | 跟踪止损百分比,与 aux_price 互斥 |
| time_in_force | Option<String> | 否 | 有效期:DAY/GTC/GTD,默认 DAY |
| outside_rth | Option<bool> | 否 | 是否允许盘前盘后交易 |
| expire_time | Option<i64> | 条件 | GTD 必填,13 位毫秒时间戳 |
| market | Option<String> | 否 | 市场:US/HK/CN |
| currency | Option<String> | 否 | 币种:USD/HKD/CNH |
| expiry | Option<String> | 否 | 期权到期日 YYYYMMDD |
| strike | Option<String> | 否 | 期权行权价 |
| right | Option<String> | 否 | 期权方向:PUT/CALL |
| adjust_limit | Option<f64> | 否 | 价格微调幅度 |
| secret_key | Option<String> | 否 | 机构交易员密钥 |
| user_mark | Option<String> | 否 | 用户备注 |
| order_legs | Option<Vec<OrderLegRequest>> | 否 | 附加订单(止盈止损) |
| algo_params | Option<AlgoParamsRequest> | 否 | 算法订单参数 |
| contract_legs | Option<Vec<ContractLegRequest>> | 否 | 组合订单腿 |
返回
Result<Option<PlaceOrderResult>, TigerError>
| 字段 | 类型 | 说明 |
|---|---|---|
| id | i64 | 全局订单 ID |
| order_id | i64 | 订单编号 |
| sub_ids | Vec<i64> | 子订单 ID 列表 |
示例
use tigeropen::config::ClientConfig;
use tigeropen::model::order::limit_order;
use tigeropen::trade::TradeClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::builder().build()?;
let account = config.account.clone();
let trade = TradeClient::from_config(config);
// 限价买入 100 股 AAPL
let order = limit_order(&account, "AAPL", "STK", "BUY", 100, 195.50);
let result = trade.place_order(order).await?;
if let Some(r) = result {
println!("下单成功, id={}, order_id={}", r.id, r.order_id);
}
Ok(())
}返回示例
{
"id": 31234567,
"order_id": 100234,
"sub_ids": []
}预览订单
签名
pub async fn preview_order(&self, order: OrderRequest) -> Result<Option<PreviewResult>, TigerError>说明
预览订单不实际提交,用于检查费用、保证金和可行性。
参数
同 下单。
返回
Result<Option<PreviewResult>, TigerError>
| 字段 | 类型 | 说明 |
|---|---|---|
| is_pass | bool | 是否通过 |
| commission | f64 | 预估佣金 |
| commission_currency | String | 佣金币种 |
| init_margin | f64 | 初始保证金 |
| maint_margin | f64 | 维持保证金 |
| equity_with_loan | f64 | 含贷权益 |
| available_ee | f64 | 可用资金 |
| message | String | 提示信息 |
示例
let order = limit_order(&account, "AAPL", "STK", "BUY", 100, 195.50);
let preview = trade.preview_order(order).await?;
if let Some(p) = preview {
println!("通过={} 佣金={} 保证金={}", p.is_pass, p.commission, p.init_margin);
}返回示例
{
"is_pass": true,
"commission": 1.99,
"commission_currency": "USD",
"init_margin": 9775.0,
"maint_margin": 9775.0,
"equity_with_loan": 50000.0,
"available_ee": 40225.0,
"message": ""
}Updated 8 days ago
Did this page help you?
