Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- **All SDKs:** attached (take-profit / stop-loss) orders gain bid/ask depth levels (longbridge/developers#1189). `SubmitAttachedParams` and `ReplaceAttachedParams` gain `profit_taker_depth_level` / `stop_loss_depth_level` (int32): the depth level used for the take-profit / stop-loss limit order's submitted price, valid when `activate_order_type` is `LIT`. `AttachedOrderDetail` gains `limit_depth_level`, returned on the `attached_orders` of `today_orders` / `history_orders` / `order_detail` (unset when the server returns `0`, `null`, a non-numeric value, or omits it). Per layer: Rust `profit_taker_depth_level(i32)` / `stop_loss_depth_level(i32)` builders and `Option<i32>`; C `const int32_t *` fields appended at the end of `CSubmitAttachedParams` / `CReplaceAttachedParams` / `CAttachedOrderDetail` (the option structs grow, so rebuild against the new header and zero-initialize them); C++ `std::optional<int32_t>`; Java `setProfitTakerDepthLevel(Integer)` / `setStopLossDepthLevel(Integer)` / `getLimitDepthLevel()`; Node.js `profitTakerDepthLevel?` / `stopLossDepthLevel?` / `limitDepthLevel`; Python keyword arguments and `AttachedOrderDetail.limit_depth_level`

## [5.2.1] - 2026-10-14

### Added
Expand Down
24 changes: 24 additions & 0 deletions c/csrc/include/longbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -4644,6 +4644,16 @@ typedef struct CReplaceAttachedParams {
* Market price (can be null)
*/
const struct lb_decimal_t *market_price;
/**
* Bid/ask depth level for the take-profit limit order submitted price,
* valid when `activate_order_type` is `LIT` (can be null)
*/
const int32_t *profit_taker_depth_level;
/**
* Bid/ask depth level for the stop-loss limit order submitted price,
* valid when `activate_order_type` is `LIT` (can be null)
*/
const int32_t *stop_loss_depth_level;
} CReplaceAttachedParams;

/**
Expand Down Expand Up @@ -4751,6 +4761,16 @@ typedef struct CSubmitAttachedParams {
* RTH setting for activated order (can be null)
*/
const enum lb_outside_rth_t *activate_rth;
/**
* Bid/ask depth level for the take-profit limit order submitted price,
* valid when `activate_order_type` is `LIT` (can be null)
*/
const int32_t *profit_taker_depth_level;
/**
* Bid/ask depth level for the stop-loss limit order submitted price,
* valid when `activate_order_type` is `LIT` (can be null)
*/
const int32_t *stop_loss_depth_level;
} CSubmitAttachedParams;

/**
Expand Down Expand Up @@ -5831,6 +5851,10 @@ typedef struct CAttachedOrderDetail {
* Submit price (maybe null)
*/
const struct lb_decimal_t *submit_price;
/**
* Bid/ask depth level of the limit order submitted price (maybe null)
*/
const int32_t *limit_depth_level;
} CAttachedOrderDetail;

