Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Jul 26, 2024
2 parents 7b009df + 3b4cd4b commit 005d13a
Show file tree
Hide file tree
Showing 64 changed files with 912 additions and 153 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ jobs:
manylinux: 2_28
args: -i python${{ matrix.python-version }} --release --out dist -m python/Cargo.toml
- uses: uraimo/run-on-arch-action@v2.2.0
if: matrix.target != 'ppc64'
name: Install built wheel
with:
arch: ${{ matrix.target }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/issue-notify.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Issue Notify
on:
issues:
types: [opened, edited]
types: [opened]

jobs:
notify:
Expand All @@ -13,6 +13,6 @@ jobs:
msg_type: text
content: |
text: |
GitHub: ${{ github.event.issue.title }} #${{ github.event.issue.number }}
${{ github.event.issue.title }} #${{ github.event.issue.number }}
${{ github.event.issue.html_url }}
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ jobs:
manylinux: 2_28
args: -i python${{ matrix.python-version }} --release --out dist -m python/Cargo.toml
- uses: uraimo/run-on-arch-action@v2.2.0
if: matrix.target != 'ppc64'
name: Install built wheel
with:
arch: ${{ matrix.target }}
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include(FetchContent)
fetchcontent_declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.2.1
GIT_TAG v0.5.0
)
fetchcontent_makeavailable(Corrosion)

Expand All @@ -31,6 +31,7 @@ add_subdirectory(examples/c/http_client)

add_subdirectory(examples/cpp/submit_order)
add_subdirectory(examples/cpp/subscribe_quote)
add_subdirectory(examples/cpp/subscribe_candlesticks)
add_subdirectory(examples/cpp/get_quote)
add_subdirectory(examples/cpp/today_orders)
add_subdirectory(examples/cpp/http_client)
2 changes: 1 addition & 1 deletion c/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "longport-c"
version = "1.0.27"
version = "1.0.29"
description = "LongPort OpenAPI SDK for C"
homepage = "https://open.longportapp.com/en/"
readme = "README.md"
Expand Down
8 changes: 4 additions & 4 deletions c/Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[tasks.c]
command = "make"
args = ["cargo-build_longport-c"]
args = ["cargo-build_longport_c"]
cwd = "cmake.build"

[tasks.c-release]
command = "make"
args = ["cargo-build_longport-c"]
args = ["cargo-build_longport_c"]
cwd = "cmake.build"

[tasks.c.windows]
command = "msbuild"
args = ["longport.sln", "-p:Configuration=Debug", "/t:cargo-build_longport-c"]
args = ["longport.sln", "-p:Configuration=Debug", "/t:cargo-build_longport_c"]
cwd = "cmake.build"

[tasks.c-release.windows]
command = "msbuild"
args = ["longport.sln", "-p:Configuration=Release", "/t:cargo-build_longport-c"]
args = ["longport.sln", "-p:Configuration=Release", "/t:cargo-build_longport_c"]
cwd = "cmake.build"

[tasks.c-test]
Expand Down
1 change: 1 addition & 0 deletions c/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cpp_compat = true
"CHeader" = "lb_http_header_t"
"CHttpResult" = "lb_http_result_t"
"CLanguage" = "lb_language_t"
"CPushCandlestickMode" = "lb_push_candlestick_mode_t"
"CMarket" = "lb_market_t"
"CDecimal" = "lb_decimal_t"
"CAsyncCallback" = "lb_async_callback_t"
Expand Down
2 changes: 1 addition & 1 deletion c/crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "longport-c-macros"
version = "1.0.27"
version = "1.0.29"
edition = "2021"

[lib]
Expand Down
19 changes: 18 additions & 1 deletion c/csrc/include/longport.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,20 @@ typedef enum lb_period_t {
PeriodYear,
} lb_period_t;

/**
* Language identifer
*/
typedef enum lb_push_candlestick_mode_t {
/**
* Real-time
*/
PushCandlestickMode_Realtime,
/**
* Confirmed
*/
PushCandlestickMode_Confirmed,
} lb_push_candlestick_mode_t;

/**
* Trade session
*/
Expand Down Expand Up @@ -3606,6 +3620,8 @@ extern "C" {
* `wss://openapi-trade.longportapp.com/v2`)
* - `LONGPORT_ENABLE_OVERNIGHT` - Enable overnight quote, `true` or `false`
* (Default: `false`)
* - `LONGPORT_PUSH_CANDLESTICK_MODE` - `realtime` or `confirmed` (Default:
* `realtime`)
*/
struct lb_config_t *lb_config_from_env(struct lb_error_t **error);

