我对交易视图的图表库相当陌生。我有自己的自定义数据源,我想将其集成。然而,在为其实现 JS API 时,由于某种原因,getBars 方法被无限次递归调用。
这是我的 JS API 代码:
获取Bars:
getBars: (symbolInfo, resolution, from=1611030900, to=1611030960, onHistoryCallback, onErrorCallback, firstDataRequest) => {
fetch('../BT_Data.json')
.then(response => response.json())
.then(btData => {
let bars = [];
btData.forEach(tuple => {
let timestamp = new Date(tuple.Timestamp);
let time = Math.floor(timestamp.getTime() / 1000); // Converting it to UNIX timestamp
bars = [...bars, {
time: time,
low: tuple.l,
high: tuple.h,
open: tuple.o,
close: tuple.c,
volume: tuple.v
}]
})
onHistoryCallback(bars, { noData: false });
})
.catch(error => console.log(error));
TradingView 图表库(链接需要 GitHub 存储库会员资格)。
当您使用 From 和 To unix 纪元时间字符串获取数据时,如果数据源中没有请求的数据,则需要设置 { noData: true }。
// btData is bars data you get from your data feed
// use from and to parameters to fetch only requested data
// so after one point in time, datafeed will not have any data so at that time, set noData: true like this
if(btData.length < 1){
onHistoryCallback([], { noData: true });
} else {
onHistoryCallback(bars, { noData: false });
}
我也是交易视图新手。很确定它与所需的倒计时
有关建议考虑 countBack 的优先级高于 from 的优先级,即必须返回 [from, to) 范围内的数据,但柱数不应小于 countBack。如果柱数少于 countBack,图表将再次调用 getBars。
let time = Math.floor(timestamp.getTime() / 1000); // Converting it to UNIX timestamp
不要将其转换为unix时间戳 它不包括 unix 时间戳。它需要条形数组中的正常 13 位时间戳。
getBars() 方法将被多次调用,直到它在数组中获得正常的时间戳。