2.1.12 • Published 5 months ago

longport v2.1.12

Weekly downloads
-
License
MIT OR Apache-2.0
Repository
github
Last release
5 months 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

2.0.3

8 months ago

2.0.2

8 months ago

2.0.5

8 months ago

2.0.4

8 months ago

2.1.12

5 months ago

2.1.10

5 months ago

2.1.11

5 months ago

1.1.1

7 months ago

1.1.0

8 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

2.1.4

7 months ago

2.1.3

7 months ago

2.1.6

6 months ago

2.1.5

7 months ago

2.1.8

6 months ago

2.1.7

6 months ago

1.0.43

9 months ago

2.1.0

8 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.39

10 months ago

1.0.42

9 months ago

1.0.41

9 months ago

1.0.32

11 months ago

1.0.35

10 months ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.29

12 months ago

1.0.27

1 year ago

1.0.31

11 months ago

1.0.30

11 months ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.11

1 year ago

1.0.13

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago