Skip to content

Commit

Permalink
add StockPosition.init_quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Mar 8, 2024
1 parent 1e76cf8 commit 20307a8
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 7 deletions.
4 changes: 4 additions & 0 deletions c/csrc/include/longport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2735,6 +2735,10 @@ typedef struct lb_stock_position_t {
* Market
*/
enum lb_market_t market;
/**
* Initial position before market opening
*/
const struct lb_decimal_t *init_quantity;
} lb_stock_position_t;

/**
Expand Down
11 changes: 11 additions & 0 deletions c/src/trade_context/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,8 @@ pub struct CStockPosition {
pub cost_price: *const CDecimal,
/// Market
pub market: CMarket,
/// Initial position before market opening
init_quantity: *const CDecimal,
}

pub(crate) struct CStockPositionOwned {
Expand All @@ -1179,6 +1181,8 @@ pub(crate) struct CStockPositionOwned {
cost_price: CDecimal,
/// Market
market: Market,
/// Initial position before market opening
init_quantity: Option<CDecimal>,
}

impl From<StockPosition> for CStockPositionOwned {
Expand All @@ -1191,6 +1195,7 @@ impl From<StockPosition> for CStockPositionOwned {
currency,
cost_price,
market,
init_quantity,
} = position;
Self {
symbol: symbol.into(),
Expand All @@ -1200,6 +1205,7 @@ impl From<StockPosition> for CStockPositionOwned {
currency: currency.into(),
cost_price: cost_price.into(),
market,
init_quantity: init_quantity.map(Into::into),
}
}
}
Expand All @@ -1216,6 +1222,7 @@ impl ToFFI for CStockPositionOwned {
currency,
cost_price,
market,
init_quantity,
} = self;
CStockPosition {
symbol: symbol.to_ffi_type(),
Expand All @@ -1225,6 +1232,10 @@ impl ToFFI for CStockPositionOwned {
currency: currency.to_ffi_type(),
cost_price: cost_price.to_ffi_type(),
market: (*market).into(),
init_quantity: init_quantity
.as_ref()
.map(ToFFI::to_ffi_type)
.unwrap_or(std::ptr::null()),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/include/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,8 @@ struct StockPosition
Decimal cost_price;
/// Market
Market market;
/// Initial position before market opening
std::optional<Decimal> init_quantity;
};

/// Stock position channel
Expand Down
12 changes: 9 additions & 3 deletions cpp/src/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,10 +1339,16 @@ inline StockPosition
convert(const lb_stock_position_t* position)
{
return StockPosition{
position->symbol, position->symbol_name,
position->quantity, position->available_quantity,
position->currency, Decimal(position->cost_price),
position->symbol,
position->symbol_name,
position->quantity,
position->available_quantity,
position->currency,
Decimal(position->cost_price),
convert(position->market),
position->init_quantity
? std::optional{ Decimal(position->init_quantity) }
: std::nullopt,
};
}

Expand Down
11 changes: 8 additions & 3 deletions java/javasrc/src/main/java/com/longport/trade/StockPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class StockPosition {
private String currency;
private BigDecimal costPrice;
private Market market;
private BigDecimal initQuantity;

public String getSymbol() {
return symbol;
Expand Down Expand Up @@ -41,10 +42,14 @@ public Market getMarket() {
return market;
}

public BigDecimal getInitQuantity() {
return initQuantity;
}

@Override
public String toString() {
return "StockPosition [availableQuantity=" + availableQuantity + ", costPrice=" + costPrice + ", currency="
+ currency + ", market=" + market + ", quantity=" + quantity + ", symbol=" + symbol + ", symbolName="
+ symbolName + "]";
return "StockPosition [symbol=" + symbol + ", symbolName=" + symbolName + ", quantity=" + quantity
+ ", availableQuantity=" + availableQuantity + ", currency=" + currency + ", costPrice=" + costPrice
+ ", market=" + market + ", initQuantity=" + initQuantity + "]";
}
}
3 changes: 2 additions & 1 deletion java/src/types/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ impl_java_class!(
available_quantity,
currency,
cost_price,
market
market,
init_quantity
]
);

Expand Down
2 changes: 2 additions & 0 deletions nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,8 @@ export class StockPosition {
get costPrice(): Decimal
/** Market */
get market(): Market
/** Initial position before market opening */
get initQuantity(): Decimal | null
}
/** Margin ratio */
export class MarginRatio {
Expand Down
3 changes: 3 additions & 0 deletions nodejs/src/trade/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,9 @@ pub struct StockPosition {
cost_price: Decimal,
/// Market
market: Market,
/// Initial position before market opening
#[js(opt)]
init_quantity: Option<Decimal>,
}

/// Margin ratio
Expand Down
5 changes: 5 additions & 0 deletions python/pysrc/longport/openapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4135,6 +4135,11 @@ class StockPosition:
Market
"""

init_quantity: Optional[Decimal]
"""
Initial position before market opening
"""


class StockPositionChannel:
"""
Expand Down
3 changes: 3 additions & 0 deletions python/src/trade/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ pub(crate) struct StockPosition {
cost_price: PyDecimal,
/// Market
market: Market,
/// Initial position before market opening
#[py(opt)]
pub init_quantity: Option<PyDecimal>,
}

/// Margin ratio
Expand Down
3 changes: 3 additions & 0 deletions rust/src/trade/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ pub struct StockPosition {
pub cost_price: Decimal,
/// Market
pub market: Market,
/// Initial position before market opening
#[serde(with = "serde_utils::decimal_opt_empty_is_none")]
pub init_quantity: Option<Decimal>,
}

/// Margin ratio
Expand Down

0 comments on commit 20307a8

Please sign in to comment.