longbridge
Advanced tools
Comparing version 0.2.8 to 0.2.9
235
index.d.ts
@@ -390,3 +390,3 @@ /* tslint:disable */ | ||
* let config = Config.fromEnv() | ||
* let ctx = new QuoteContext(config, (_, event) => console.log(event)) | ||
* let ctx = new QuoteContext(config, (_, event) => console.log(event.toString())) | ||
* await ctx.open() | ||
@@ -497,3 +497,3 @@ * await ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true) | ||
* let resp = await ctx.depth("700.HK") | ||
* console.log(obj.toString()) | ||
* console.log(resp.toString()) | ||
* ``` | ||
@@ -514,3 +514,3 @@ */ | ||
* let resp = await ctx.brokers("700.HK") | ||
* console.log(obj.toString()) | ||
* console.log(resp.toString()) | ||
* ``` | ||
@@ -604,3 +604,3 @@ */ | ||
* for (let obj of resp) { | ||
* console.log(obj) | ||
* console.log(obj.toString()) | ||
* } | ||
@@ -623,3 +623,3 @@ * ``` | ||
* for (let obj of resp) { | ||
* console.log(obj) | ||
* console.log(obj.toString()) | ||
* } | ||
@@ -642,3 +642,3 @@ * ``` | ||
* for (let obj of resp) { | ||
* console.log(obj) | ||
* console.log(obj.toString()) | ||
* } | ||
@@ -661,3 +661,3 @@ * ``` | ||
* for (let obj of resp) { | ||
* console.log(obj) | ||
* console.log(obj.toString()) | ||
* } | ||
@@ -679,3 +679,3 @@ * ``` | ||
* let resp = await ctx.tradingDays() | ||
* console.log(resp) | ||
* console.log(resp.toString()) | ||
* ``` | ||
@@ -701,3 +701,3 @@ */ | ||
* for (let obj of resp) { | ||
* console.log(obj) | ||
* console.log(obj.toString()) | ||
* } | ||
@@ -723,3 +723,3 @@ * ``` | ||
* let resp = await ctx.realtimeDepth("HK.700") | ||
* console.log(resp) | ||
* console.log(resp.toString()) | ||
* ``` | ||
@@ -744,3 +744,3 @@ */ | ||
* let resp = await ctx.realtimeBrokers("HK.700") | ||
* console.log(resp) | ||
* console.log(resp.toString()) | ||
* ``` | ||
@@ -766,3 +766,3 @@ */ | ||
* for (let obj of resp) { | ||
* console.log(obj) | ||
* console.log(obj.toString()) | ||
* } | ||
@@ -1197,23 +1197,212 @@ * ``` | ||
unsubscribe(topics: Array<TopicType>): Promise<void> | ||
/** Get history executions */ | ||
/** | ||
* Get history executions | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext, GetHistoryExecutionsOptions } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.historyExecutions( | ||
* new GetHistoryExecutionsOptions() | ||
* .symbol("700.HK") | ||
* .startAt(new Date(2022, 5, 9)) | ||
* .endAt(new Date(2022, 5, 12)) | ||
* ) | ||
* for (let obj of resp) { | ||
* console.log(obj.toString()) | ||
* } | ||
* ``` | ||
*/ | ||
historyExecutions(opts?: GetHistoryExecutionsOptions | undefined | null): Promise<Array<Execution>> | ||
/** Get today executions */ | ||
/** | ||
* Get today executions | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext, GetTodayExecutionsOptions } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.todayExecutions(new GetTodayExecutionsOptions().symbol("700.HK")) | ||
* for (let obj of resp) { | ||
* console.log(obj.toString()) | ||
* } | ||
* ``` | ||
*/ | ||
todayExecutions(opts?: GetTodayExecutionsOptions | undefined | null): Promise<Array<Execution>> | ||
/** Get history orders */ | ||
/** | ||
* Get history orders | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext, GetHistoryOrdersOptions, OrderStatus, OrderSide, Market } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.historyOrders( | ||
* new GetHistoryOrdersOptions() | ||
* .symbol("700.HK") | ||
* .status([OrderStatus.Filled, OrderStatus.New]) | ||
* .side(OrderSide.Buy) | ||
* .market(Market.HK) | ||
* .startAt(2022, 5, 9) | ||
* .endAt(2022, 5, 12) | ||
* ) | ||
* for (let obj of resp) { | ||
* console.log(obj.toString()) | ||
* } | ||
* ``` | ||
*/ | ||
historyOrders(opts?: GetHistoryOrdersOptions | undefined | null): Promise<Array<Order>> | ||
/** Get today orders */ | ||
/** | ||
* Get today orders | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext, GetTodayOrdersOptions, OrderStatus, OrderSide, Market } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.todayOrders( | ||
* new GetTodayOrdersOptions() | ||
* .symbol("700.HK") | ||
* .status([OrderStatus.Filled, OrderStatus.New]) | ||
* .side(OrderSide.Buy) | ||
* .market(Market.HK) | ||
* ) | ||
* for (let obj of resp) { | ||
* console.log(obj.toString()) | ||
* } | ||
* ``` | ||
*/ | ||
todayOrders(opts?: GetTodayOrdersOptions | undefined | null): Promise<Array<Order>> | ||
/** Replace order */ | ||
/** | ||
* Replace order | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext, ReplaceOrderOptions, Decimal } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.replaceOrder(new ReplaceOrderOptions("700.HK", new Decimal("100")).price(new Decimal("300"))) | ||
* for (let obj of resp) { | ||
* console.log(obj.toString()) | ||
* } | ||
* ``` | ||
*/ | ||
replaceOrder(opts: ReplaceOrderOptions): Promise<void> | ||
/** Submit order */ | ||
/** | ||
* Submit order | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext, SubmitOrderOptions, OrderType, OrderSide, Decimal, TimeInForceType } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.submitOrder( | ||
* new SubmitOrderOptions("700.HK", OrderType.LO, OrderSide.Buy, new Decimal("200"), TimeInForceType.Day) | ||
* .price(new Decimal("300")) | ||
* ) | ||
* console.log(resp) | ||
* ``` | ||
*/ | ||
submitOrder(opts: SubmitOrderOptions): Promise<SubmitOrderResponse> | ||
/** Withdraw order */ | ||
/** | ||
* Withdraw order | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* await ctx.withdrawOrder("709043056541253632") | ||
* ``` | ||
*/ | ||
withdrawOrder(orderId: string): Promise<void> | ||
/** Get account balance */ | ||
/** | ||
* Get account balance | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.accountBalance() | ||
* for (let obj of resp) { | ||
* console.log(obj.toString()) | ||
* } | ||
* ``` | ||
*/ | ||
accountBalance(): Promise<Array<AccountBalance>> | ||
/** Get cash flow */ | ||
/** | ||
* Get cash flow | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext, GetCashFlowOptions } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.cashFlow(new GetCashFlowOptions(new Date(2022, 5, 9), new Date(2022, 5, 12))) | ||
* for (let obj of resp) { | ||
* console.log(obj.toString()) | ||
* } | ||
* ``` | ||
*/ | ||
cashFlow(opts: GetCashFlowOptions): Promise<Array<CashFlow>> | ||
/** Get fund positions */ | ||
/** | ||
* Get fund positions | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.fundPositions() | ||
* console.log(resp) | ||
* ``` | ||
*/ | ||
fundPositions(symbols?: Array<string> | undefined | null): Promise<FundPositionsResponse> | ||
/** Get stock positions */ | ||
/** | ||
* Get stock positions | ||
* | ||
* #### Example | ||
* | ||
* ```javascript | ||
* import { Config, TradeContext } from 'longbridge' | ||
* | ||
* let config = Config.fromEnv() | ||
* let ctx = new TradeContext(config) | ||
* await ctx.open() | ||
* let resp = await ctx.stockPositions() | ||
* console.log(resp) | ||
* ``` | ||
*/ | ||
stockPositions(symbols?: Array<string> | undefined | null): Promise<StockPositionsResponse> | ||
@@ -1220,0 +1409,0 @@ } |
{ | ||
"name": "longbridge", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"main": "index.js", | ||
@@ -31,6 +31,6 @@ "types": "index.d.ts", | ||
"optionalDependencies": { | ||
"longbridge-win32-x64-msvc": "0.2.8", | ||
"longbridge-darwin-x64": "0.2.8", | ||
"longbridge-linux-x64-gnu": "0.2.8" | ||
"longbridge-win32-x64-msvc": "0.2.9", | ||
"longbridge-darwin-x64": "0.2.9", | ||
"longbridge-linux-x64-gnu": "0.2.9" | ||
} | ||
} |
# Longbridge OpenAPI SDK for Node.js | ||
`longbridge` provides an easy-to-use interface for invokes [`Longbridge OpenAPI`](https://open.longbridgeapp.com/en/). | ||
## Quickstart | ||
_Install Longbridge OpenAPI SDK_ | ||
```bash | ||
npm install longbridge | ||
``` | ||
_Setting environment variables(MacOS/Linux)_ | ||
```bash | ||
export LONGBRIDGE_APP_KEY="App Key get from user center" | ||
export LONGBRIDGE_APP_SECRET="App Secret get from user center" | ||
export LONGBRIDGE_ACCESS_TOKEN="Access Token get from user center" | ||
``` | ||
_Setting environment variables(Windows)_ | ||
```powershell | ||
setx LONGBRIDGE_APP_KEY "App Key get from user center" | ||
setx LONGBRIDGE_APP_SECRET "App Secret get from user center" | ||
setx LONGBRIDGE_ACCESS_TOKEN "Access Token get from user center" | ||
``` | ||
## Quote API _(Get basic information of securities)_ | ||
```javascript | ||
import { Config, QuoteContext } from 'longbridge' | ||
let config = Config.fromEnv() | ||
let ctx = new QuoteContext(config) | ||
await ctx.open() | ||
let resp = await ctx.quote(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"]) | ||
for (let obj of resp) { | ||
console.log(obj.toString()) | ||
} | ||
``` | ||
## Quote API _(Subscribe quotes)_ | ||
```javascript | ||
import { Config, QuoteContext, SubType } from 'longbridge' | ||
let config = Config.fromEnv() | ||
let ctx = new QuoteContext(config, (_, event) => console.log(event.toString())) | ||
await ctx.open() | ||
await ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true) | ||
``` | ||
## Trade API _(Submit order)_ | ||
```javascript | ||
import { Config, TradeContext, SubmitOrderOptions, OrderType, OrderSide, Decimal, TimeInForceType } from 'longbridge' | ||
let config = Config.fromEnv() | ||
let ctx = new TradeContext(config) | ||
await ctx.open() | ||
let resp = await ctx.submitOrder( | ||
new SubmitOrderOptions("700.HK", OrderType.LO, OrderSide.Buy, new Decimal("200"), TimeInForceType.Day) | ||
.price(new Decimal("300")) | ||
) | ||
console.log(resp) | ||
``` | ||
## License | ||
Licensed under either of | ||
* Apache License, Version 2.0,([LICENSE-APACHE](./LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) | ||
* MIT license ([LICENSE-MIT](./LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. |
59381
6
2050
75