Expand All @@ -3616,7 +3632,8 @@ struct lb_config_t *lb_config_new(const char *app_key,
const char *quote_ws_url,
const char *trade_ws_url,
const enum lb_language_t *language,
bool enable_overight);
bool enable_overight,
const enum lb_push_candlestick_mode_t *push_candlestick_mode);

/**
* Free the config object
Expand Down
12 changes: 11 additions & 1 deletion c/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use time::OffsetDateTime;
use crate::{
async_call::{execute_async, CAsyncCallback},
error::{set_error, CError},
types::{CLanguage, CString},
types::{CLanguage, CPushCandlestickMode, CString},
};

/// Configuration options for LongPort sdk
Expand All @@ -33,6 +33,8 @@ pub struct CConfig(pub(crate) Arc<Config>);
/// `wss://openapi-trade.longportapp.com/v2`)
/// - `LONGPORT_ENABLE_OVERNIGHT` - Enable overnight quote, `true` or `false`
/// (Default: `false`)
/// - `LONGPORT_PUSH_CANDLESTICK_MODE` - `realtime` or `confirmed` (Default:
/// `realtime`)
#[no_mangle]
pub unsafe extern "C" fn lb_config_from_env(error: *mut *mut CError) -> *mut CConfig {
match Config::from_env() {
Expand All @@ -57,6 +59,7 @@ pub unsafe extern "C" fn lb_config_new(
trade_ws_url: *const c_char,
language: *const CLanguage,
enable_overight: bool,
push_candlestick_mode: *const CPushCandlestickMode,
) -> *mut CConfig {
let app_key = CStr::from_ptr(app_key).to_str().expect("invalid app key");
let app_secret = CStr::from_ptr(app_secret)
Expand All @@ -70,20 +73,23 @@ pub unsafe extern "C" fn lb_config_new(
if !http_url.is_null() {
config = config.http_url(CStr::from_ptr(http_url).to_str().expect("invalid http url"));
}

if !quote_ws_url.is_null() {
config = config.quote_ws_url(
CStr::from_ptr(quote_ws_url)
.to_str()
.expect("invalid quote websocket url"),
);
}

if !trade_ws_url.is_null() {
config = config.trade_ws_url(
CStr::from_ptr(trade_ws_url)
.to_str()
.expect("invalid trade websocket url"),
);
}

if !language.is_null() {
config = config.language((*language).into());
}
Expand All @@ -92,6 +98,10 @@ pub unsafe extern "C" fn lb_config_new(
config = config.enable_overnight();
}

if !push_candlestick_mode.is_null() {
config = config.push_candlestick_mode((*push_candlestick_mode).into());
}

Box::into_raw(Box::new(CConfig(Arc::new(config))))
}

Expand Down
2 changes: 2 additions & 0 deletions c/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod decimal;
mod language;
mod market;
mod option;
mod push_candlestick_mode;
mod string;

use std::{ffi::CStr, os::raw::c_char};
Expand All @@ -16,6 +17,7 @@ pub(crate) use decimal::CDecimal;
pub(crate) use language::CLanguage;
pub(crate) use market::CMarket;
pub(crate) use option::COption;
pub(crate) use push_candlestick_mode::CPushCandlestickMode;
pub(crate) use string::CString;

pub(crate) trait ToFFI {
Expand Down
15 changes: 15 additions & 0 deletions c/src/types/push_candlestick_mode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use longport_c_macros::CEnum;

/// Language identifer
#[derive(Debug, Copy, Clone, Eq, PartialEq, CEnum)]
#[c(remote = "longport::PushCandlestickMode")]
#[allow(clippy::enum_variant_names, non_camel_case_types)]
#[repr(C)]
pub enum CPushCandlestickMode {
/// Real-time
#[c(remote = "Realtime")]
PushCandlestickMode_Realtime,
/// Confirmed
#[c(remote = "Confirmed")]
PushCandlestickMode_Confirmed,
}
4 changes: 1 addition & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ add_library(
longport_cpp SHARED
${SOURCES}
)
if(NOT CMAKE_HOST_LINUX)
target_link_libraries(longport_cpp longport-c)
endif()
target_link_libraries(longport_cpp longport_c)

add_subdirectory(test)
28 changes: 27 additions & 1 deletion cpp/include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Config
* @param trade_ws_url Trade websocket endpoint url (Default:
* wss://openapi-trade.longportapp.com/v2)
* @param language Language identifer (Default: Language::EN)
* @param push_candlestick_mode Push candlestick mode (Default:
* PushCandlestickMode::Realtime)
*/
Config(const std::string& app_key,
const std::string& app_secret,
Expand All @@ -43,7 +45,29 @@ class Config
const std::optional<std::string>& quote_ws_url,
const std::optional<std::string>& trade_ws_url,
const std::optional<Language>& language,
bool enable_overnight);
bool enable_overnight,
const std::optional<PushCandlestickMode>& push_candlestick_mode);

