Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ https://longbridge.github.io/openapi
- Debugging
- Enable logs via `LONGBRIDGE_LOG_PATH`.
- If quotes connect but look empty, keep `LONGBRIDGE_PRINT_QUOTE_PACKAGES=true` to confirm opened quote packages.
- Paper trading
- If your account is a paper trading (simulation) account and you want to place orders, set `LONGBRIDGE_PAPERTRADING=true`. When enabled, all API calls target the paper trading environment and the server validates the token — if the token belongs to a real-money account the server returns an error. When `false` (the default) the server imposes no restrictions.

## Minimal Verification

Expand Down
29 changes: 29 additions & 0 deletions c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,35 @@ setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center"
| LONGBRIDGE_PUSH_CANDLESTICK_MODE | `realtime` or `confirmed` (Default: `realtime`) |
| LONGBRIDGE_PRINT_QUOTE_PACKAGES | Print quote packages when connected, `true` or `false` (Default: `true`) |
| LONGBRIDGE_LOG_PATH | Set the path of the log files (Default: `no logs`) |
| LONGBRIDGE_PAPERTRADING | Enable paper trading mode, `true` or `false` (Default: `false`). See [Paper Trading](#paper-trading). |

## Paper Trading

If your account is a **paper trading** (simulation) account and you want to
place orders, you must explicitly enable paper trading mode. When enabled, all
API calls target the paper trading environment and the server validates the
token — if the token belongs to a real-money account the server returns an
error.

By default this option is **off**: the server imposes no restrictions and
accepts requests from both paper trading and real-money accounts.

**Via environment variable** (applies automatically to all constructor methods):

```bash
export LONGBRIDGE_PAPERTRADING=true # macOS / Linux
```

```powershell
$env:LONGBRIDGE_PAPERTRADING = "true" # Windows PowerShell
```

**Programmatically:**

```c
lb_config_t* config = lb_config_from_apikey("app-key", "app-secret", "access-token");
lb_config_enable_papertrading(config);
```

## Quote API _(Get basic information of securities)_

Expand Down
16 changes: 16 additions & 0 deletions c/csrc/include/longbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -9028,6 +9028,22 @@ void lb_config_set_push_candlestick_mode(struct lb_config_t *config,
*/
void lb_config_disable_print_quote_packages(struct lb_config_t *config);

/**
* Enable paper trading mode.
*
* When enabled, all API calls target the paper trading (simulation)
* environment. The server validates the token: if it belongs to a real-money
* account the server returns an error.
*
* When disabled (the default) the server imposes no restrictions — both
* paper trading and real-money accounts are accepted.
*
* Paper trading users should call this function as a safety guard.
*
* @param config Config object
*/
void lb_config_enable_papertrading(struct lb_config_t *config);

/**
* Set the log file path
*
Expand Down
17 changes: 17 additions & 0 deletions c/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ pub unsafe extern "C" fn lb_config_disable_print_quote_packages(config: *mut CCo
(*config).0.set_dont_print_quote_packages();
}

/// Enable paper trading mode.
///
/// When enabled, all API calls target the paper trading (simulation)
/// environment. The server validates the token: if it belongs to a real-money
/// account the server returns an error.
///
/// When disabled (the default) the server imposes no restrictions — both
/// paper trading and real-money accounts are accepted.
///
/// Paper trading users should call this function as a safety guard.
///
/// @param config Config object
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lb_config_enable_papertrading(config: *mut CConfig) {
(*config).0.set_enable_papertrading();
}

/// Set the log file path
///
/// @param config Config object
Expand Down
29 changes: 29 additions & 0 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,35 @@ setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center"
| LONGBRIDGE_PUSH_CANDLESTICK_MODE | `realtime` or `confirmed` (Default: `realtime`) |
| LONGBRIDGE_PRINT_QUOTE_PACKAGES | Print quote packages when connected, `true` or `false` (Default: `true`) |
| LONGBRIDGE_LOG_PATH | Set the path of the log files (Default: `no logs`) |
| LONGBRIDGE_PAPERTRADING | Enable paper trading mode, `true` or `false` (Default: `false`). See [Paper Trading](#paper-trading). |

## Paper Trading

If your account is a **paper trading** (simulation) account and you want to
place orders, you must explicitly enable paper trading mode. When enabled, all
API calls target the paper trading environment and the server validates the
token — if the token belongs to a real-money account the server returns an
error.

By default this option is **off**: the server imposes no restrictions and
accepts requests from both paper trading and real-money accounts.

**Via environment variable** (applies automatically to all constructor methods):

```bash
export LONGBRIDGE_PAPERTRADING=true # macOS / Linux
```

```powershell
$env:LONGBRIDGE_PAPERTRADING = "true" # Windows PowerShell
```

**Programmatically:**

```c++
Config config = Config::from_apikey("app-key", "app-secret", "access-token")
.enable_papertrading();
```

## Quote API _(Get basic information of securities)_

Expand Down
12 changes: 12 additions & 0 deletions cpp/include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ class Config
/// Enable overnight quote
Config& enable_overnight();

/// Enable paper trading mode.
///
/// When enabled, all API calls target the paper trading (simulation)
/// environment. The server validates the token: if it belongs to a
/// real-money account the server returns an error.
///
/// By default this option is disabled and the server imposes no restrictions
/// — both paper trading and real-money accounts are accepted.
///
/// Paper trading users should call this method as a safety guard.
Config& enable_papertrading();

/// Set the push candlestick mode
Config& set_push_candlestick_mode(PushCandlestickMode mode);

Expand Down
7 changes: 7 additions & 0 deletions cpp/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ Config::enable_overnight()
return *this;
}

Config&
Config::enable_papertrading()
{
lb_config_enable_papertrading(config_);
return *this;
}

Config&
Config::set_push_candlestick_mode(PushCandlestickMode mode)
{
Expand Down
31 changes: 31 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,37 @@ setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center"
| LONGBRIDGE_PUSH_CANDLESTICK_MODE | `realtime` or `confirmed` (Default: `realtime`) |
| LONGBRIDGE_PRINT_QUOTE_PACKAGES | Print quote packages when connected, `true` or `false` (Default: `true`) |
| LONGBRIDGE_LOG_PATH | Set the path of the log files (Default: `no logs`) |
| LONGBRIDGE_PAPERTRADING | Enable paper trading mode, `true` or `false` (Default: `false`). See [Paper Trading](#paper-trading). |

## Paper Trading

If your account is a **paper trading** (simulation) account and you want to
place orders, you must explicitly enable paper trading mode. When enabled, all
API calls target the paper trading environment and the server validates the
token — if the token belongs to a real-money account the server returns an
error.

By default this option is **off**: the server imposes no restrictions and
accepts requests from both paper trading and real-money accounts.

**Via environment variable** (applies automatically to all constructor methods):

```bash
export LONGBRIDGE_PAPERTRADING=true # macOS / Linux
```

```powershell
$env:LONGBRIDGE_PAPERTRADING = "true" # Windows PowerShell
```

**Programmatically:**

```java
import com.longbridge.*;

Config config = Config.fromApikey("app-key", "app-secret", "access-token")
.enablePapertrading();
```

## Quote API _(Get basic information of securities)_

Expand Down
19 changes: 19 additions & 0 deletions java/javasrc/src/main/java/com/longbridge/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ public Config logPath(String path) {
return this;
}

/**
* Enable paper trading mode.
*
* <p>When enabled, all API calls target the paper trading (simulation)
* environment. The server validates the token: if it belongs to a real-money
* account the server returns an error.
*
* <p>By default this option is disabled and the server imposes no restrictions
* — requests from both paper trading and real-money accounts are accepted.
*
* <p>Paper trading users should call this method as a safety guard.
*
* @return this object
*/
public Config enablePapertrading() {
this.raw = SdkNative.configSetEnablePapertrading(this.raw);
return this;
}

/**
* Gets a new {@code access_token}.
*
Expand Down
2 changes: 2 additions & 0 deletions java/javasrc/src/main/java/com/longbridge/SdkNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public static native long newHttpClientFromApikey(String appKey, String appSecre

public static native long configSetLogPath(long config, String logPath);

public static native long configSetEnablePapertrading(long config);

public static native void configRefreshAccessToken(long config, OffsetDateTime expiredAt,
AsyncCallback callback);

Expand Down
12 changes: 12 additions & 0 deletions java/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ pub unsafe extern "system" fn Java_com_longbridge_SdkNative_configSetLogPath(
})
}

#[unsafe(no_mangle)]
pub unsafe extern "system" fn Java_com_longbridge_SdkNative_configSetEnablePapertrading(
mut env: JNIEnv,
_class: JClass,
config: jlong,
) -> jlong {
jni_result(&mut env, config, |_env| {
(*(config as *mut Config)).set_enable_papertrading();
Ok(config)
})
}

// ── Async operations
// ──────────────────────────────────────────────────────────

Expand Down
35 changes: 35 additions & 0 deletions nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center"
| LONGBRIDGE_PUSH_CANDLESTICK_MODE | `realtime` or `confirmed` (Default: `realtime`) |
| LONGBRIDGE_PRINT_QUOTE_PACKAGES | Print quote packages when connected, `true` or `false` (Default: `true`) |
| LONGBRIDGE_LOG_PATH | Set the path of the log files (Default: `no logs`) |
| LONGBRIDGE_PAPERTRADING | Enable paper trading mode, `true` or `false` (Default: `false`). See [Paper Trading](#paper-trading). |

Then create a config from the environment:

Expand Down Expand Up @@ -230,6 +231,40 @@ async function main() {
main();
```

## Paper Trading

If your account is a **paper trading** (simulation) account and you want to
place orders, you must explicitly enable paper trading mode. When enabled, all
API calls target the paper trading environment and the server validates the
token — if the token belongs to a real-money account the server returns an
error.

By default this option is **off**: the server imposes no restrictions and
accepts requests from both paper trading and real-money accounts.

**Via environment variable** (applies automatically to all constructor methods):

```bash
export LONGBRIDGE_PAPERTRADING=true # macOS / Linux
```

```powershell
$env:LONGBRIDGE_PAPERTRADING = "true" # Windows PowerShell
```

**Programmatically:**

```javascript
const { Config } = require('longbridge');

const config = Config.fromApikey(
process.env.LONGBRIDGE_APP_KEY,
process.env.LONGBRIDGE_APP_SECRET,
process.env.LONGBRIDGE_ACCESS_TOKEN,
{ enablePapertrading: true },
);
```

## Troubleshooting

- Windows `setx` requires a new terminal; use `set` for the current `cmd.exe` session.
Expand Down
14 changes: 14 additions & 0 deletions nodejs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ pub struct ExtraConfigParams {
pub enable_print_quote_packages: Option<bool>,
/// Set the path of the log files (Default: `no logs`)
pub log_path: Option<String>,
/// Enable paper trading mode (default: `false`).
///
/// When `true`, all API calls target the paper trading (simulation)
/// environment. The server validates the token: if it belongs to a
/// real-money account the server returns an error.
///
/// When `false` (the default) the server imposes no restrictions — both
/// paper trading and real-money accounts are accepted.
///
/// Paper trading users should set this to `true` as a safety guard.
pub enable_papertrading: Option<bool>,
}

fn apply_extra(
Expand Down Expand Up @@ -62,6 +73,9 @@ fn apply_extra(
if let Some(log_path) = extra.log_path {
config.set_log_path(log_path);
}
if let Some(true) = extra.enable_papertrading {
config.set_enable_papertrading();
}
}
config
}
Expand Down
33 changes: 33 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center"
| LONGBRIDGE_PUSH_CANDLESTICK_MODE | `realtime` or `confirmed` (Default: `realtime`) |
| LONGBRIDGE_PRINT_QUOTE_PACKAGES | Print quote packages when connected, `true` or `false` (Default: `true`) |
| LONGBRIDGE_LOG_PATH | Set the path of the log files (Default: `no logs`) |
| LONGBRIDGE_PAPERTRADING | Enable paper trading mode, `true` or `false` (Default: `false`). See [Paper Trading](#paper-trading). |

Then create a config from the environment:

Expand Down Expand Up @@ -292,6 +293,38 @@ asyncio.run(main())

See the `*_async.py` examples in `examples/python/` for full async flows.

## Paper Trading

If your account is a **paper trading** (simulation) account and you want to
place orders, you must explicitly enable paper trading mode. When enabled, all
API calls target the paper trading environment and the server validates the
token — if the token belongs to a real-money account the server returns an
error.

By default this option is **off**: the server imposes no restrictions and
accepts requests from both paper trading and real-money accounts.

**Via environment variable** (applies automatically to all constructor methods):

```bash
export LONGBRIDGE_PAPERTRADING=true # macOS / Linux
```

```powershell
$env:LONGBRIDGE_PAPERTRADING = "true" # Windows PowerShell
```

**Programmatically:**

```python
from longbridge.openapi import Config

config = Config.from_apikey(
"app-key", "app-secret", "access-token",
enable_papertrading=True,
)
```

## Troubleshooting

- Windows `setx` requires a new terminal; use `set` for the current `cmd.exe` session.
Expand Down
Loading
Loading