/**
Expand Down
12 changes: 12 additions & 0 deletions c/src/trade_context/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,12 @@ pub unsafe extern "C" fn lb_trade_context_replace_order(
if !ap.market_price.is_null() {
rp = rp.market_price((*ap.market_price).value);
}
if !ap.profit_taker_depth_level.is_null() {
rp = rp.profit_taker_depth_level(*ap.profit_taker_depth_level);
}
if !ap.stop_loss_depth_level.is_null() {
rp = rp.stop_loss_depth_level(*ap.stop_loss_depth_level);
}
opts2 = opts2.attached_params(rp);
}
execute_async(callback, ctx, userdata, async move {
Expand Down Expand Up @@ -623,6 +629,12 @@ pub unsafe extern "C" fn lb_trade_context_submit_order(
if !ap.activate_rth.is_null() {
sp = sp.activate_rth((*ap.activate_rth).into());
}
if !ap.profit_taker_depth_level.is_null() {
sp = sp.profit_taker_depth_level(*ap.profit_taker_depth_level);
}
if !ap.stop_loss_depth_level.is_null() {
sp = sp.stop_loss_depth_level(*ap.stop_loss_depth_level);
}
opts2 = opts2.attached_params(sp);
}
execute_async(callback, ctx, userdata, async move {
Expand Down
22 changes: 22 additions & 0 deletions c/src/trade_context/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub struct CAttachedOrderDetail {
pub activate_rth: *const COutsideRTH,
/// Submit price (maybe null)
pub submit_price: *const CDecimal,
/// Bid/ask depth level of the limit order submitted price (maybe null)
pub limit_depth_level: *const i32,
}

#[derive(Debug)]
Expand All @@ -131,6 +133,7 @@ pub(crate) struct CAttachedOrderDetailOwned {
activate_order_type: OrderType,
activate_rth: Option<COutsideRTH>,
submit_price: Option<CDecimal>,
limit_depth_level: Option<i32>,
}

impl From<AttachedOrderDetail> for CAttachedOrderDetailOwned {
Expand All @@ -157,6 +160,7 @@ impl From<AttachedOrderDetail> for CAttachedOrderDetailOwned {
activate_order_type,
activate_rth,
submit_price,
limit_depth_level,
} = detail;
Self {
order_id: order_id.into(),
Expand All @@ -180,6 +184,7 @@ impl From<AttachedOrderDetail> for CAttachedOrderDetailOwned {
activate_order_type,
activate_rth: activate_rth.map(Into::into),
submit_price: submit_price.map(Into::into),
limit_depth_level,
}
}
}
Expand Down Expand Up @@ -210,6 +215,7 @@ impl ToFFI for CAttachedOrderDetailOwned {
activate_order_type,
activate_rth,
submit_price,
limit_depth_level,
} = self;
CAttachedOrderDetail {
order_id: order_id.to_ffi_type(),
Expand Down Expand Up @@ -254,6 +260,10 @@ impl ToFFI for CAttachedOrderDetailOwned {
.as_ref()
.map(ToFFI::to_ffi_type)
.unwrap_or(std::ptr::null()),
limit_depth_level: limit_depth_level
.as_ref()
.map(|value| value as *const i32)
.unwrap_or(std::ptr::null()),
}
}
}
Expand Down Expand Up @@ -444,6 +454,12 @@ pub struct CSubmitAttachedParams {
pub stop_loss_submit_price: *const CDecimal,
/// RTH setting for activated order (can be null)
pub activate_rth: *const COutsideRTH,
/// Bid/ask depth level for the take-profit limit order submitted price,
/// valid when `activate_order_type` is `LIT` (can be null)
pub profit_taker_depth_level: *const i32,
/// Bid/ask depth level for the stop-loss limit order submitted price,
/// valid when `activate_order_type` is `LIT` (can be null)
pub stop_loss_depth_level: *const i32,
}

/// Options for replace attached order params
Expand Down Expand Up @@ -480,6 +496,12 @@ pub struct CReplaceAttachedParams {
pub quantity: *const CDecimal,
/// Market price (can be null)
pub market_price: *const CDecimal,
/// Bid/ask depth level for the take-profit limit order submitted price,
/// valid when `activate_order_type` is `LIT` (can be null)
pub profit_taker_depth_level: *const i32,
/// Bid/ask depth level for the stop-loss limit order submitted price,
/// valid when `activate_order_type` is `LIT` (can be null)
pub stop_loss_depth_level: *const i32,
}

/// Order changed message
Expand Down
14 changes: 14 additions & 0 deletions cpp/include/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,8 @@ struct AttachedOrderDetail
OrderType activate_order_type;
std::optional<OutsideRTH> activate_rth;
std::optional<Decimal> submit_price;
/// Bid/ask depth level of the limit order submitted price
std::optional<int32_t> limit_depth_level;
};

/// Submit attached order params
Expand All @@ -1669,6 +1671,12 @@ struct SubmitAttachedParams
std::optional<Decimal> profit_taker_submit_price;
std::optional<Decimal> stop_loss_submit_price;
std::optional<OutsideRTH> activate_rth;
/// Bid/ask depth level for the take-profit limit order submitted price,
/// valid when `activate_order_type` is `LIT`
std::optional<int32_t> profit_taker_depth_level;
/// Bid/ask depth level for the stop-loss limit order submitted price, valid
/// when `activate_order_type` is `LIT`
std::optional<int32_t> stop_loss_depth_level;
};

/// Replace attached order params
Expand All @@ -1689,6 +1697,12 @@ struct ReplaceAttachedParams
std::optional<int64_t> main_id;
std::optional<Decimal> quantity;
std::optional<Decimal> market_price;
/// Bid/ask depth level for the take-profit limit order submitted price,
/// valid when `activate_order_type` is `LIT`
std::optional<int32_t> profit_taker_depth_level;
/// Bid/ask depth level for the stop-loss limit order submitted price, valid
/// when `activate_order_type` is `LIT`
std::optional<int32_t> stop_loss_depth_level;
};

/// Multi-leg strategy
Expand Down
10 changes: 10 additions & 0 deletions cpp/src/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,8 @@ convert(const CAttachedOrderDetail* detail)
: std::nullopt,
detail->submit_price ? std::optional{ Decimal(detail->submit_price) }
: std::nullopt,
detail->limit_depth_level ? std::optional{ *detail->limit_depth_level }
: std::nullopt,
};
}

Expand Down Expand Up @@ -1514,6 +1516,10 @@ convert_submit_attached(const SubmitAttachedParams& src)
s.activate_rth = convert(*src.activate_rth);
s.params.activate_rth = &s.activate_rth;
}
s.params.profit_taker_depth_level =
src.profit_taker_depth_level ? &*src.profit_taker_depth_level : nullptr;
s.params.stop_loss_depth_level =
src.stop_loss_depth_level ? &*src.stop_loss_depth_level : nullptr;
return s;
}

Expand Down Expand Up @@ -1568,6 +1574,10 @@ convert_replace_attached(const ReplaceAttachedParams& src)
src.quantity ? (const lb_decimal_t*)src.quantity.value() : nullptr;
s.params.market_price =
src.market_price ? (const lb_decimal_t*)src.market_price.value() : nullptr;
s.params.profit_taker_depth_level =
src.profit_taker_depth_level ? &*src.profit_taker_depth_level : nullptr;
s.params.stop_loss_depth_level =
src.stop_loss_depth_level ? &*src.stop_loss_depth_level : nullptr;
return s;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AttachedOrderDetail {
private OrderType activateOrderType;
private OutsideRTH activateRth;
private BigDecimal submitPrice;
private Integer limitDepthLevel;

/**
* Returns the order ID.
Expand Down Expand Up @@ -219,6 +220,15 @@ public BigDecimal getSubmitPrice() {
return submitPrice;
}

/**
* Returns the bid/ask depth level of the limit order submitted price.
*
* @return depth level, or {@code null} if not set
*/
public Integer getLimitDepthLevel() {
return limitDepthLevel;
}

