当前位置:   article > 正文

KLINECHARTS

klinecharts
class e0 {
    constructor(l) {
        En(this, "_apiKey"), En(this, "_prevSymbolMarket"), En(this, "_ws"), this._apiKey = l
    }

    async searchSymbols(l) {
        return await ((await (await fetch(`https://api.polygon.io/v3/reference/tickers?apiKey=${this._apiKey}&active=true&search=${l ?? ""}`)).json()).results || []).map(a => ({
            ticker: a.ticker,
            name: a.name,
            shortName: a.ticker,
            market: a.market,
            exchange: a.primary_exchange,
            priceCurrency: a.currency_name,
            type: a.type,
            logo: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAA66SURBVHic7Z17cFTVGcB/527AiKGgRA0ShGhKoQjFMb4qUMCMPIrWqdbHSEdlHDGgI9V2aq2d1hmKtVbRsSTGEcQRp4pStaZQlNYUwYLiSKU0SCMBDRCmoQSJGGF3T/84d2VZk+w9d899hf3NMBnl3ns+5vtyHt/5HoIehpQIaijDYjiSciRlwCCgBCgG+gNFQCGCAvUScaADaAfagFagBdiFoAlBI0m2UkWTEMgA/lmeIYIWIFdkLQNJMBbBJUjOA8agFOwF7cAmBO8hWUeMtWIWezwayxciZwByGb1pZTyCaUguA0YGLNIWBK8jWUExa8Q1HA5YHi0iYQByGTH2UYnkBmA6cHLQMnXBfqAOwXMMYLW4hkTQAmUj1AYgqzkLuAXBTUgGBi2PFoI9SJYAT4nZbA9anK4IpQHIhUzE4i4k04OWxQiCOpI8IubwZtCiZBIqA5A1TEdyH3Bh0LJ4xAYE80QVdUELkiIUBiCf4FIk85FcELQsviB4B8G94jb+GrwoASKfZBgJHkUyNUg5AkOwkhhzxa1sC06EAJALKUJwL3A30DsIGULEYeBhJPPFHNr9Htx3A5A1TECyGCjze+yQ04Rgpqii3s9BfTMAWUsfksxD8iO/xowkggVY3Cdmccif4XxAPskw4rwCjPBjvB5AAwVc6cfewPJ6AFnNzcTZSF75OowgzkZZzc1eD+SZAUiJkNX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XF/wF+fTz59Jc5ygAAAABJRU5ErkJggg=="
        }))
    }

    async getHistoryKLineData(l, a, v, m) {
        return await ((await (await fetch(`https://api.polygon.io/v2/aggs/ticker/${l.ticker}/range/${a.multiplier}/${a.timespan}/${v}/${m}?apiKey=${this._apiKey}`)).json()).results || []).map(C => ({timestamp: C.t, open: C.o, high: C.h, low: C.l, close: C.c, volume: C.v, turnover: C.vw}))
    }

    subscribe(l, a, v) {
        var m, C;
        this._prevSymbolMarket !== l.market ? ((m = this._ws) == null || m.close(), this._ws = new WebSocket(`wss://delayed.polygon.io/${l.market}`), this._ws.onopen = () => {
            var S;
            (S = this._ws) == null || S.send(JSON.stringify({action: "auth", params: this._apiKey}))
        }, this._ws.onmessage = S => {
            var b;
            const A = JSON.parse(S.data);
            A[0].ev === "status" ? A[0].status === "auth_success" && ((b = this._ws) == null || b.send(JSON.stringify({action: "subscribe", params: `T.${l.ticker}`}))) : "sym" in A && v({timestamp: A.s, open: A.o, high: A.h, low: A.l, close: A.c, volume: A.v, turnover: A.vw})
        }) : (C = this._ws) == null || C.send(JSON.stringify({action: "subscribe", params: `T.${l.ticker}`})), this._prevSymbolMarket = l.market
    }

    unsubscribe(l, a) {
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
class CustomDatafeed {
  /**
   * 模糊搜索标的
   * 在搜索框输入的时候触发
   * 返回标的信息数组
   */
  searchSymbols (search?: string): Promise<SymbolInfo[]> {
    // 根据模糊字段远程拉取标的数据
  }

  /**
   * 获取历史k线数据
   * 当标的和周期发生变化的时候触发
   * 
   * 返回标的k线数据数组
   */
  getHistoryKLineData (symbol: SymbolInfo, period: Period, from: number, to: number): Promise<KLineData[]> {
    // 完成数据请求
  }

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

  /**
   * 取消订阅标的在某个周期的实时数据
   * 当标的和周期发生变化的时候触发
   * 
   */ 
  unsubscribe (symbol: SymbolInfo, period: Period): void {
    // 完成ws订阅取消或者http轮询取消
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
{
    "results"
:
    [{"ticker": "A", "name": "Agilent Technologies Inc.", "market": "stocks", "locale": "us", "primary_exchange": "XNYS", "type": "CS", "active": true, "currency_name": "usd", "cik": "0001090872", "composite_figi": "BBG000C2V3D6", "share_class_figi": "BBG001SCTQY4", "last_updated_utc": "2023-05-03T00:00:00Z"}, {"ticker": "AA", "name": "Alcoa Corporation", "market": "stocks", "locale": "us", "primary_exchange": "XNYS", "type": "CS", "active": true, "currency_name": "usd", "cik": "0001675149", "composite_figi": "BBG00B3T3HD3", "share_class_figi": "BBG00B3T3HF1", "last_updated_utc": "2023-05-03T00:00:00Z"}, {"ticker": "AAA", "name": "AXS First Priority CLO Bond ETF", "market": "stocks", "locale": "us", "primary_exchange": "ARCX", "type": "ETF", "active": true, "currency_name": "usd", "cik": "0001776878", "composite_figi": "BBG01B0JRCS6", "share_class_figi": "BBG01B0JRCT5", "last_updated_utc": "2023-05-03T00:00:00Z"}, {
        "ticker": "AAAIF",
        "name": "ALTERNATIVE INVSTMENT TR",
        "market": "otc",
        "locale": "us",
        "type": "FUND",
        "active": true,
        "currency_name": "USD",
        "last_updated_utc": "2022-08-26T05:00:07.114Z"
    },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/124000
推荐阅读
相关标签
  

闽ICP备14008679号