Skip to content

Commit 17b7675

Browse files
committed
examples(nodejs): add history candlesticks example
1 parent b099c0f commit 17b7675

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const {
2+
Config,
3+
QuoteContext,
4+
Period,
5+
AdjustType,
6+
TradeSessions,
7+
NaiveDate,
8+
NaiveDatetime,
9+
Time,
10+
OAuth,
11+
} = require('longbridge');
12+
13+
async function main() {
14+
const oauth = await OAuth.build("your-client-id", (_, url) => {
15+
console.log("Open this URL to authorize: " + url);
16+
});
17+
const config = Config.fromOAuth(oauth);
18+
const ctx = await QuoteContext.new(config);
19+
20+
// get candlesticks by offset
21+
console.log("get candlesticks by offset");
22+
console.log("====================");
23+
const datetime = new NaiveDatetime(new NaiveDate(2023, 8, 18), new Time(0, 0, 0));
24+
const byOffset = await ctx.historyCandlesticksByOffset(
25+
"700.HK",
26+
Period.Day,
27+
AdjustType.NoAdjust,
28+
false,
29+
datetime,
30+
10,
31+
TradeSessions.Intraday,
32+
);
33+
for (const candlestick of byOffset) {
34+
console.log(candlestick.toString());
35+
}
36+
37+
// get candlesticks by date
38+
console.log("get candlesticks by date");
39+
console.log("====================");
40+
const byDate = await ctx.historyCandlesticksByDate(
41+
"700.HK",
42+
Period.Day,
43+
AdjustType.NoAdjust,
44+
new NaiveDate(2022, 5, 5),
45+
new NaiveDate(2022, 6, 23),
46+
TradeSessions.Intraday,
47+
);
48+
for (const candlestick of byDate) {
49+
console.log(candlestick.toString());
50+
}
51+
}
52+
53+
main().catch(console.error);

0 commit comments

Comments
 (0)