11# LongPort OpenAPI SDK for C
22
3- ` longport ` provides an easy-to-use interface for invokes [ ` LongPort OpenAPI ` ] ( https://open.longportapp.com/en/ ) .
3+ ` longport ` provides an easy-to-use interface for invoking [ ` LongPort OpenAPI ` ] ( https://open.longportapp.com/en/ ) .
4+
5+ ## Documentation
6+
7+ - SDK docs: https://longportapp.github.io/openapi/c/index.html
8+ - LongPort OpenAPI: https://open.longportapp.com/en/
9+
10+ ## Examples
11+
12+ Runnable examples live in ` examples/c/ ` :
13+
14+ - ` examples/c/account_asset/main.c `
15+ - ` examples/c/get_quote/main.c `
16+ - ` examples/c/http_client/main.c `
17+ - ` examples/c/subscribe_quote/main.c `
18+ - ` examples/c/submit_order/main.c `
19+ - ` examples/c/today_orders/main.c `
420
521## Quickstart
622
@@ -44,8 +60,7 @@ on_quote(const struct lb_async_result_t* res)
4460 }
4561
4662 lb_security_quote_t* data = (lb_security_quote_t* )res->data;
47- fop(int i = 0; i < res->length; i++)
48- {
63+ for (int i = 0; i < res->length; i++) {
4964 const lb_security_quote_t* quote = &data[ i] ;
5065 printf("%s timestamp=%ld last_done=%f open=%f high=%f low=%f volume=%ld "
5166 "turnover=%f\n",
@@ -72,7 +87,7 @@ on_quote_context_created(const struct lb_async_result_t* res)
7287 * ((const lb_quote_context_t** )res->userdata) = res->ctx;
7388
7489 const char* symbols[ ] = { "700.HK", "AAPL.US", "TSLA.US", "NFLX.US" };
75- lb_quote_context_quote(res->ctx, symbols, on_quote, NULL);
90+ lb_quote_context_quote(res->ctx, symbols, 4, on_quote, NULL);
7691}
7792
7893int
@@ -150,7 +165,7 @@ on_quote_context_created(const struct lb_async_result_t* res)
150165
151166 const char* symbols[] = { "700.HK", "AAPL.US", "TSLA.US", "NFLX.US" };
152167 lb_quote_context_subscribe(
153- res->ctx, symbols, 4, LB_SUBFLAGS_QUOTE, true, on_subscrbe, NULL);
168+ res->ctx, symbols, 4, LB_SUBFLAGS_QUOTE, on_subscrbe, NULL);
154169}
155170
156171int
@@ -212,12 +227,18 @@ on_trade_context_created(const struct lb_async_result_t* res)
212227 * ((const lb_quote_context_t** )res->userdata) = res->ctx;
213228
214229 lb_decimal_t* submitted_price = lb_decimal_from_double(50.0);
230+ lb_decimal_t* submitted_quantity = lb_decimal_from_double(200.0);
215231 lb_submit_order_options_t opts = {
216- "700.HK", OrderTypeLO, OrderSideBuy, 200, TimeInForceDay, submitted_price,
217- NULL, NULL, NULL, NULL, NULL, NULL,
232+ "700.HK", OrderTypeLO,
233+ OrderSideBuy, submitted_quantity,
234+ TimeInForceDay, submitted_price,
235+ NULL, NULL,
236+ NULL, NULL,
237+ NULL, NULL,
218238 NULL,
219239 };
220240 lb_decimal_free(submitted_price);
241+ lb_decimal_free(submitted_quantity);
221242 lb_trade_context_submit_order(res->ctx, &opts, on_submit_order, NULL);
222243}
223244
@@ -245,9 +266,16 @@ main(int argc, char const* argv[])
245266}
246267```
247268
269+ ## Troubleshooting
270+
271+ - Windows `setx` requires a new terminal; use `set` for the current `cmd.exe` session.
272+ - If you don't see callbacks, keep the process alive (examples use `getchar()`).
273+ - If building on Linux/macOS, ensure `ncurses` is installed (examples link it on non-Windows).
274+ - For debugging, set `LONGPORT_LOG_PATH` to enable SDK logs.
275+
248276## License
249277
250278Licensed under either of
251279
252- * Apache License, Version 2.0,([LICENSE-APACHE](./LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
253- * MIT license ([LICENSE-MIT](./LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option.
280+ * Apache License, Version 2.0,([LICENSE-APACHE](.. /LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
281+ * MIT license ([LICENSE-MIT](.. /LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option.
0 commit comments