StaticnewSet order changed callback, after receiving the order changed event, it will call back to this function.
Set grid order changed callback, after receiving the grid order changed event, it will call back to this function.
Subscribe
const {
OAuth, Config,
TradeContext,
Decimal,
OrderSide,
TimeInForceType,
OrderType,
TopicType,
} = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
ctx.setOnOrderChanged((_, event) => console.log(event.toString()));
await ctx.subscribe([TopicType.Private]);
const resp = await ctx.submitOrder({
symbol: "700.HK",
orderType: OrderType.LO,
side: OrderSide.Buy,
timeInForce: TimeInForceType.Day,
submittedPrice: new Decimal("50"),
submittedQuantity: 200,
});
console.log(resp.toString());
Get history executions
const { OAuth, Config, TradeContext } = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.historyExecutions({
symbol: "700.HK",
startAt: new Date(2022, 5, 9),
endAt: new Date(2022, 5, 12),
});
for (let obj of resp) {
console.log(obj.toString());
}
Optionalopts: GetHistoryExecutionsOptions | nullGet today executions
const { OAuth, Config, TradeContext } = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.todayExecutions({ symbol: "700.HK" });
for (let obj of resp) {
console.log(obj.toString());
}
Optionalopts: GetTodayExecutionsOptions | nullGet all executions
Optionalopts: GetAllExecutionsOptions | nullGet history orders
const {
OAuth, Config,
TradeContext,
OrderStatus,
OrderSide,
Market,
} = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.historyOrders({
symbol: "700.HK",
status: [OrderStatus.Filled, OrderStatus.New],
side: OrderSide.Buy,
market: Market.HK,
startAt: new Date(2022, 5, 9),
endAt: new Date(2022, 5, 12),
});
for (let obj of resp) {
console.log(obj.toString());
}
Optionalopts: GetHistoryOrdersOptions | nullGet today orders
const {
OAuth, Config,
TradeContext,
OrderStatus,
OrderSide,
Market,
} = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.todayOrders({
symbol: "700.HK",
status: [OrderStatus.Filled, OrderStatus.New],
side: OrderSide.Buy,
market: Market.HK,
});
for (let obj of resp) {
console.log(obj.toString());
}
Optionalopts: GetTodayOrdersOptions | nullReplace order
const { OAuth, Config, TradeContext, Decimal } = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
await ctx.replaceOrder({
orderId: "709043056541253632",
quantity: 100,
price: new Decimal("300"),
});
Submit order
const {
OAuth, Config,
TradeContext,
OrderType,
OrderSide,
Decimal,
TimeInForceType,
} = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.submitOrder({
symbol: "700.HK",
orderType: OrderType.LO,
side: OrderSide.Buy,
timeInForce: TimeInForceType.Day,
submittedQuantity: 200,
submittedPrice: new Decimal("300"),
});
console.log(resp.toString());
Submit a multi-leg option combination order (such as vertical spreads, straddles, strangles, collars, etc.). All legs are submitted together as a single strategy order.
const {
OAuth, Config,
TradeContext,
OrderType,
OrderSide,
Decimal,
MultiLegStrategy,
} = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.submitMultileg({
side: OrderSide.Buy,
orderType: OrderType.LO,
submittedQuantity: new Decimal("1"),
strategy: MultiLegStrategy.VerticalCallSpread,
submittedPrice: new Decimal("1.5"),
legs: [
{ symbol: "QQQ260731C764000.US", ratioQuantity: new Decimal("1") },
{ symbol: "QQQ260731C767000.US", ratioQuantity: new Decimal("1") },
],
});
console.log(resp.toString());
Cancel order
const { OAuth, Config, TradeContext } = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
await ctx.cancelOrder("709043056541253632");
OptionalisAttached: boolean | nullGet account balance
const { OAuth, Config, TradeContext } = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.accountBalance();
for (let obj of resp) {
console.log(obj.toString());
}
Optionalcurrency: string | nullGet cash flow
const { OAuth, Config, TradeContext } = require('longbridge');
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.cashFlow({
startAt: new Date(2022, 5, 9),
endAt: new Date(2022, 5, 12),
});
for (let obj of resp) {
console.log(obj.toString());
}
Get fund positions
const { OAuth, Config, TradeContext } = require('longbridge')
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.fundPositions();
console.log(resp);
Optionalsymbols: string[] | nullGet stock positions
const { OAuth, Config, TradeContext } = require('longbridge')
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.stockPositions();
console.log(resp);
Optionalsymbols: string[] | nullGet margin ratio
const { OAuth, Config, TradeContext } = require('longbridge')
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.marginRatio("700.HK");
console.log(resp);
Get order detail
const { OAuth, Config, TradeContext } = require('longbridge')
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.orderDetail("701276261045858304");
console.log(resp);
Query US order list. Returns JSON string. US token required. symbol: user-facing symbol e.g. "AAPL.US"; action: 0=all/1=buy/2=sell.
Get US order detail. US token required.
Get US account asset overview. US token required.
Get US realized P&L. US token required.
Optionalcategory: string | nullEstimating the maximum purchase quantity for Hong Kong and US stocks, warrants, and options
const { OAuth, Config, TradeContext, OrderType, OrderSide } = require('longbridge')
const oauth = await OAuth.build('your-client-id', (_, url) => console.log('Visit:', url));
const ctx = TradeContext.new(Config.fromOAuth(oauth));
const resp = await ctx.estimateMaxPurchaseQuantity({
symbol: "700.HK",
orderType: OrderType.LO,
side: OrderSide.Buy,
});
console.log(resp);
Trade context