@Override
public String toString() {
return "AttachedOrderDetail [orderId=" + orderId + ", attachedTypeDisplay=" + attachedTypeDisplay
Expand All @@ -228,6 +238,6 @@ public String toString() {
+ ", executedAmount=" + executedAmount + ", tag=" + tag + ", submittedAt=" + submittedAt
+ ", executedPrice=" + executedPrice + ", forceOnlyRth=" + forceOnlyRth + ", reviewed=" + reviewed
+ ", activateOrderType=" + activateOrderType + ", activateRth=" + activateRth + ", submitPrice="
+ submitPrice + "]";
+ submitPrice + ", limitDepthLevel=" + limitDepthLevel + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ReplaceAttachedParams {
private Long mainId;
private BigDecimal quantity;
private BigDecimal marketPrice;
private Integer profitTakerDepthLevel;
private Integer stopLossDepthLevel;

public ReplaceAttachedParams(AttachedOrderType attachedOrderType) {
this.attachedOrderType = attachedOrderType;
Expand Down Expand Up @@ -81,4 +83,26 @@ public ReplaceAttachedParams(AttachedOrderType attachedOrderType) {
public ReplaceAttachedParams setMarketPrice(BigDecimal v) { this.marketPrice = v; return this; }

public BigDecimal getMarketPrice() { return marketPrice; }

/**
* Sets the bid/ask depth level for the take-profit limit order submitted
* price, valid when {@code activateOrderType} is {@code LIT}.
*
* @param v depth level
* @return this instance for chaining
*/
public ReplaceAttachedParams setProfitTakerDepthLevel(Integer v) { this.profitTakerDepthLevel = v; return this; }

public Integer getProfitTakerDepthLevel() { return profitTakerDepthLevel; }

/**
* Sets the bid/ask depth level for the stop-loss limit order submitted
* price, valid when {@code activateOrderType} is {@code LIT}.
*
* @param v depth level
* @return this instance for chaining
*/
public ReplaceAttachedParams setStopLossDepthLevel(Integer v) { this.stopLossDepthLevel = v; return this; }

public Integer getStopLossDepthLevel() { return stopLossDepthLevel; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class SubmitAttachedParams {
private BigDecimal profitTakerSubmitPrice;
private BigDecimal stopLossSubmitPrice;
private OutsideRTH activateRth;
private Integer profitTakerDepthLevel;
private Integer stopLossDepthLevel;

public SubmitAttachedParams(AttachedOrderType attachedOrderType) {
this.attachedOrderType = attachedOrderType;
Expand Down Expand Up @@ -51,4 +53,26 @@ public SubmitAttachedParams(AttachedOrderType attachedOrderType) {
public SubmitAttachedParams setActivateRth(OutsideRTH v) { this.activateRth = v; return this; }

public OutsideRTH getActivateRth() { return activateRth; }

/**
* Sets the bid/ask depth level for the take-profit limit order submitted
* price, valid when {@code activateOrderType} is {@code LIT}.
*
* @param v depth level
* @return this instance for chaining
*/
public SubmitAttachedParams setProfitTakerDepthLevel(Integer v) { this.profitTakerDepthLevel = v; return this; }

public Integer getProfitTakerDepthLevel() { return profitTakerDepthLevel; }

/**
* Sets the bid/ask depth level for the stop-loss limit order submitted
* price, valid when {@code activateOrderType} is {@code LIT}.
*
* @param v depth level
* @return this instance for chaining
*/
public SubmitAttachedParams setStopLossDepthLevel(Integer v) { this.stopLossDepthLevel = v; return this; }

public Integer getStopLossDepthLevel() { return stopLossDepthLevel; }
}
18 changes: 18 additions & 0 deletions java/src/trade_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,15 @@ fn read_submit_attached_params(
if let Some(v) = activate_rth {
params = params.activate_rth(v);
}
let profit_taker_depth_level: Option<JavaInteger> =
get_field(env, obj, "profitTakerDepthLevel")?;
if let Some(v) = profit_taker_depth_level {
params = params.profit_taker_depth_level(v.into());
}
let stop_loss_depth_level: Option<JavaInteger> = get_field(env, obj, "stopLossDepthLevel")?;
if let Some(v) = stop_loss_depth_level {
params = params.stop_loss_depth_level(v.into());
}
Ok(params)
}

Expand Down Expand Up @@ -492,6 +501,15 @@ fn read_replace_attached_params(
if let Some(v) = market_price {
params = params.market_price(v);
}
let profit_taker_depth_level: Option<JavaInteger> =
get_field(env, obj, "profitTakerDepthLevel")?;
if let Some(v) = profit_taker_depth_level {
params = params.profit_taker_depth_level(v.into());
}
let stop_loss_depth_level: Option<JavaInteger> = get_field(env, obj, "stopLossDepthLevel")?;
if let Some(v) = stop_loss_depth_level {
params = params.stop_loss_depth_level(v.into());
}
Ok(params)
}

Expand Down
3 changes: 2 additions & 1 deletion java/src/types/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ impl_java_class!(
reviewed,
activate_order_type,
activate_rth,
submit_price
submit_price,
limit_depth_level
]
);

Expand Down
Loading
Loading