diff --git a/c/cbindgen.toml b/c/cbindgen.toml index 17a3b07b2..3307e8d6d 100644 --- a/c/cbindgen.toml +++ b/c/cbindgen.toml @@ -44,6 +44,7 @@ cpp_compat = true "COptionQuote" = "lb_option_quote_t" "CDate" = "lb_date_t" "CTime" = "lb_time_t" +"CDateTime" = "lb_datetime_t" "CWarrantQuote" = "lb_warrant_quote_t" "CSecurityDepth" = "lb_security_depth_t" "CSecurityBrokers" = "lb_security_brokers_t" diff --git a/c/csrc/include/longbridge.h b/c/csrc/include/longbridge.h index f6635eb78..a4e640db3 100644 --- a/c/csrc/include/longbridge.h +++ b/c/csrc/include/longbridge.h @@ -1153,6 +1153,17 @@ typedef struct lb_date_t { uint8_t day; } lb_date_t; +typedef struct lb_time_t { + uint8_t hour; + uint8_t minute; + uint8_t second; +} lb_time_t; + +typedef struct lb_datetime_t { + struct lb_date_t date; + struct lb_time_t time; +} lb_datetime_t; + /** * An request to create a watchlist group */ @@ -2055,12 +2066,6 @@ typedef struct lb_issuer_info_t { const char *name_hk; } lb_issuer_info_t; -typedef struct lb_time_t { - uint8_t hour; - uint8_t minute; - uint8_t second; -} lb_time_t; - /** * The information of trading session */ @@ -3214,6 +3219,31 @@ void lb_quote_context_candlesticks(const struct lb_quote_context_t *ctx, lb_async_callback_t callback, void *userdata); +/** + * Get security history candlesticks by offset + */ +void lb_quote_context_history_candlesticks_by_offset(const struct lb_quote_context_t *ctx, + const char *symbol, + enum lb_period_t period, + enum lb_adjust_type_t adjust_type, + bool forward, + struct lb_datetime_t time, + uintptr_t count, + lb_async_callback_t callback, + void *userdata); + +/** + * Get security history candlesticks by date + */ +void lb_quote_context_history_candlesticks_by_date(const struct lb_quote_context_t *ctx, + const char *symbol, + enum lb_period_t period, + enum lb_adjust_type_t adjust_type, + const struct lb_date_t *start, + const struct lb_date_t *end, + lb_async_callback_t callback, + void *userdata); + /** * Get option chain expiry date list */ diff --git a/c/src/quote_context/context.rs b/c/src/quote_context/context.rs index 0d0e20ca0..74aa1559f 100644 --- a/c/src/quote_context/context.rs +++ b/c/src/quote_context/context.rs @@ -27,7 +27,7 @@ use crate::{ LB_WATCHLIST_GROUP_NAME, LB_WATCHLIST_GROUP_SECURITIES, }, }, - types::{cstr_array_to_rust, cstr_to_rust, CCow, CDate, CMarket, CVec, ToFFI}, + types::{cstr_array_to_rust, cstr_to_rust, CCow, CDate, CDateTime, CMarket, CVec, ToFFI}, }; pub type COnQuoteCallback = extern "C" fn(*const CQuoteContext, *const CPushQuote, *mut c_void); @@ -584,6 +584,70 @@ pub unsafe extern "C" fn lb_quote_context_candlesticks( }); } +/// Get security history candlesticks by offset +#[no_mangle] +pub unsafe extern "C" fn lb_quote_context_history_candlesticks_by_offset( + ctx: *const CQuoteContext, + symbol: *const c_char, + period: CPeriod, + adjust_type: CAdjustType, + forward: bool, + time: CDateTime, + count: usize, + callback: CAsyncCallback, + userdata: *mut c_void, +) { + let ctx_inner = (*ctx).ctx.clone(); + let symbol = cstr_to_rust(symbol); + execute_async(callback, ctx, userdata, async move { + let rows: CVec = ctx_inner + .history_candlesticks_by_offset( + symbol, + period.into(), + adjust_type.into(), + forward, + time.into(), + count, + ) + .await? + .into(); + Ok(rows) + }); +} + +/// Get security history candlesticks by date +#[no_mangle] +pub unsafe extern "C" fn lb_quote_context_history_candlesticks_by_date( + ctx: *const CQuoteContext, + symbol: *const c_char, + period: CPeriod, + adjust_type: CAdjustType, + start: *const CDate, + end: *const CDate, + callback: CAsyncCallback, + userdata: *mut c_void, +) { + let ctx_inner = (*ctx).ctx.clone(); + let symbol = cstr_to_rust(symbol); + let start = if start.is_null() { + None + } else { + Some((*start).into()) + }; + let end = if end.is_null() { + None + } else { + Some((*end).into()) + }; + execute_async(callback, ctx, userdata, async move { + let rows: CVec = ctx_inner + .history_candlesticks_by_date(symbol, period.into(), adjust_type.into(), start, end) + .await? + .into(); + Ok(rows) + }); +} + /// Get option chain expiry date list #[no_mangle] pub unsafe extern "C" fn lb_quote_context_option_chain_expiry_date_list( diff --git a/c/src/types/datetime.rs b/c/src/types/datetime.rs index cfbf5edd5..adc2c08a8 100644 --- a/c/src/types/datetime.rs +++ b/c/src/types/datetime.rs @@ -1,4 +1,4 @@ -use time::{Date, Month, Time}; +use time::{Date, Month, PrimitiveDateTime, Time}; use crate::types::ToFFI; @@ -58,6 +58,12 @@ impl From