Static
newReturns the quote package details
Set quote callback, after receiving the quote data push, it will call back to this function.
Set depth callback, after receiving the depth data push, it will call back to this function.
Set brokers callback, after receiving the brokers data push, it will call back to this function.
Set trades callback, after receiving the trades data push, it will call back to this function.
Set candlestick callback, after receiving the trades data push, it will call back to this function.
Subscribe
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"], [SubType.Quote], true);
});
Unsubscribe
const { Config, QuoteContext, SubType } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => {
ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true)
.then(() => ctx.unsubscribe(["AAPL.US"], [SubType.Quote], true)))
})
Subscribe security candlesticks
Unsubscribe security candlesticks
Get subscription information
const { Config, QuoteContext, SubType } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config)
.then((ctx) => {
return ctx
.subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true)
.then(() => ctx.subscriptions());
})
.then((resp) => console.log(resp.toString()));
Get basic information of securities
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.staticInfo(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"]))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Get quote 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())
}
})
Get quote of option securities
import { Config, QuoteContext } from 'longport'
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.optionQuote(["AAPL230317P160000.US"]))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Get quote of warrant securities
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.warrantQuote(["21125.HK"]))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Get security depth
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.depth("700.HK"))
.then((resp) => console.log(resp.toString()))
Get security brokers
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.brokers("700.HK"))
.then((resp) => console.log(resp.toString()))
Get participants
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.participants())
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString());
}
})
Get security trades
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.trades("700.HK", 10))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString());
}
})
Get security intraday
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.intraday("700.HK"))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString());
}
})
Get security candlesticks
const { Config, QuoteContext, Period, AdjustType } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.candlesticks("700.HK", Period.Day, 10, AdjustType.NoAdjust))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString());
}
})
Get security history candlesticks by offset
Get security history candlesticks by date
Optional
start: NaiveDateOptional
end: NaiveDateGet option chain expiry date list
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.optionChainExpiryDateList("AAPL.US"))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Get option chain info by date
const { Config, QuoteContext, NaiveDate } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.optionChainInfoByDate("AAPL.US", new NaiveDate(2023, 1, 20)))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Get warrant issuers
const { Config, QuoteContext, NaiveDate } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.warrantIssuers())
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Query warrant list
const { Config, QuoteContext, WarrantSortBy, SortOrderType } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.warrantList("700.HK", WarrantSortBy.LastDone, SortOrderType.Asc))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Optional
warrantType: WarrantType[]Optional
issuer: number[]Optional
expiryDate: FilterWarrantExpiryDate[]Optional
priceType: FilterWarrantInOutBoundsType[]Optional
status: WarrantStatus[]Get trading session of the day
const { Config, QuoteContext, NaiveDate } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.tradingSession())
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Get trading session of the day
const { Config, QuoteContext, Market, NaiveDate } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.tradingDays(Market.HK, new NaiveDate(2022, 1, 20), new NaiveDate(2022, 2, 20)))
.then((resp) => console.log(resp.toString()))
Get capital flow intraday
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.capitalFlow("700.HK"))
.then((resp) => {
for (let obj of resp) {
console.log(obj.toString())
}
})
Get capital distribution
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.capitalDistribution("700.HK"))
.then((resp) => console.log(resp.toString()))
Get calc indexes
Get watchlist
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv()
QuoteContext.new(config)
.then((ctx) => ctx.watchList())
.then((resp) => console.log(resp.toString()))
Create watchlist group
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config)
.then((ctx) => {
ctx.createWatchlistGroup({
name: "Watchlist1",
securities: ["700.HK", "BABA.US"],
})
.then((group_id) => console.log(group_id));
Delete watchlist group
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config)
.then(ctx => ctx.deleteWatchlistGroup({ id: 10086 });
Update watchlist group
const { Config, QuoteContext } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config)
.then(ctx => ctx.updateWatchlistGroup({
id: 10086,
name: "Watchlist2",
securities: ["700.HK", "BABA.US"],
});
Get security list
const { Config, QuoteContext, Market, SecurityListCategory } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config)
.then((ctx) => ctx.securityList(Market.US, SecurityListCategory.Overnight))
.then((resp) => console.log(resp.toString()));
Get real-time quote
const { Config, QuoteContext, SubType } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config).then((ctx) => {
ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true).then(() => {
setTimeout(() => {
ctx.realtimeQuote(["700.HK", "AAPL.US"]).then((resp) => {
for (let obj of resp) {
console.log(obj.toString());
}
});
}, 5000);
});
});
Get real-time depth
const { Config, QuoteContext, SubType } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config).then((ctx) => {
ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Depth], true);
setTimeout(
() =>
ctx.realtimeDepth("700.HK").then((resp) => console.log(resp.toString())),
5000
);
});
Get real-time brokers
const { Config, QuoteContext, NaiveDate, SubType } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config).then((ctx) => {
ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Brokers], true).then(() => {
setTimeout(
() =>
ctx
.realtimeBrokers("700.HK")
.then((resp) => console.log(resp.toString())),
5000
);
});
});
Get real-time trades
const { Config, QuoteContext, SubType } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config).then((ctx) => {
ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Trade], false).then(() => {
setTimeout(() => {
ctx.realtimeTrades("700.HK", 10).then((resp) => {
for (let obj of resp) {
console.log(obj.toString());
}
});
}, 5000);
});
});
Get real-time candlesticks
const { Config, QuoteContext, Period } = require("longport")
let config = Config.fromEnv();
QuoteContext.new(config).then((ctx) => {
ctx.subscribeCandlesticks("700.HK", Period.Min_1).then(() => {
setTimeout(() => {
ctx.realtimeCandlesticks("700.HK", Period.Min_1, 10).then((resp) => {
for (let obj of resp) {
console.log(obj.toString());
}
});
}, 5000);
});
});
Quote context