1.0.23 • Published 20 days ago

longport v1.0.23

Weekly downloads
-
License
MIT OR Apache-2.0
Repository
github
Last release
20 days ago

LongPort OpenAPI SDK for Node.js

longport provides an easy-to-use interface for invokes LongPort OpenAPI.

Quickstart

Install LongPort OpenAPI SDK

npm install longport

Setting environment variables(MacOS/Linux)

export LONGPORT_APP_KEY="App Key get from user center"
export LONGPORT_APP_SECRET="App Secret get from user center"
export LONGPORT_ACCESS_TOKEN="Access Token get from user center"

Setting environment variables(Windows)

setx LONGPORT_APP_KEY "App Key get from user center"
setx LONGPORT_APP_SECRET "App Secret get from user center"
setx LONGPORT_ACCESS_TOKEN "Access Token get from user center"

Quote API (Get basic information of securities)

const { Config, QuoteContext } = require("longport");

let config = Config.fromEnv();
QuoteContext.new(config)
    .then((ctx) => ctx.quote(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"]))
    .then((resp) => {
        for (let obj of resp) {
            console.log(obj.toString())
        }
    });

Quote API (Subscribe quotes)

const { Config, QuoteContext, SubType } = require("longport");

let config = Config.fromEnv();
QuoteContext.new(config).then((ctx) => {
  ctx.setOnQuote((_, event) => console.log(event.toString()));
  ctx.subscribe(
    ["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"],
    [SubType.Quote],
    true
  );
});

Trade API (Submit order)

const {
  Config,
  TradeContext,
  Decimal,
  OrderSide,
  TimeInForceType,
  OrderType,
} = require("longport");

let config = Config.fromEnv();
TradeContext.new(config)
  .then((ctx) =>
    ctx.submitOrder({
      symbol: "700.HK",
      orderType: OrderType.LO,
      side: OrderSide.Buy,
      timeInForce: TimeInForceType.Day,
      submittedPrice: new Decimal("50"),
      submittedQuantity: 200,
    })
  )
  .then((resp) => console.log(resp.toString()));

License

Licensed under either of

1.0.23

20 days ago

1.0.22

24 days ago

1.0.21

1 month ago

1.0.20

1 month ago

1.0.19

2 months ago

1.0.18

2 months ago

1.0.16

2 months ago

1.0.15

2 months ago

1.0.14

2 months ago

1.0.11

2 months ago

1.0.13

2 months ago

1.0.10

2 months ago

1.0.9

2 months ago

1.0.8

2 months ago

1.0.7

2 months ago

1.0.6

3 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

6 months ago