/** Config
*
* @param app_key App key
* @param app_secret App secret
* @param access_token Access token
*/
Config(const std::string& app_key,
const std::string& app_secret,
const std::string& access_token)
: Config(app_key,
app_secret,
access_token,
std::nullopt,
std::nullopt,
std::nullopt,
std::nullopt,
false,
std::nullopt)
{
}

~Config();

Expand All @@ -67,6 +91,8 @@ class Config
/// `wss://openapi-trade.longportapp.com/v2`)
/// - `LONGPORT_ENABLE_OVERNIGHT` - Enable overnight quote, `true` or
/// `false` (Default: `false`)
/// - `LONGPORT_PUSH_CANDLESTICK_MODE` - `realtime` or `confirmed` (Default:
/// `realtime`)
static Status from_env(Config& config);

/// Gets a new `access_token`
Expand Down
2 changes: 2 additions & 0 deletions cpp/include/http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace longport {
struct HttpResult
{
const char* response_body;

HttpResult(const char* response_body) {}
};

class HttpClient
Expand Down
6 changes: 4 additions & 2 deletions cpp/include/status.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <stdint.h>

typedef struct lb_error_t lb_error_t;

namespace longport {
Expand All @@ -13,7 +15,7 @@ class Status
Status();
Status(const lb_error_t* err);
Status(lb_error_t* err);
Status(Status&& status);
Status(Status&& status) noexcept;
~Status();

inline operator bool() { return is_ok(); }
Expand All @@ -25,7 +27,7 @@ class Status
bool is_err() const;

/// Returns the error code
int code() const;
int64_t code() const;

/// Returns the error message
const char* message() const;
Expand Down
9 changes: 9 additions & 0 deletions cpp/include/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ enum class Language
EN,
};

/// Push candlestick mode
enum class PushCandlestickMode
{
/// Real-time
Realtime,
/// Confirmed
Confirmed,
};

/// Market
enum class Market
{
Expand Down
26 changes: 17 additions & 9 deletions cpp/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,29 @@ Config::Config(const std::string& app_key,
const std::optional<std::string>& quote_ws_url,
const std::optional<std::string>& trade_ws_url,
const std::optional<Language>& language,
bool enable_overnight)
bool enable_overnight,
const std::optional<PushCandlestickMode>& push_candlestick_mode)
{
lb_language_t c_language;
if (language) {
c_language = convert::convert(*language);
}

config_ = lb_config_new(app_key.c_str(),
app_secret.c_str(),
access_token.c_str(),
http_url ? http_url->c_str() : nullptr,
quote_ws_url ? quote_ws_url->c_str() : nullptr,
trade_ws_url ? trade_ws_url->c_str() : nullptr,
language ? &c_language : nullptr,
enable_overnight);
lb_push_candlestick_mode_t c_push_candlestick_mode;
if (push_candlestick_mode) {
c_push_candlestick_mode = convert::convert(*push_candlestick_mode);
}

config_ =
lb_config_new(app_key.c_str(),
app_secret.c_str(),
access_token.c_str(),
http_url ? http_url->c_str() : nullptr,
quote_ws_url ? quote_ws_url->c_str() : nullptr,
trade_ws_url ? trade_ws_url->c_str() : nullptr,
language ? &c_language : nullptr,
enable_overnight,
push_candlestick_mode ? &c_push_candlestick_mode : nullptr);
}

Config::~Config()
Expand Down
Loading

0 comments on commit 005d13a

Please sign in to comment.