Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我的图表一直是第一次获取到的数据在不断重复 #39

Open
wakaryry opened this issue Apr 11, 2024 · 2 comments
Open

我的图表一直是第一次获取到的数据在不断重复 #39

wakaryry opened this issue Apr 11, 2024 · 2 comments

Comments

@wakaryry
Copy link

import {getStockRecentKMinuteRT, getStockKRT} from '@/api/stockrt'
import {parseTime} from '@/utils/utils'

export default class CustomDatafeed {
  /**
   * 模糊搜索标的
   * 在搜索框输入的时候触发
   * 返回标的信息数组
   */
  searchSymbols(search) {
    // 根据模糊字段远程拉取标的数据
    console.log(search)
  }

  /**
   * 获取历史k线数据
   * 当标的和周期发生变化的时候触发
   *
   * 返回标的k线数据数组
   */
  getHistoryKLineData(symbol, period, from, to) {
    // 完成数据请求
    console.log(symbol, period, from, to, parseTime(from, '{y}-{m}-{d} {h}:{i}:{s}'), parseTime(to, '{y}-{m}-{d} {h}:{i}:{s}'))
    let api = getStockRecentKMinuteRT
    const params = {
      code: symbol.ticker,
      period: `${period.multiplier}`,
      start_date: parseTime(from, '{y}-{m}-{d} {h}:{i}:{s}'),
      end_date:  parseTime(to, '{y}-{m}-{d} {h}:{i}:{s}')
    }
    if (period.timespan != 'minute') {
      api = getStockKRT
      params.period = period.timespan == 'day' ? 'daily': (period.timespan == 'week' ? 'weekly': 'monthly')
      params.start_date = parseTime(from, '{y}{m}{d}')
      params.end_date = parseTime(to, '{y}{m}{d}')
    }
    return new Promise((resolve, reject) => {
        api(params).then((res) => {
            const _its = res.data.items || []
            const _items = _its.map(item => {
                return {
                    timestamp: (new Date(item.time||item.date)).getTime(),
                    open: item.open,
                    close: item.close,
                    high: item.highest,
                    low: item.lowest,
                    volume: item.volume,
                    turnover: item.turnover || 1
                }
            })
            resolve(_items)
        }).catch(() => {
            resolve([])
        })
    })
  }

  /**
   * 订阅标的在某个周期的实时数据
   * 当标的和周期发生变化的时候触发
   *
   * 通过callback告知图表接收数据
   */
  subscribe(symbol, period, callback) {
    // 完成ws订阅或者http轮询
    console.log('subscribe', symbol, period, callback)
  }

  /**
   * 取消订阅标的在某个周期的实时数据
   * 当标的和周期发生变化的时候触发
   *
   */
  unsubscribe(symbol, period) {
    // 完成ws订阅取消或者http轮询取消
    console.log('unsubscribe', symbol, period)
  }
}

当我拖动图表的时候,我能看到getHistoryKLineData被触发,然后通过新的from/to来获取到数据,我看了下接口请求的参数和返回的数据都是正常。但是图表里面显示的一直都是第一次调用getHistoryKLineData时的数据的重复显示!

@wakaryry
Copy link
Author

image

@joketanke
Copy link

from, to 是时间戳,你转换后在数据源拉取的数据有问题,当你放大缩小图表时候就会把数据重复渲染出来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants