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: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ build
# Eclipse IDE
.project
.classpath
.settings/
.settings/


.DS_Store
*/.DS_Store
7 changes: 7 additions & 0 deletions c/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ cpp_compat = true
"CGranularity" = "lb_granularity_t"
"CMarketTemperature" = "lb_market_temperature_t"
"CHistoryMarketTemperatureResponse" = "lb_history_market_temperature_response_t"
"CFilingItem" = "lb_filing_item_t"
"CTopicItem" = "lb_topic_item_t"
"CNewsItem" = "lb_news_item_t"
"CContentContext" = "lb_content_context_t"
"COAuth" = "lb_oauth_t"

[export]
Expand Down Expand Up @@ -169,5 +173,8 @@ include = [
"CQuotePackageDetail",
"CMarketTemperature",
"CHistoryMarketTemperatureResponse",
"CFilingItem",
"CTopicItem",
"CNewsItem",
"COAuth",
]
186 changes: 178 additions & 8 deletions c/csrc/include/longbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,11 @@ typedef enum lb_granularity_t {
*/
typedef struct lb_config_t lb_config_t;

/**
* Content context
*/
typedef struct lb_content_context_t lb_content_context_t;

typedef struct lb_decimal_t lb_decimal_t;

typedef struct lb_error_t lb_error_t;
Expand Down Expand Up @@ -1312,14 +1317,6 @@ typedef struct lb_quote_context_t lb_quote_context_t;
*/
typedef struct lb_trade_context_t lb_trade_context_t;

/**
* HTTP Header
*/
typedef struct lb_http_header_t {
const char *name;
const char *value;
} lb_http_header_t;

typedef struct lb_async_result_t {
const void *ctx;
const struct lb_error_t *error;
Expand All @@ -1330,6 +1327,14 @@ typedef struct lb_async_result_t {

typedef void (*lb_async_callback_t)(const struct lb_async_result_t*);

/**
* HTTP Header
*/
typedef struct lb_http_header_t {
const char *name;
const char *value;
} lb_http_header_t;

typedef void (*lb_free_userdata_func_t)(void*);

/**
Expand Down Expand Up @@ -3870,6 +3875,116 @@ typedef struct lb_history_market_temperature_response_t {
uintptr_t num_records;
} lb_history_market_temperature_response_t;

/**
* Filing item
*/
typedef struct lb_filing_item_t {
/**
* Filing ID
*/
const char *id;
/**
* Title
*/
const char *title;
/**
* Description
*/
const char *description;
/**
* File name
*/
const char *file_name;
/**
* File URLs
*/
const char *const *file_urls;
/**
* Number of file URLs
*/
uintptr_t num_file_urls;
/**
* Published time (Unix timestamp)
*/
int64_t published_at;
} lb_filing_item_t;

/**
* Topic item
*/
typedef struct lb_topic_item_t {
/**
* Topic ID
*/
const char *id;
/**
* Title
*/
const char *title;
/**
* Description
*/
const char *description;
/**
* URL
*/
const char *url;
/**
* Published time (Unix timestamp)
*/
int64_t published_at;
/**
* Comments count
*/
int32_t comments_count;
/**
* Likes count
*/
int32_t likes_count;
/**
* Shares count
*/
int32_t shares_count;
} lb_topic_item_t;

/**
* News item
*/
typedef struct lb_news_item_t {
/**
* News ID
*/
const char *id;
/**
* Title
*/
const char *title;
/**
* Description
*/
const char *description;
/**
* URL
*/
const char *url;
/**
* Published time (Unix timestamp)
*/
int64_t published_at;
/**
* Comments count
*/
int32_t comments_count;
/**
* Likes count
*/
int32_t likes_count;
/**
* Shares count
*/
int32_t shares_count;
} lb_news_item_t;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
Expand Down Expand Up @@ -3990,6 +4105,53 @@ void lb_config_set_log_path(struct lb_config_t *config, const char *log_path);
*/
void lb_config_free(struct lb_config_t *config);

/**
* Create a new `ContentContext`
*
* @param config Config object
* @param callback Async callback
* @param userdata User data passed to the callback
*/
void lb_content_context_new(const struct lb_config_t *config,
lb_async_callback_t callback,
void *userdata);

/**
* Retain the content context (increment reference count)
*/
void lb_content_context_retain(const struct lb_content_context_t *ctx);

/**
* Release the content context (decrement reference count)
*/
void lb_content_context_release(const struct lb_content_context_t *ctx);

/**
* Get discussion topics list for a symbol
*
* @param ctx Content context
* @param symbol Security symbol (e.g. "700.HK")
* @param callback Async callback
* @param userdata User data passed to the callback
*/
void lb_content_context_topics(const struct lb_content_context_t *ctx,
const char *symbol,
lb_async_callback_t callback,
void *userdata);

/**
* Get news list for a symbol
*
* @param ctx Content context
* @param symbol Security symbol (e.g. "700.HK")
* @param callback Async callback
* @param userdata User data passed to the callback
*/
void lb_content_context_news(const struct lb_content_context_t *ctx,
const char *symbol,
lb_async_callback_t callback,
void *userdata);

/**
* Free the error object
*/
Expand Down Expand Up @@ -4507,6 +4669,14 @@ void lb_quote_context_realtime_candlesticks(const struct lb_quote_context_t *ctx
lb_async_callback_t callback,
void *userdata);

/**
* Get filings
*/
void lb_quote_context_filings(const struct lb_quote_context_t *ctx,
const char *symbol,
lb_async_callback_t callback,
void *userdata);

/**
* Get security list
*/
Expand Down
102 changes: 102 additions & 0 deletions c/src/content_context/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use std::{ffi::c_void, os::raw::c_char, sync::Arc};

use longbridge::content::ContentContext;

use crate::{
async_call::{CAsyncCallback, CAsyncResult, execute_async},
config::CConfig,
content_context::types::{CNewsItemOwned, CTopicItemOwned},
types::{CVec, cstr_to_rust},
};

/// Content context
pub struct CContentContext {
ctx: ContentContext,
}

/// Create a new `ContentContext`
///
/// @param config Config object
/// @param callback Async callback
/// @param userdata User data passed to the callback
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lb_content_context_new(
config: *const CConfig,
callback: CAsyncCallback,
userdata: *mut c_void,
) {
let config = Arc::new((*config).0.clone());
let userdata_pointer = userdata as usize;

execute_async(
callback,
std::ptr::null_mut::<c_void>(),
userdata,
async move {
let ctx = ContentContext::try_new(config)?;
let arc_ctx = Arc::new(CContentContext { ctx });
let ctx = Arc::into_raw(arc_ctx);
Ok(CAsyncResult {
ctx: ctx as *const c_void,
error: std::ptr::null(),
data: std::ptr::null_mut(),
length: 0,
userdata: userdata_pointer as *mut c_void,
})
},
);
}

/// Retain the content context (increment reference count)
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lb_content_context_retain(ctx: *const CContentContext) {
Arc::increment_strong_count(ctx);
}

/// Release the content context (decrement reference count)
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lb_content_context_release(ctx: *const CContentContext) {
let _ = Arc::from_raw(ctx);
}

/// Get discussion topics list for a symbol
///
/// @param ctx Content context
/// @param symbol Security symbol (e.g. "700.HK")
/// @param callback Async callback
/// @param userdata User data passed to the callback
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lb_content_context_topics(
ctx: *const CContentContext,
symbol: *const c_char,
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<CTopicItemOwned> = ctx_inner.topics(symbol).await?.into();
Ok(rows)
});
}

/// Get news list for a symbol
///
/// @param ctx Content context
/// @param symbol Security symbol (e.g. "700.HK")
/// @param callback Async callback
/// @param userdata User data passed to the callback
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lb_content_context_news(
ctx: *const CContentContext,
symbol: *const c_char,
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<CNewsItemOwned> = ctx_inner.news(symbol).await?.into();
Ok(rows)
});
}
2 changes: 2 additions & 0 deletions c/src/content_context/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod context;
mod types;
Loading
Loading