{"id":4934,"date":"2026-09-22T07:23:00","date_gmt":"2026-09-21T23:23:00","guid":{"rendered":"https:\/\/laoyulaoyu.com\/?p=4934"},"modified":"2026-09-16T17:23:59","modified_gmt":"2026-09-16T09:23:59","slug":"%e5%9b%9b%e6%ad%a5%e6%8a%8atradingview%e5%9b%be%e8%a1%a8%e6%90%ac%e5%9b%9e%e7%94%b5%e8%84%91%ef%bc%8c%e6%8e%a5%e4%b8%8a%e8%87%aa%e5%b7%b1%e7%9a%84%e6%95%b0%e6%8d%ae%e6%ba%90","status":"publish","type":"post","link":"https:\/\/laoyulaoyu.com\/index.php\/2026\/09\/22\/%e5%9b%9b%e6%ad%a5%e6%8a%8atradingview%e5%9b%be%e8%a1%a8%e6%90%ac%e5%9b%9e%e7%94%b5%e8%84%91%ef%bc%8c%e6%8e%a5%e4%b8%8a%e8%87%aa%e5%b7%b1%e7%9a%84%e6%95%b0%e6%8d%ae%e6%ba%90\/","title":{"rendered":"\u56db\u6b65\u628aTradingView\u56fe\u8868\u642c\u56de\u7535\u8111\uff0c\u63a5\u4e0a\u81ea\u5df1\u7684\u6570\u636e\u6e90"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4f5c \u8005\uff1a<a href=\"https:\/\/www.laoyulaoyu.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u8001\u4f59\u635e\u9c7c<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-cyan-bluish-gray-color\">\u539f\u521b\u4e0d\u6613\uff0c\u8f6c\u8f7d\u8bf7\u6807\u660e\u51fa\u5904\u53ca\u539f\u4f5c\u8005\u3002<\/mark><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"900\" height=\"383\" src=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/cover-1.jpg\" alt=\"\" class=\"wp-image-4895\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/cover-1.jpg 900w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/cover-1-300x128.jpg 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/cover-1-768x327.jpg 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u6587\u4e2d\u793a\u4f8b\u4ec5\u7528\u4e8e\u6280\u672f\u8ba8\u8bba\uff0c\u4e0d\u6784\u6210\u4efb\u4f55\u64cd\u4f5c\u5efa\u8bae\u3002<br>\u91cf\u5316\u7b56\u7565\u5f00\u53d1\u5e94\u4ee5\u5b66\u4e60\u548c\u6280\u672f\u4ea4\u6d41\u4e3a\u76ee\u7684\u3002<br>\u672c\u53f7\u4e0d\u8350\u80a1\u3001\u4e0d\u5356\u8bfe\u3001\u4e0d\u627f\u8bfa\u6536\u76ca\u3002<br>\u5e02\u573a\u6709\u98ce\u9669\uff0c\u8bf7\u5408\u6cd5\u5408\u89c4\u6295\u8d44\u3002<\/p>\n<\/blockquote>\n\n\n\n<p class=\"has-text-align-left wp-block-paragraph\">\u672c\u6587\u7ea6 4900 \u5b57 | \u9884\u8ba1\u9605\u8bfb 8-12 \u5206\u949f\uff0c\u540e\u6709\u4ee3\u7801\u4e0b\u8f7d\uff0c\u5efa\u8bae\u5148\u6536\u85cf\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\">\u00b7 \u00b7 \u00b7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5de5\u5177\u7528\u4e45\u4e86\uff0c\u8111\u5b50\u91cc\u4f1a\u5192\u51fa\u4e00\u4e2a\u5ff5\u5934\u3002\u6211\u6bcf\u5929\u76ef\u7684\u6570\u636e\u5230\u5e95\u8eba\u5728\u8c01\u7684\u670d\u52a1\u5668\u4e0a\uff0c\u6709\u6ca1\u6709\u53ef\u80fd\u6574\u5957\u642c\u5230\u81ea\u5df1\u7684\u673a\u5668\u91cc\u5934\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u7bc7\u6587\u7ae0\u8bb2\u7684\u5c31\u662f\u8fd9\u4ef6\u4e8b\u3002<strong>TradingView<\/strong>\u00a0\u6709\u53ef\u4ee5\u672c\u5730\u90e8\u7f72\u7684\u56fe\u8868\u5e93\uff0c\u7528 Vue \u8d77\u4e00\u4e2a\u9875\u9762\uff0c\u5c31\u80fd\u5728\u81ea\u5df1\u673a\u5668\u4e0a\u8dd1\u8d77\u4e00\u6574\u5957 K \u7ebf\u56fe\u8868\uff0c\u63a5\u4e0a\u81ea\u5df1\u7684\u6570\u636e\u6e90\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u636e\u4e0d\u5f52\u5b83\u7ba1\u3002K \u7ebf\u4ece\u54ea\u513f\u6765\uff0c\u5b83\u538b\u6839\u4e0d\u5173\u5fc3\u3002\u5b83\u7ba1\u7684\u662f\u56fe\u8868\u3002\u753b\u7ebf\u3001\u7f29\u653e\u3001\u5341\u5b57\u5149\u6807\u3001\u591a\u5468\u671f\u5207\u6362\u3001\u6307\u6807\u53e0\u52a0\uff0c\u8fd9\u4e9b\u6d3b\u5b83\u5168\u5305\u4e86\uff0c\u4f60\u4e00\u884c\u90fd\u4e0d\u7528\u5199\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"537\" src=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/01-what-it-does-1024x537.png\" alt=\"\" class=\"wp-image-4940\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/01-what-it-does-1024x537.png 1024w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/01-what-it-does-300x157.png 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/01-what-it-does-768x403.png 768w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/01-what-it-does-1536x806.png 1536w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/01-what-it-does-2048x1074.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe1\uff1a\u5de6\u8fb9\u90a3\u4e9b\u6d3b\u5b83\u5168\u5305\u4e86\uff0c\u53f3\u8fb9\u90a3\u4e00\u644a\u5f97\u6211\u81ea\u5df1\u63a5\u4e0a<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001\u4e24\u5c42\u4e1c\u897f\uff0c\u4e24\u4e2a\u95e8\u69db<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u628a\u4e24\u5c42\u62c6\u5f00\u8bb2\uff0c\u8fd9\u6837\u4f60\u5f80\u4e0b\u4e00\u8def\u770b\uff0c\u5c31\u77e5\u9053\u6bcf\u4e00\u6b65\u5361\u5728\u54ea\u513f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u5957\u90e8\u7f72\u5176\u5b9e\u662f\u4e24\u5c42\u4e1c\u897f\u53e0\u5728\u4e00\u8d77\u3002\u4e0a\u9762\u4e00\u5c42\u662f\u8d44\u6e90\u548c\u9875\u9762\uff0c\u5165\u53e3\u811a\u672c\u3001bundles\u3001\u6837\u5f0f\u3001\u8bed\u8a00\u5305\u3001\u7c7b\u578b\u58f0\u660e\uff0c\u518d\u52a0\u4e00\u4e2a\u63d0\u4f9b\u5bb9\u5668\u7684\u9875\u9762\u3002\u4e0b\u9762\u4e00\u5c42\u662f\u6570\u636e\uff0c\u5386\u53f2 K \u7ebf\u600e\u4e48\u53d6\u3001\u5b9e\u65f6\u884c\u60c5\u600e\u4e48\u63a8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u90a3\u4e00\u5c42\u7684\u95e8\u69db\u4e0d\u5728\u6280\u672f\uff0c\u5728&nbsp;<strong>TradingView&nbsp;<\/strong>\u6388\u6743\u3002\u5b98\u65b9\u56fe\u8868\u5e93\u4e0d\u516c\u5f00\u5206\u53d1\uff0c\u60f3\u62ff\u5230\u5b8c\u6574\u90a3\u5957\u8d44\u6e90\uff0c\u5f97\u5148\u8fc7\u6388\u6743\u6d41\u7a0b\uff08\u8ba2\u9605\u7528\u6237\u5c31\u80fd\u7528\uff09\u3002\u8fd9\u4e00\u6b65\u8fc7\u4e0d\u53bb\uff0c\u540e\u9762\u5168\u90fd\u514d\u8c08\uff0c\u6240\u4ee5\u5b83\u662f\u6574\u4ef6\u4e8b\u91cc\u6700\u786c\u7684\u4e00\u9053\u95e8\u69db\uff0c\u5f97\u6700\u5148\u786e\u8ba4\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"575\" src=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/02-two-layers-1024x575.png\" alt=\"\" class=\"wp-image-4939\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/02-two-layers-1024x575.png 1024w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/02-two-layers-300x169.png 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/02-two-layers-768x431.png 768w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/02-two-layers-1536x863.png 1536w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/02-two-layers-2048x1151.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe2\uff1a\u4e0a\u9762\u90a3\u5c42\u6302\u7740\u4e00\u628a\u6388\u6743\u7684\u9501\uff0c\u4e0b\u9762\u90a3\u5c42\u624d\u662f\u771f\u6b63\u82b1\u65f6\u95f4\u7684\u5730\u65b9<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u90a3\u4e00\u5c42\u624d\u662f\u5927\u591a\u6570\u4eba\u771f\u6b63\u82b1\u65f6\u95f4\u7684\u5730\u65b9\u3002\u5b9e\u65f6\u884c\u60c5\u600e\u4e48\u843d\u5230\u6b63\u786e\u7684\u90a3\u5f20\u56fe\u4e0a\uff0c\u8f93\u5165\u662f\u4e00\u5305\u6d88\u606f\uff0c\u8f93\u51fa\u662f\u4e00\u6b21\u56de\u8c03\uff0c\u4e2d\u95f4\u9760\u4e00\u5f20\u8ba2\u9605\u8868\u7ef4\u6301\u5173\u7cfb\u3002\u8fd9\u6bb5\u662f\u7eaf JavaScript\uff0c\u8ddf\u56fe\u8868\u5e93\u6ca1\u5173\u7cfb\uff0c\u6362\u4e2a\u9879\u76ee\u539f\u6837\u642c\u8d70\u5c31\u80fd\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\u6211\u628a\u8fd9\u5957\u65b9\u6848\u6574\u7406\u6210\u4e86\u4e0b\u9762\u8fd9\u4efd\u6e05\u5355\u3002\u56db\u6b65\u6bcf\u6b65\u914d\u4e00\u53e5\u9a8c\u6536\u6807\u51c6\uff0c\u6570\u636e\u63a5\u53e3\u7ec6\u5230\u6bcf\u4e2a\u5b57\u6bb5\uff0c\u8ba2\u9605\u5c42\u7ed9\u5b8c\u6574\u5b9e\u73b0\u3002\u6700\u540e\u518d\u628a\u56db\u4e2a\u6700\u5bb9\u6613\u7ffb\u8f66\u7684\u5730\u65b9\u9010\u4e2a\u6807\u51fa\u6765\u3002\u4f60\u7167\u7740\u5f80\u4e0b\u8d70\uff0c\u54ea\u4e00\u6b65\u5bf9\u4e0d\u4e0a\uff0c\u56de\u5934\u770b\u90a3\u53e5\u9a8c\u6536\u6807\u51c6\uff0c\u5c31\u77e5\u9053\u5361\u5728\u54ea\u513f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u56db\u6b65\u88c5\u8d77\u6765<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u5957\u90e8\u7f72\u62c6\u6210\u56db\u6b65\uff0c\u6bcf\u4e00\u6b65\u6211\u90fd\u914d\u4e86\u4e00\u53e5\u9a8c\u6536\u6807\u51c6\u3002\u8fd9\u51e0\u53e5\u8bdd\u6211\u5355\u72ec\u62ce\u51fa\u6765\u8bb2\uff0c\u56e0\u4e3a\u90a3\u5c31\u662f\u4f60\u5224\u65ad\u81ea\u5df1\u505a\u6ca1\u505a\u5bf9\u7684\u5c3a\u5b50\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u7b2c\u4e00\u6b65 \u521d\u59cb\u5316\u524d\u7aef\u9879\u76ee<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9875\u9762\u51fa\u5bb9\u5668\uff0c\u72b6\u6001\u4ea4\u7ed9 Store \u7ba1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bb9\u5668\u5f97\u6709\u660e\u786e\u7684\u5bbd\u9ad8\uff0c\u8fd8\u5f97\u7b49\u9875\u9762\u6302\u8f7d\u5b8c\uff0c\u518d\u53bb\u521d\u59cb\u5316\u56fe\u8868\u3002\u9ed8\u8ba4\u6807\u7684\u4e5f\u5f97\u63d0\u524d\u5907\u597d\uff0c\u4e0d\u7136\u56fe\u8868\u521b\u5efa\u51fa\u6765\u89e3\u6790\u4e0d\u5230\u4ea4\u6613\u5bf9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e00\u6b65\u7684\u5173\u952e\u662f<strong>\u6302\u8f7d<\/strong>\u3002\u9875\u9762\u80fd\u8dd1\u3001\u72b6\u6001\u80fd\u8bfb\u3001\u5bb9\u5668\u5df2\u7ecf\u51fa\u73b0\u5728\u9875\u9762\u4e0a\uff0c\u8fd9\u4e09\u6837\u9f50\u4e86\u624d\u7b97\u8fc7\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2460 \u72b6\u6001\u653e\u5728 Store \u91cc\uff0c\u9875\u9762\u53ea\u8d1f\u8d23\u63d0\u4f9b\u5bb9\u5668<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ store\/chart.js   \u5b58\u9ed8\u8ba4\u6807\u7684\u3001\u5468\u671f\u3001\u4e3b\u9898\nimport { defineStore } from \"pinia\";\n\nexport const useChartStore = defineStore(\"chart\", {\n  state: () => ({\n    symbol: \"BTCUSDT\",\n    resolution: \"1m\",\n  }),\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2461 \u6302\u8f7d\u5b8c\u6210\u4e4b\u540e\u518d\u521b\u5efa\u56fe\u8868\u5b9e\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template>\n  &lt;div ref=\"container\" class=\"chart-container\">&lt;\/div>\n&lt;\/template>\n\n&lt;script setup>\nimport { onMounted, onBeforeUnmount, ref } from \"vue\";\nimport { useChartStore } from \"@\/store\/chart\";\n\nconst container = ref(null);\nconst store = useChartStore();\nlet widget = null;\n\nonMounted(() => {\n  \/\/ \u5bb9\u5668\u5fc5\u987b\u5df2\u7ecf\u6709\u660e\u786e\u7684\u5bbd\u9ad8\uff0c\u56fe\u8868\u624d\u77e5\u9053\u5f80\u54ea\u513f\u753b\n  widget = new TradingView.widget({\n    container: container.value,\n    symbol: store.symbol,\n    interval: store.resolution,\n    library_path: \"\/charting_library\/\",\n    datafeed: new CustomDataFeed(),\n    locale: \"zh\",\n  });\n});\n\nonBeforeUnmount(() => {\n  \/\/ \u9875\u9762\u5378\u8f7d\u65f6\u9500\u6bc1\u5b9e\u4f8b\uff0c\u5426\u5219\u8ba2\u9605\u4f1a\u7559\u5728\u8868\u91cc\n  widget = null;\n});\n&lt;\/script>\n\n&lt;style>\n.chart-container {\n  width: 100%;\n  height: 520px;\n}\n&lt;\/style><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u7b2c\u4e8c\u6b65 \u52a0\u8f7d\u56fe\u8868\u5e93<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u62ff\u5230\u5b98\u65b9\u8d44\u6e90\u4e4b\u540e\uff0c\u6574\u4e2a\u76ee\u5f55\u539f\u6837\u4fdd\u5b58\uff0c\u5165\u53e3\u811a\u672c\u3001bundles\u3001\u6837\u5f0f\u3001\u8bed\u8a00\u5305\u3001\u7c7b\u578b\u58f0\u660e\uff0c\u4e00\u6837\u90fd\u522b\u52a8\u3002\u91cc\u9762\u7684 bundles \u662f\u56fe\u8868\u5e93\u81ea\u5df1\u7ba1\u7684\uff0c\u522b\u91cd\u547d\u540d\uff0c\u4e5f\u522b\u62c6\u5f00\u91cd\u65b0\u7f16\u8bd1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9875\u9762\u8981\u5148\u628a\u5165\u53e3\u811a\u672c\u52a0\u8f7d\u8d77\u6765\uff0c\u811a\u672c\u8dd1\u6210\u529f\u4e4b\u540e\uff0cwindow \u4e0a\u624d\u4f1a\u6302\u51fa\u90a3\u4e2a\u5168\u5c40\u5bf9\u8c61\u3002\u5230\u8fd9\u4e00\u6b65\uff0c\u4f60\u7684\u4e1a\u52a1\u4ee3\u7801\u624d\u80fd\u521b\u5efa\u56fe\u8868\u5b9e\u4f8b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2462 \u5148\u52a0\u8f7d\u5165\u53e3\u811a\u672c\uff0c\u518d\u521b\u5efa\u5b9e\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script src=\"\/charting_library\/standalone.js\">&lt;\/script>\n&lt;script>\n  \/\/ \u5148\u52a0\u8f7d\u5165\u53e3\u811a\u672c\uff08standalone.js\uff09\uff0c\u8dd1\u5b8c window \u4e0a\u624d\u6709 TradingView \u8fd9\u4e2a\u5168\u5c40\u5bf9\u8c61\n  \/\/ \u987a\u5e8f\u53cd\u4e86\u4f1a\u62a5 TradingView is not defined\n  const widget = new TradingView.widget({\n    container: document.getElementById(\"chart\"),\n    library_path: \"\/charting_library\/\",\n    datafeed: new CustomDataFeed(),\n  });\n&lt;\/script><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u914d\u7f6e\u91cc\u7684 library_path \u6307\u5411\u6574\u5957\u8d44\u6e90\u7684\u8bbf\u95ee\u76ee\u5f55\u3002\u56fe\u8868\u540e\u9762\u8fd8\u8981\u4ece\u8fd9\u4e2a\u76ee\u5f55\u53bb\u53d6\u5185\u90e8\u811a\u672c\u548c\u6837\u5f0f\uff0c\u6240\u4ee5\u5165\u53e3\u6587\u4ef6\u80fd\u6253\u5f00\uff0c\u4e0d\u4ee3\u8868\u6240\u6709\u8d44\u6e90\u90fd\u5230\u4f4d\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e00\u6b65\u7684\u5173\u952e\u662f<strong>\u5b8c\u6574<\/strong>\u3002\u8d44\u6e90\u5168\u90fd\u80fd\u52a0\u8f7d\u4e0a\uff0c\u63a7\u5236\u53f0\u91cc\u65e2\u6ca1\u6709 TradingView is not defined\uff0c\u4e5f\u6ca1\u6709 404\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u7b2c\u4e09\u6b65 \u5bf9\u63a5\u6570\u636e\u6e90<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u4e00\u4e2a CustomDataFeed\uff0c\u585e\u8fdb\u56fe\u8868\u7684 datafeed \u53c2\u6570\u91cc\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6709\u4e2a\u65b9\u5411\u8981\u7559\u795e\uff0c\u662f\u56fe\u8868\u4e3b\u52a8\u6765\u8c03\u4f60\u7684\u63a5\u53e3\uff0c\u4e0d\u662f\u4f60\u5f80\u56fe\u8868\u91cc\u786c\u585e\u6570\u636e\u3002\u65b9\u5411\u641e\u53cd\u4e86\uff0c\u540e\u9762\u4f1a\u5168\u4e71\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"463\" src=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/03-data-direction-1024x463.png\" alt=\"\" class=\"wp-image-4938\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/03-data-direction-1024x463.png 1024w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/03-data-direction-300x136.png 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/03-data-direction-768x347.png 768w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/03-data-direction-1536x694.png 1536w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/03-data-direction-2048x925.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe3\uff1a\u662f\u5b83\u6765\u6572\u95e8\u95ee\u4f60\u8981\uff0c\u4e0d\u662f\u4f60\u62b1\u7740\u6570\u636e\u5f80\u91cc\u585e<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e09\u4e2a\u65b9\u6cd5\u5404\u6709\u5404\u7684\u5206\u5de5\u3002onReady \u58f0\u660e\u4f60\u652f\u6301\u54ea\u4e9b\u5468\u671f\uff0cresolveSymbol \u4ea4\u4ee3\u4ea4\u6613\u65f6\u6bb5\u3001\u65f6\u533a\uff0c\u8fd8\u6709\u4ef7\u683c\u7cbe\u5ea6\uff0cgetBars \u6309\u6807\u7684\u3001\u5468\u671f\uff0c\u8fd8\u6709\u8d77\u6b62\u65f6\u95f4\u53d6\u5386\u53f2\u6570\u636e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u636e\u56de\u6765\u4e4b\u540e\u7edf\u4e00\u8f6c\u6210\u516d\u4e2a\u5b57\u6bb5\uff0c\u65f6\u95f4\u3001\u5f00\u76d8\u3001\u6700\u9ad8\u3001\u6700\u4f4e\u3001\u6536\u76d8\u3001\u6210\u4ea4\u91cf\u3002\u65f6\u95f4\u7528\u6beb\u79d2\u65f6\u95f4\u6233\uff0c\u4e0d\u662f\u79d2\u3002\u6570\u636e\u6309\u65f6\u95f4\u5347\u5e8f\u6392\u597d\uff0c\u518d\u7528 onHistoryCallback \u4ea4\u56de\u53bb\u3002\u8fd9\u516d\u4e2a\u5b57\u6bb5\u7684\u5f62\u72b6\uff0c\u5386\u53f2\u6570\u636e\u548c\u5b9e\u65f6\u884c\u60c5\u5fc5\u987b\u4e00\u6a21\u4e00\u6837\uff0c\u4e0d\u7136\u56fe\u8868\u4f1a\u628a\u4e24\u8fb9\u5f53\u6210\u4e24\u62e8\u4e1c\u897f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2463 \u4e09\u4e2a\u65b9\u6cd5\u5404\u7ba1\u4e00\u6bb5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class CustomDataFeed {\n  \/\/ \u58f0\u660e\u652f\u6301\u54ea\u4e9b\u5468\u671f\n  onReady(callback) {\n    setTimeout(() => {\n      callback({ supported_resolutions: &#91;\"1\", \"5\", \"15\", \"60\", \"1D\"] });\n    }, 0);\n  }\n\n  \/\/ \u4ea4\u4ee3\u4ea4\u6613\u65f6\u6bb5\u3001\u65f6\u533a\u3001\u4ef7\u683c\u7cbe\u5ea6\n  resolveSymbol(symbolName, onResolve, onError) {\n    onResolve({\n      name: symbolName,\n      session: \"24x7\",\n      timezone: \"Asia\/Shanghai\",\n      minmov: 1,\n      pricescale: 100,\n      has_intraday: true,\n    });\n  }\n\n  \/\/ \u6309\u6807\u7684\u3001\u5468\u671f\u3001\u8d77\u6b62\u65f6\u95f4\u53d6\u5386\u53f2 K \u7ebf\n  async getBars(symbolInfo, resolution, periodParams, onHistoryCallback, onError) {\n    \/\/ \u56fe\u8868\u7ed9\u8fc7\u6765\u7684 from \/ to \u662f\u79d2\uff0c\u5148\u8f6c\u6beb\u79d2\uff0c\u4e24\u5957\u5355\u4f4d\u5404\u7ba1\u4e00\u6bb5\uff0c\u522b\u6df7\u7740\u7528\n    const fromMs = periodParams.from * 1000;\n    const toMs = periodParams.to * 1000;\n\n    const rows = await fetchKline(symbolInfo.name, resolution, fromMs, toMs);\n\n    const bars = rows.map((r) => ({\n      time: Number(r.time),   \/\/ \u6beb\u79d2\u65f6\u95f4\u6233\uff0c\u4e0d\u662f\u79d2\n      open: Number(r.open),\n      high: Number(r.high),\n      low: Number(r.low),\n      close: Number(r.close),\n      volume: Number(r.volume),\n    }));\n\n    onHistoryCallback(bars, { noData: bars.length === 0 });\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e00\u6b65\u7684\u5173\u952e\u662f<strong>\u683c\u5f0f<\/strong>\u3002\u9996\u5c4f\u80fd\u770b\u5230\u5386\u53f2 K \u7ebf\uff0c\u5207\u6807\u7684\u3001\u5207\u5468\u671f\u3001\u5f80\u5de6\u6eda\u52a8\u7684\u65f6\u5019\u8fd8\u80fd\u7ee7\u7eed\u53d6\u5230\u6570\u636e\uff0c\u5c31\u7b97\u8fc7\u4e86\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u7b2c\u56db\u6b65 \u8865\u4e0a\u5b9e\u65f6\u884c\u60c5<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5386\u53f2\u663e\u793a\u51fa\u6765\u4e4b\u540e\uff0c\u56fe\u8868\u4f1a\u81ea\u5df1\u6765\u8c03 subscribeBars\u3002\u8fd9\u4e2a\u65f6\u5019\uff0c\u4f60\u628a\u6807\u7684\u3001\u5468\u671f\u3001\u8ba2\u9605\u8005\u7f16\u53f7\uff0c\u4ee5\u53ca\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\u4ea4\u7ed9 WebSocket \u90a3\u5c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6536\u5230\u5b9e\u65f6\u6d88\u606f\uff0c\u8f6c\u6210\u8ddf\u5386\u53f2\u4e00\u81f4\u7684\u683c\u5f0f\u3002\u65f6\u95f4\u8ddf\u6700\u540e\u4e00\u6839 K \u7ebf\u76f8\u540c\uff0c\u5c31\u66f4\u65b0\u8fd9\u4e00\u6839\u3002\u65f6\u95f4\u8fdb\u5165\u65b0\u5468\u671f\uff0c\u5c31\u8ffd\u52a0\u4e00\u6839\u65b0\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u4e00\u6761\u8fde\u63a5\u53ef\u4ee5\u627f\u8f7d\u591a\u4e2a\u6807\u7684\u548c\u5468\u671f\uff0c\u6240\u4ee5\u8981\u9760\u8ba2\u9605\u8868\u6309\u9891\u9053\u8bb0\u6e05\u695a\u8c01\u5728\u542c\u3002\u5207\u6807\u7684\u6216\u5468\u671f\u7684\u65f6\u5019\u628a\u65e7\u8ba2\u9605\u5220\u6389\uff0c\u9875\u9762\u5378\u8f7d\u7684\u65f6\u5019\u9500\u6bc1\u56fe\u8868\u5b9e\u4f8b\u3002\u771f\u8981\u4e0a\u7ebf\uff0c\u65ad\u7ebf\u91cd\u8fde\u3001\u5fc3\u8df3\u3001\u5f02\u5e38\u6d88\u606f\u3001\u8ba2\u9605\u6062\u590d\u8fd9\u4e9b\u6d3b\u4e5f\u90fd\u8eb2\u4e0d\u6389\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2464 \u56fe\u8868\u628a\u5b9e\u65f6\u8ba2\u9605\u4ea4\u51fa\u6765\uff0c\u5269\u4e0b\u7684\u7531\u8ba2\u9605\u5c42\u63a5\u7ba1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u56fe\u8868\u628a\u5b9e\u65f6\u8ba2\u9605\u4ea4\u51fa\u6765\uff0c\u5269\u4e0b\u7684\u7531\u8ba2\u9605\u5c42\u63a5\u7ba1\nsubscribeBars(symbolInfo, resolution, onRealtimeCallback, subscriberUID, onResetCacheNeededCallback) {\n  socket.subscribeOnStream(\n    symbolInfo,\n    resolution,\n    onRealtimeCallback,\n    subscriberUID,\n    onResetCacheNeededCallback,\n    null\n  );\n}\n\nunsubscribeBars(subscriberUID) {\n  socket.unsubscribeFromStream(subscriberUID);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e00\u6b65\u7684\u5173\u952e\u662f<strong>\u8ba2\u9605<\/strong>\u3002\u5386\u53f2\u548c\u5b9e\u65f6\u80fd\u63a5\u4e0a\uff0c\u5207\u9891\u9053\u7684\u65f6\u5019\u65e7\u8ba2\u9605\u88ab\u6e05\u5e72\u51c0\uff0c\u5f53\u524d\u8fd9\u6839\u4e00\u76f4\u5728\u52a8\uff0c\u5c31\u5bf9\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56db\u6b65\u8d70\u5b8c\uff0c\u4e00\u5957\u80fd\u770b\u80fd\u52a8\u7684\u672c\u5730 K \u7ebf\u5c31\u6210\u5f62\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u662f\u6d41\u7a0b\u90e8\u5206\uff0c\u7167\u7740\u505a\u5c31\u80fd\u8dd1\u8d77\u6765\u3002\u5f80\u4e0b\u662f\u52a8\u624b\u90e8\u5206\uff0c\u8bb2\u90a3\u5f20\u8ba2\u9605\u8868\u5230\u5e95\u600e\u4e48\u5de5\u4f5c\u3001\u4ee3\u7801\u600e\u4e48\u5199\uff0c\u8fd8\u6709\u56db\u4e2a\u6700\u5bb9\u6613\u7ffb\u8f66\u7684\u5730\u65b9\u3002\u4e0d\u5173\u5fc3\u4ee3\u7801\u7684\u8bdd\uff0c\u7b2c\u4e94\u8282\u548c\u7b2c\u4e03\u8282\u7684\u7ed3\u8bba\u53ef\u4ee5\u76f4\u63a5\u770b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u56db\u3001\u4e00\u5f20\u8ba2\u9605\u8868\uff0c\u7ba1\u7740\u4e09\u4ef6\u4e8b<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u8bf4 PubSub \u8fd9\u4e2a\u8bcd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5168\u540d\u662f\u53d1\u5e03\u8ba2\u9605\u3002\u4f60\u53ef\u4ee5\u60f3\u6210\u5e7f\u64ad\u7535\u53f0\uff0c\u53d1\u6d88\u606f\u7684\u4eba\u53ea\u7ba1\u5f80\u67d0\u4e2a\u9891\u9053\u4e22\uff0c\u542c\u7684\u4eba\u53ea\u7ba1\u5b88\u7740\u81ea\u5df1\u5173\u5fc3\u7684\u90a3\u4e2a\u9891\u9053\uff0c\u4e24\u8fb9\u4e0d\u7528\u8ba4\u8bc6\u5f7c\u6b64\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u843d\u5230 K \u7ebf\u8fd9\u4e2a\u573a\u666f\u91cc\uff0c\u6807\u7684\u52a0\u5468\u671f\u62fc\u8d77\u6765\u5c31\u662f\u9891\u9053\u540d\u3002\u4e00\u5206\u949f\u5468\u671f\u7684 BTC \u5bf9 USDT\uff0c\u9891\u9053\u540d\u5c31\u662f btcusdt@kline_1m\u3002WebSocket \u6536\u5230\u884c\u60c5\u7684\u65f6\u5019\u662f\u53d1\u7684\u4eba\uff0c\u56fe\u8868\u7ed9\u8fc7\u6765\u7684\u56de\u8c03\u662f\u542c\u7684\u4eba\uff0c\u8ba2\u9605\u8868\u8bb0\u7684\u5c31\u662f\u8c01\u5728\u542c\u54ea\u4e2a\u9891\u9053\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a0\u8fd9\u5f20\u8868\uff0c\u4e3a\u7684\u662f\u628a\u4e24\u8fb9\u89e3\u8026\u3002WebSocket \u4e0d\u9700\u8981\u77e5\u9053\u9875\u9762\u4e0a\u6709\u51e0\u5f20\u56fe\uff0c\u56fe\u8868\u4e5f\u4e0d\u9700\u8981\u61c2\u5e95\u5c42\u7684\u6d88\u606f\u534f\u8bae\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u89d2\u8272<\/th><th>\u5bf9\u5e94\u5b9e\u73b0<\/th><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">\u9891\u9053<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u6807\u7684\u52a0\u5468\u671f\u62fc\u6210\u7684\u5b57\u7b26\u4e32<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">\u8ba2\u9605\u8868<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u4e00\u4e2a Map<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">\u542c\u4f17<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u56fe\u8868\u7ed9\u7684\u56de\u8c03\u51fd\u6570<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">\u6d88\u606f<\/td><td class=\"has-text-align-center\" data-align=\"center\">WebSocket \u6536\u5230\u7684\u90a3\u4e00\u5305<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u90a3\u4e3a\u4ec0\u4e48\u975e\u8981\u5728\u4e2d\u95f4\u52a0\u8fd9\u4e00\u5c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u76f4\u63a5\u5728 WebSocket \u7684\u6d88\u606f\u56de\u8c03\u91cc\u5199\u56fe\u8868\u66f4\u65b0\u903b\u8f91\uff0c\u53ea\u6709\u4e00\u5f20\u56fe\u7684\u65f6\u5019\u4e5f\u8dd1\u5f97\u8d77\u6765\u3002\u56fe\u4e00\u591a\u5c31\u4e71\u4e86\uff0c\u56de\u8c03\u548c\u8fde\u63a5\u7684\u5173\u7cfb\u7f20\u6210\u4e00\u56e2\uff0c\u53d6\u6d88\u8ba2\u9605\u7684\u65f6\u5019\u4f60\u90fd\u4e0d\u77e5\u9053\u8be5\u5173\u54ea\u4e00\u4e2a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e2d\u95f4\u52a0\u4e00\u5c42\u8868\u4e4b\u540e\uff0c\u597d\u5904\u662f\u4e09\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8fde\u63a5\u66f4\u5c11<\/strong>\u3002\u540c\u4e00\u4e2a\u9891\u9053\u53ea\u5efa\u4e00\u6b21\u8fdc\u7aef\u8ba2\u9605\uff0c\u672c\u5730\u518d\u628a\u540c\u4e00\u6761\u884c\u60c5\u5206\u53d1\u7ed9\u6240\u6709\u9700\u8981\u7684\u56fe\u8868\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5207\u6362\u66f4\u7a33<\/strong>\u3002\u6bcf\u4e2a\u542c\u4f17\u5e26\u4e00\u4e2a\u8ba2\u9605\u8005\u7f16\u53f7\uff0c\u53d6\u6d88\u7684\u65f6\u5019\u6309\u7f16\u53f7\u7cbe\u786e\u5220\u9664\uff0c\u4e0d\u4f1a\u8bef\u4f24\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u804c\u8d23\u66f4\u6e05\u695a<\/strong>\u3002WebSocket \u7ba1\u6536\u53d1\uff0c\u8ba2\u9605\u8868\u7ba1\u5173\u7cfb\uff0c\u56fe\u8868\u7ba1\u6e32\u67d3\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8868\u672c\u8eab\u5f88\u7b80\u5355\uff0c\u4e24\u4e2a\u7c7b\u578b\u5b9a\u4e49\u5c31\u88c5\u4e0b\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2465 \u4e00\u5f20\u8868\uff0c\u4e24\u4e2a\u7c7b\u578b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4e00\u4e2a\u542c\u4f17\uff0cid \u662f\u56fe\u8868\u7ed9\u7684\u8ba2\u9605\u8005\u7f16\u53f7\uff0c\u7528\u6765\u7cbe\u786e\u5220\u9664\ntype Handler = {\n  id: string;\n  callback: (bar: any) => void;\n};\n\n\/\/ \u4e00\u4e2a\u9891\u9053\uff0chandlers \u91cc\u88c5\u7740\u6240\u6709\u5728\u542c\u5b83\u7684\u542c\u4f17\ntype Subscription = {\n  lastBar: any;\n  handlers: Handler&#91;];\n};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u770b\u8ba2\u9605\u3002\u8fd9\u6bb5\u4ee3\u7801\u4e00\u5171\u5341\u51e0\u884c\uff0c\u8981\u7d27\u7684\u5c31\u5728\u4e2d\u95f4\u90a3\u4e2a\u5224\u65ad\u4e0a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2466 \u9891\u9053\u5df2\u5b58\u5728\u65f6\uff0c\u672c\u5730\u52a0\u4eba\uff0c\u8fdc\u7aef\u4e0d\u52a0\u6307\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>subscribeOnStream(symbolInfo, resolution, callback, subscriberUID, onResetCache, lastBar) {\n  const topic = this.getTopic(symbolInfo.name, resolution);\n  const current = this.channelToSubscription.get(topic);\n\n  \/\/ \u9891\u9053\u5df2\u7ecf\u6709\u4eba\u8ba2\u8fc7\uff0c\u672c\u5730\u52a0\u4e2a\u542c\u4f17\u5c31\u884c\uff0c\u4e0d\u7528\u518d\u901a\u77e5\u670d\u52a1\u7aef\n  if (current) {\n    current.handlers.push({ id: subscriberUID, callback });\n    return;\n  }\n\n  \/\/ \u65b0\u9891\u9053\uff0c\u5efa\u8bb0\u5f55\uff0c\u7136\u540e\u624d\u53d1\u8ba2\u9605\u6307\u4ee4\n  this.channelToSubscription.set(topic, {\n    lastBar,\n    handlers: &#91;{ id: subscriberUID, callback }],\n  });\n  this.emit(\"SUBSCRIBE\", &#91;topic]);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\u90a3\u4e2a\u63d0\u524d\u8fd4\u56de\u3002\u9891\u9053\u6709\u4eba\u8ba2\u8fc7\u7684\u65f6\u5019\uff0c\u4ee3\u7801\u76f4\u63a5 return\uff0c\u8fdc\u7aef\u4e00\u6761\u6307\u4ee4\u90fd\u4e0d\u53d1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u300c\u4e24\u4e2a\u56fe\u8868\u5171\u7528\u4e00\u6761\u8fde\u63a5\u300d\u5c31\u662f\u5728\u8fd9\u513f\u53d1\u751f\u7684\u3002\u7b2c\u4e8c\u5f20\u56fe\u8ba2\u9605\u7684\u65f6\u5019\u8d70\u8fdb\u4e0a\u9762\u90a3\u4e2a\u5206\u652f\uff0c\u672c\u5730\u542c\u4f17\u4ece 1 \u4e2a\u53d8\u6210 2 \u4e2a\uff0c\u8fdc\u7aef\u5b8c\u5168\u4e0d\u77e5\u9053\u591a\u4e86\u4e2a\u4eba\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"585\" src=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-1-share-1024x585.png\" alt=\"\" class=\"wp-image-4937\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-1-share-1024x585.png 1024w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-1-share-300x171.png 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-1-share-768x439.png 768w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-1-share.png 1344w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe4\uff1a\u4e24\u5f20\u56fe\u6307\u5411\u8ba2\u9605\u8868\u7684\u540c\u4e00\u6761\u8bb0\u5f55\uff0c\u6700\u540e\u5f52\u5230\u4e00\u6761\u8fde\u63a5\u4e0a<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u770b\u6d88\u606f\u8fdb\u6765\u4e4b\u540e\u662f\u600e\u4e48\u5206\u53d1\u4e0b\u53bb\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2467 \u8fd8\u539f\u9891\u9053\u540d\uff0c\u518d\u5206\u53d1\u7ed9\u6240\u6709\u542c\u4f17<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>publish(rawData) {\n  const message = JSON.parse(rawData);\n\n  \/\/ \u5173\u952e\u4e00\u6b65\uff0c\u8fd9\u91cc\u5fc5\u987b\u8ddf\u8ba2\u9605\u7aef\u7528\u540c\u4e00\u5957\u9891\u9053\u540d\u89c4\u5219\n  const topic = this.getTopic(message.symbol, message.resolution);\n  const item = this.channelToSubscription.get(topic);\n  if (!item) return;\n\n  const bar = {\n    time: Number(message.time),\n    open: Number(message.open),\n    high: Number(message.high),\n    low: Number(message.low),\n    close: Number(message.close),\n    volume: Number(message.volume),\n  };\n  item.lastBar = bar;\n\n  \/\/ \u540c\u4e00\u4e2a\u9891\u9053\u7684\u6240\u6709\u542c\u4f17\uff0c\u5404\u6536\u5230\u4e00\u6b21\n  item.handlers.forEach((handler) => handler.callback(bar));\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6709\u4e24\u884c\u662f\u5173\u952e\u3002\u4e0a\u9762\u90a3\u884c getTopic \u662f\u7b2c\u4e00\u4e2a\u5751\u7684\u5165\u53e3\uff0c\u4e0b\u9762\u90a3\u4e2a forEach \u5c31\u662f\u5206\u53d1\u52a8\u4f5c\u672c\u8eab\uff0c\u4e00\u6761\u884c\u60c5\u8fdb\u6765\uff0c\u4e24\u4e2a\u542c\u4f17\u5404\u6536\u5230\u4e00\u6b21\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u662f\u53d6\u6d88\u8ba2\u9605\u3002\u8fd9\u4e00\u6bb5\u7684\u65f6\u673a\u6bd4\u52a8\u4f5c\u672c\u8eab\u91cd\u8981\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2468 \u672c\u5730\u5220\u4eba\u548c\u8fdc\u7aef\u9000\u8ba2\uff0c\u662f\u4e24\u4ef6\u4e8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>unsubscribeFromStream(subscriberUID) {\n  for (const &#91;topic, item] of this.channelToSubscription) {\n    item.handlers = item.handlers.filter((h) => h.id !== subscriberUID);\n\n    \/\/ \u9891\u9053\u7a7a\u4e86\uff0c\u624d\u901a\u77e5\u670d\u52a1\u7aef\u9000\u8ba2\n    if (!item.handlers.length) {\n      this.emit(\"UNSUBSCRIBE\", &#91;topic]);\n      this.channelToSubscription.delete(topic);\n    }\n  }\n}\n\ngetTopic(symbol, resolution) {\n  \/\/ \u5168\u5c40\u552f\u4e00\u7684\u4e00\u5957\u9891\u9053\u540d\u89c4\u5219\uff0c\u8ba2\u9605\u548c\u63a5\u6536\u90fd\u8d70\u8fd9\u91cc\n  return symbol.toLowerCase() + \"@kline_\" + resolution;\n}\n\nemit(method, topics) {\n  if (this.socket.readyState !== WebSocket.OPEN) return;\n  this.socket.send(JSON.stringify({ method, topics }));\n}this.socket.send(JSON.stringify({ method, topics }));}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53d6\u6d88\u8ba2\u9605\u7684\u52a8\u4f5c\u662f\u5220\u672c\u5730\u5217\u8868\uff0c\u901a\u77e5\u670d\u52a1\u7aef\u662f\u53e6\u4e00\u4ef6\u4e8b\uff0c\u5f97\u7b49\u5217\u8868\u7a7a\u4e86\u624d\u505a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6bb5\u903b\u8f91\u8dd1\u8d77\u6765\u53ea\u6709\u4e09\u79cd\u72b6\u6001\u3002\u4e24\u5f20\u56fe\u8868\u90fd\u5f00\u7740\u7684\u65f6\u5019\uff0c\u672c\u5730 2 \u4e2a\u542c\u4f17\uff0c\u8fdc\u7aef\u8ba2\u9605\u6307\u4ee4 1 \u6761\u3002\u5173\u6389\u7b2c\u4e00\u5f20\uff0c\u672c\u5730\u51cf\u5230 1 \u4e2a\uff0c\u8fdc\u7aef\u4e00\u6761\u6307\u4ee4\u90fd\u4e0d\u53d1\u3002\u5173\u6389\u7b2c\u4e8c\u5f20\uff0c\u672c\u5730\u5f52\u96f6\uff0c\u8fdc\u7aef\u624d\u6536\u5230\u90a3 1 \u6761\u9000\u8ba2\uff0c\u9891\u9053\u4ece\u8868\u91cc\u5220\u6389\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"585\" src=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-2-unsub-1024x585.png\" alt=\"\" class=\"wp-image-4936\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-2-unsub-1024x585.png 1024w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-2-unsub-300x171.png 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-2-unsub-768x439.png 768w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-2-unsub.png 1344w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe5\uff1a\u672c\u5730\u542c\u4f17\u4ece 2 \u51cf\u5230 0\uff0c\u9000\u8ba2\u6307\u4ee4\u8981\u7b49\u6700\u540e\u4e00\u6b65\u624d\u53d1\u51fa\u53bb<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5dee\u4e00\u62cd\u5c31\u5dee\u5728\u8fd9\u513f\u3002\u8fdc\u7aef\u8ba2\u9605\u7684\u751f\u6b7b\uff0c\u770b\u7684\u662f\u672c\u5730\u542c\u4f17\u6570\u91cf\uff0c\u4e0d\u662f\u56fe\u8868\u6570\u91cf\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u56db\u4e2a\u6700\u5bb9\u6613\u7ffb\u8f66\u7684\u5730\u65b9<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u9762\u56db\u6b65\u8d70\u987a\u4e86\uff0c\u56fe\u4e5f\u51fa\u6765\u4e86\uff0c\u8fd9\u65f6\u5019\u6700\u5bb9\u6613\u51fa\u5c94\u5b50\u7684\u53cd\u800c\u662f\u7ec6\u8282\u3002\u4e0b\u9762\u56db\u4e2a\uff0c\u524d\u4e24\u4e2a\u5728\u8ba2\u9605\u5c42\uff0c\u540e\u4e24\u4e2a\u5728\u6570\u636e\u548c\u8d44\u6e90\u4e0a\u3002\u5b83\u4eec\u7684\u5171\u540c\u70b9\u662f\u90fd\u4e0d\u592a\u50cf bug\uff0c\u66f4\u50cf\u7384\u5b66\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e00\u4e2a\u5751\uff0c\u9891\u9053\u540d\u5c11\u505a\u4e00\u6b21\u5f52\u4e00\u5316<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9891\u9053\u540d\u662f\u62fc\u51fa\u6765\u7684\u3002\u8ba2\u9605\u7684\u65f6\u5019\u8d70 getTopic\uff0c\u91cc\u9762\u6709\u4e00\u53e5 toLowerCase\uff0c\u4f1a\u628a\u6807\u7684\u8f6c\u6210\u5c0f\u5199\uff0c\u62fc\u51fa\u6765\u662f btcusdt@kline_1m\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u95ee\u9898\u51fa\u5728\u6d88\u606f\u7aef\u3002\u8981\u662f\u90a3\u4e00\u6bb5\u4ee3\u7801\u56fe\u7701\u4e8b\uff0c\u76f4\u63a5\u62ff\u6d88\u606f\u91cc\u7684 symbol \u62fc\u9891\u9053\u540d\uff0c\u6ca1\u8d70\u7edf\u4e00\u7684\u90a3\u4e2a\u51fd\u6570\uff0c\u62fc\u51fa\u6765\u5c31\u662f BTCUSDT@kline_1m\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e24\u4e2a\u5b57\u7b26\u4e32\u957f\u5f97\u51e0\u4e4e\u4e00\u6a21\u4e00\u6837\uff0c\u5c31\u5dee\u4e2a\u5927\u5c0f\u5199\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u987a\u7740\u8fd9\u6761\u8def\u5f84\u5f80\u4e0b\u8d70\u4e00\u904d\u5c31\u6e05\u695a\u4e86\u3002\u8ba2\u9605\u8868\u91cc\u67e5\u51fa\u6765\u662f\u7a7a\uff0c\u4ee3\u7801\u8d70\u5230 if (!item) return \u90a3\u4e00\u884c\uff0c\u76f4\u63a5\u8fd4\u56de\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u629b\u5f02\u5e38\u3002\u4e0d\u6253\u65e5\u5fd7\u3002\u63a7\u5236\u53f0\u5e72\u5e72\u51c0\u51c0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u628a\u4e24\u79cd\u5199\u6cd5\u5e76\u6392\u770b\uff0c\u540c\u4e00\u6839\u884c\u60c5\u63a8\u8fdb\u6765\uff0c\u8d70\u5f52\u4e00\u5316\u7684\u90a3\u79cd\u56fe\u8868\u66f4\u65b0 1 \u6839 K \u7ebf\uff0c\u4e0d\u8d70\u5f52\u4e00\u5316\u7684\u66f4\u65b0 0 \u6839\u3002\u800c\u4f60\u5750\u5728\u5c4f\u5e55\u524d\u770b\u5230\u7684\u753b\u9762\u662f\uff0c\u56fe\u8868\u52a0\u8f7d\u4e86\uff0c\u5386\u53f2 K \u7ebf\u4e5f\u5728\uff0c\u5c31\u662f\u4e0d\u52a8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6392\u67e5\u8fd9\u7c7b\u95ee\u9898\u6700\u8d39\u65f6\u95f4\u7684\u5730\u65b9\u5c31\u5728\u8fd9\u513f\u3002\u4f60\u4e0d\u7f3a\u62a5\u9519\uff0c\u4f60\u7f3a\u7684\u662f\u4e00\u6761\u7ebf\u7d22\u3002\u5386\u53f2\u80fd\u663e\u793a\uff0c\u8bf4\u660e\u63a5\u53e3\u662f\u901a\u7684\u3002\u56fe\u4e0a\u4e0d\u52a8\uff0c\u8bf4\u660e\u5b9e\u65f6\u90a3\u4e00\u6bb5\u65ad\u4e86\u3002\u53ef\u4ee3\u7801\u4e00\u53e5\u8bdd\u90fd\u4e0d\u4f1a\u544a\u8bc9\u4f60\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540e\u6765\u6211\u7ed9\u81ea\u5df1\u7acb\u4e86\u4e00\u6761\u786c\u89c4\u77e9\u3002\u9891\u9053\u540d\u53ea\u51c6\u4ece getTopic \u8fd9\u4e00\u4e2a\u51fd\u6570\u91cc\u51fa\u6765\uff0c\u8c01\u90fd\u4e0d\u8bb8\u81ea\u5df1\u62fc\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e8c\u4e2a\u5751\uff0c\u5207\u6362\u5468\u671f\u65f6\u8ba2\u9605\u8005\u7f16\u53f7\u590d\u7528<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba2\u9605\u8005\u7f16\u53f7\u662f\u56fe\u8868\u7ed9\u7684\uff0c\u6bcf\u6b21\u8ba2\u9605\u90fd\u5e26\u4e00\u4e2a\u3002\u53d6\u6d88\u8ba2\u9605\u7684\u65f6\u5019\uff0c\u4ee3\u7801\u662f\u6309\u7f16\u53f7\u5728\u5168\u8868\u91cc\u8fc7\u6ee4\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbe\u60f3\u4e00\u4e2a\u52a8\u4f5c\uff0c\u4f60\u628a\u56fe\u8868\u4ece\u4e00\u5206\u949f\u5207\u5230\u4e94\u5206\u949f\u3002\u56fe\u8868\u90a3\u8fb9\u901a\u5e38\u4f1a\u5148\u9000\u8ba2\u65e7\u7684\uff0c\u518d\u8ba2\u9605\u65b0\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u662f\u5b9e\u73b0\u91cc\u8fd9\u4e24\u6b65\u7684\u987a\u5e8f\u88ab\u5f04\u53cd\u4e86\uff0c\u5148\u8ba2\u9605\u65b0\u7684\u518d\u9000\u8ba2\u65e7\u7684\uff0c\u540c\u65f6\u65b0\u8ba2\u9605\u53c8\u590d\u7528\u4e86\u540c\u4e00\u4e2a\u7f16\u53f7\uff0c\u9ebb\u70e6\u5c31\u6765\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9000\u8ba2\u90a3\u4e00\u884c\u662f\u6309\u7f16\u53f7\u8fc7\u6ee4\u7684\uff0c\u5b83\u4e0d\u533a\u5206\u9891\u9053\u3002\u521a\u5efa\u7acb\u8d77\u6765\u7684\u4e94\u5206\u949f\u8ba2\u9605\uff0c\u7f16\u53f7\u8ddf\u6b63\u5728\u9000\u8ba2\u7684\u4e00\u5206\u949f\u4e00\u6a21\u4e00\u6837\uff0c\u4e8e\u662f\u88ab\u4e00\u8d77\u5e26\u8d70\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u987a\u7740\u8fd9\u6761\u8def\u5f84\u8d70\u4e00\u904d\uff0c\u9000\u8ba2\u6307\u4ee4\u4f1a\u53d1\u51fa 2 \u6761\uff0c\u8ba2\u9605\u8868\u91cc\u4e00\u4e2a\u9891\u9053\u90fd\u4e0d\u5269\u3002\u5207\u5b8c\u5468\u671f\u4e4b\u540e\uff0c\u4e94\u5206\u949f\u8fd9\u6839 K \u7ebf\u518d\u4e5f\u6536\u4e0d\u5230\u884c\u60c5\uff0c\u56de\u8c03\u89e6\u53d1 0 \u6b21\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u5751\u6bd4\u7b2c\u4e00\u4e2a\u66f4\u9690\u853d\u3002\u7b2c\u4e00\u4e2a\u5751\u662f\u6d88\u606f\u4e22\u4e86\u4f46\u8868\u8fd8\u5728\uff0c\u7b2c\u4e8c\u4e2a\u5751\u662f\u8868\u88ab\u6e05\u5e72\u51c0\u4e86\uff0c\u4f60\u53bb\u7ffb\u8868\uff0c\u4ec0\u4e48\u90fd\u770b\u4e0d\u51fa\u6765\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"585\" src=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-3-traps-1024x585.png\" alt=\"\" class=\"wp-image-4935\" srcset=\"https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-3-traps-1024x585.png 1024w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-3-traps-300x171.png 300w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-3-traps-768x439.png 768w, https:\/\/laoyulaoyu.com\/wp-content\/uploads\/2026\/09\/chart-3-traps.png 1344w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\u56fe6\uff1a\u540c\u4e00\u6839\u884c\u60c5\u63a8\u8fdb\u6765\uff0c\u56db\u79cd\u5199\u6cd5\u4e0b\u56fe\u8868\u5b9e\u9645\u80fd\u66f4\u65b0\u5230\u51e0\u6839 K \u7ebf<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e09\u4e2a\u5751\uff0c\u8fdb\u6765\u662f\u79d2\uff0c\u51fa\u53bb\u662f\u6beb\u79d2<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56fe\u8868\u95ee\u4f60\u8981\u5386\u53f2\u6570\u636e\u7684\u65f6\u5019\uff0c\u7ed9\u8fc7\u6765\u7684\u662f\u79d2\u3002\u4f60\u4ea4\u56de\u53bb\u7684\u6bcf\u6839 K \u7ebf\uff0c\u65f6\u95f4\u5b57\u6bb5\u5f97\u662f\u6beb\u79d2\u3002\u8fd9\u4e24\u5957\u5355\u4f4d\u5404\u7ba1\u4e00\u6bb5\uff0c\u8c01\u4e5f\u4e0d\u4f1a\u66ff\u4f60\u8f6c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f6c\u6f0f\u4e86\u7684\u540e\u679c\u4e0d\u592a\u76f4\u89c2\u3002\u6570\u636e\u5176\u5b9e\u53d6\u56de\u6765\u4e86\uff0c\u53ea\u662f\u53d6\u9519\u4e86\u533a\u95f4\uff0c\u56fe\u4e0a\u8868\u73b0\u4e3a\u7f3a\u4e00\u6bb5\uff0c\u6216\u8005\u6574\u6bb5\u5f80\u5de6\u632a\u4e86\u4e00\u683c\u3002\u63a7\u5236\u53f0\u7167\u6837\u4e00\u6761\u62a5\u9519\u90fd\u6ca1\u6709\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e09\u6b65\u90a3\u6bb5 getBars \u91cc\uff0c\u6211\u628a\u8f6c\u6362\u5199\u5728\u6700\u524d\u9762\u4e86\uff0cperiodParams \u7684 from \u548c to \u5404\u4e58 1000 \u518d\u5f80\u540e\u7aef\u4f20\u3002\u8fd9\u4e2a\u8f6c\u6362\u53ea\u505a\u4e00\u6b21\u5c31\u591f\uff0c\u505a\u5b8c\u522b\u518d\u52a8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u56db\u4e2a\u5751\uff0c\u8d44\u6e90\u8def\u5f84\u5dee\u4e00\u4e2a\u659c\u6760\uff0c\u5bb9\u5668\u9ad8\u5ea6\u7b97\u51fa\u6765\u662f 0<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e24\u4e2a\u90fd\u5728\u7b2c\u4e8c\u6b65\uff0c\u5c5e\u4e8e\u90e8\u7f72\u671f\u7684\u5751\uff0c\u4e00\u6b21\u914d\u9519\uff0c\u540e\u9762\u6bcf\u4e00\u6b65\u90fd\u602a\u602a\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">library_path \u6307\u5411\u6574\u5957\u8d44\u6e90\u7684\u8bbf\u95ee\u76ee\u5f55\uff0c\u672b\u5c3e\u90a3\u4e2a\u659c\u6760\u4e0d\u80fd\u7701\u3002\u56fe\u8868\u540e\u9762\u8fd8\u8981\u4ece\u8fd9\u4e2a\u76ee\u5f55\u53bb\u53d6\u5185\u90e8\u7684\u811a\u672c\u548c\u6837\u5f0f\uff0c\u8def\u5f84\u62fc\u63a5\u7684\u65f6\u5019\u5c11\u4e86\u659c\u6760\uff0c\u5c31\u53d8\u6210\u5f80\u4e0a\u4e00\u7ea7\u76ee\u5f55\u627e\uff0c\u5165\u53e3\u6587\u4ef6\u7167\u6837\u80fd\u6253\u5f00\uff0c\u5185\u90e8\u8d44\u6e90\u5168\u662f 404\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bb9\u5668\u9ad8\u5ea6\u90a3\u4e00\u6761\u66f4\u5e38\u89c1\u3002\u5bb9\u5668\u5199\u7684\u662f\u767e\u5206\u6bd4\u9ad8\u5ea6\uff0c\u7236\u7ea7\u6ca1\u7ed9\u9ad8\u5ea6\uff0c\u7b97\u51fa\u6765\u5c31\u662f 0\u3002\u56fe\u8868\u521d\u59cb\u5316\u4e0d\u62a5\u9519\uff0c\u753b\u51fa\u6765\u4e00\u7247\u7a7a\u767d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e24\u4e2a\u90fd\u597d\u67e5\uff0c\u63a7\u5236\u53f0\u548c\u5143\u7d20\u9762\u677f\u4e00\u773c\u80fd\u770b\u5230\u3002\u771f\u6b63\u8d39\u65f6\u95f4\u7684\u662f\u5b83\u4eec\u7684\u8868\u73b0\u592a\u50cf\u6570\u636e\u95ee\u9898\u4e86\uff0c\u4eba\u4f1a\u4e00\u76f4\u5f80\u9519\u8bef\u7684\u65b9\u5411\u627e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56db\u4e2a\u5751\u6446\u5728\u4e00\u8d77\uff0c\u6211\u5fc3\u91cc\u90a3\u53e5\u7ed3\u8bba\u4e5f\u5c31\u6e05\u695a\u4e86\u3002\u8fd9\u5957\u4e1c\u897f\u7a33\u4e0d\u7a33\uff0c\u4e00\u534a\u9760\u673a\u5236\u8bbe\u8ba1\uff0c\u4e00\u534a\u9760\u547d\u540d\u3001\u7f16\u53f7\u3001\u5355\u4f4d\u3001\u8def\u5f84\u8fd9\u4e9b\u5c0f\u4e8b\u4e0a\u7684\u89c4\u77e9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u516d\u3001\u8ba2\u9605\u5c42\u5b8c\u6574\u5b9e\u73b0\uff0c\u53ef\u4ee5\u76f4\u63a5\u6284<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u8fd9\u4efd\u662f\u8ba2\u9605\u5c42\u7684\u5b8c\u6574\u5b9e\u73b0\uff0c\u4e0d\u542b\u4efb\u4f55\u6d4b\u8bd5\u811a\u624b\u67b6\uff0c\u53ef\u4ee5\u76f4\u63a5\u6284\u8fdb\u4f60\u7684\u9879\u76ee\u3002\u5b83\u4e0d\u4f9d\u8d56\u56fe\u8868\u5e93\uff0c\u53ea\u8981\u4f60\u7684\u884c\u60c5\u63a8\u9001\u662f\u8ba2\u9605\u9891\u9053\u52a0\u63a8\u6d88\u606f\u8fd9\u4e2a\u6a21\u578b\uff0c\u5c31\u80fd\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2469 \u8ba2\u9605\u5c42\u5b8c\u6574\u5b9e\u73b0\uff0c\u4e00\u5f20\u8868\u7ba1\u4f4f\u9891\u9053\u4e0e\u542c\u4f17<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ socket-client.js   \u8ba2\u9605\u5c42\uff1a\u4e00\u5f20\u8868\u7ba1\u4f4f\u9891\u9053\u4e0e\u542c\u4f17\u7684\u5173\u7cfb\nclass SocketClient {\n  constructor(socket) {\n    this.socket = socket;\n    this.channelToSubscription = new Map();\n    this.socket.addEventListener(\"message\", (event) => this.publish(event.data));\n  }\n\n  subscribeOnStream(symbolInfo, resolution, callback, subscriberUID, onResetCache, lastBar) {\n    const topic = this.getTopic(symbolInfo.name, resolution);\n    const current = this.channelToSubscription.get(topic);\n\n    if (current) {\n      current.handlers.push({ id: subscriberUID, callback });\n      return;\n    }\n\n    this.channelToSubscription.set(topic, {\n      lastBar,\n      handlers: &#91;{ id: subscriberUID, callback }],\n    });\n    this.emit(\"SUBSCRIBE\", &#91;topic]);\n  }\n\n  publish(rawData) {\n    const message = JSON.parse(rawData);\n    const topic = this.getTopic(message.symbol, message.resolution);\n    const item = this.channelToSubscription.get(topic);\n    if (!item) return;\n\n    const bar = {\n      time: Number(message.time),\n      open: Number(message.open),\n      high: Number(message.high),\n      low: Number(message.low),\n      close: Number(message.close),\n      volume: Number(message.volume),\n    };\n    item.lastBar = bar;\n    item.handlers.forEach((handler) => handler.callback(bar));\n  }\n\n  unsubscribeFromStream(subscriberUID) {\n    for (const &#91;topic, item] of this.channelToSubscription) {\n      item.handlers = item.handlers.filter((handler) => handler.id !== subscriberUID);\n      if (!item.handlers.length) {\n        this.emit(\"UNSUBSCRIBE\", &#91;topic]);\n        this.channelToSubscription.delete(topic);\n      }\n    }\n  }\n\n  getTopic(symbol, resolution) {\n    return symbol.toLowerCase() + \"@kline_\" + resolution;\n  }\n\n  emit(method, topics) {\n    if (this.socket.readyState !== WebSocket.OPEN) return;\n    this.socket.send(JSON.stringify({ method, topics }));\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u6cd5\u5c31\u4e24\u884c\uff0c\u63a5\u4e0a\u771f\u5b9e\u8fde\u63a5\uff0c\u628a\u56fe\u8868\u7ed9\u7684\u56de\u8c03\u4ea4\u7ed9\u5b83\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u246a \u63a5\u4e0a\u771f\u5b9e\u8fde\u63a5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u63a5\u4e0a\u771f\u5b9e\u8fde\u63a5\uff0c\u628a\u5b9e\u4f8b\u6302\u51fa\u53bb\u7ed9 datafeed \u7528\nconst socket = new WebSocket(\"wss:\/\/\u4f60\u7684\u884c\u60c5\u5730\u5740\/stream\");\nconst client = new SocketClient(socket);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd8\u6709\u4e00\u6b65\u662f\u6536\u5230\u884c\u60c5\u4e4b\u540e\u600e\u4e48\u843d\u56fe\u3002\u5224\u65ad\u8fd9\u5305\u6d88\u606f\u8be5\u66f4\u65b0\u6700\u540e\u4e00\u6839\uff0c\u8fd8\u662f\u65b0\u5f00\u4e00\u6839\uff0c\u4f9d\u636e\u53ea\u6709\u65f6\u95f4\uff0c\u4e0d\u662f\u6d88\u606f\u5e8f\u53f7\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u246b \u66f4\u65b0\u8fd8\u662f\u8ffd\u52a0\uff0c\u53ea\u770b\u65f6\u95f4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u628a\u4e00\u5305\u884c\u60c5\u843d\u5230\u56fe\u8868\u4e0a\uff0c\u66f4\u65b0\u8fd8\u662f\u8ffd\u52a0\uff0c\u53ea\u770b\u65f6\u95f4\nfunction applyTick(lastBar, tick, resolutionSec, onRealtimeCallback) {\n  const size = resolutionSec * 1000;\n  const barTime = Math.floor(tick.time \/ size) * size;\n\n  \/\/ \u65f6\u95f4\u8fd8\u843d\u5728\u5f53\u524d\u8fd9\u6839\u91cc\uff0c\u66f4\u65b0\u5b83\n  if (lastBar &amp;&amp; barTime === lastBar.time) {\n    const merged = {\n      ...lastBar,\n      high: Math.max(lastBar.high, tick.price),\n      low: Math.min(lastBar.low, tick.price),\n      close: tick.price,\n      volume: lastBar.volume + (tick.volume || 0),\n    };\n    onRealtimeCallback(merged);\n    return merged;\n  }\n\n  \/\/ \u65f6\u95f4\u8fdb\u4e86\u4e0b\u4e00\u6839\uff0c\u65b0\u5f00\u4e00\u6839\n  const fresh = {\n    time: barTime,\n    open: tick.price,\n    high: tick.price,\n    low: tick.price,\n    close: tick.price,\n    volume: tick.volume || 0,\n  };\n  onRealtimeCallback(fresh);\n  return fresh;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4efd\u4ee3\u7801\u4e5f\u53ef\u4ee5\u76f4\u63a5\u62ff\u53bb\u6539\u3002getTopic \u6362\u6210\u4f60\u81ea\u5df1\u7684\u9891\u9053\u540d\u89c4\u5219\uff0cpublish \u91cc\u90a3\u516d\u4e2a\u5b57\u6bb5\u7684\u7ec4\u88c5\u6362\u6210\u4f60\u6570\u636e\u6e90\u7684\u5b57\u6bb5\u540d\uff0c\u5269\u4e0b\u7684\u4e00\u884c\u90fd\u4e0d\u7528\u52a8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u8bf4\u4e00\u53e5\u6570\u636e\u6e90\u600e\u4e48\u63a5\u3002\u8fd9\u7c7b\u90e8\u7f72\u91cc\u7684\u5730\u5740\u57fa\u672c\u90fd\u662f\u5360\u4f4d\u7b26\uff0c\u6211\u8865\u51e0\u53e5\u56fd\u5185\u80fd\u843d\u5730\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u90a3\u79cd\u9891\u9053\u540d\u7684\u683c\u5f0f\uff0c\u662f\u516c\u5f00\u884c\u60c5\u63a8\u9001\u91cc\u5f88\u5e38\u89c1\u7684\u547d\u540d\u6cd5\uff0c\u8fde\u6ce8\u518c\u90fd\u4e0d\u7528\uff0c\u9002\u5408\u5148\u628a\u94fe\u8def\u8dd1\u901a\u3002\u94fe\u8def\u8dd1\u901a\u4e4b\u540e\uff0c\u518d\u6362\u6210\u4f60\u81ea\u5df1\u7684\u6570\u636e\u6e90\u3002\u6e20\u9053\u5927\u81f4\u6709\u4e09\u79cd\u3002\u5238\u5546\u7684\u884c\u60c5\u63a8\u9001\u6700\u7701\u4e8b\uff0c\u524d\u63d0\u662f\u4f60\u6709\u8d26\u6237\u548c\u6743\u9650\u3002\u901a\u8fbe\u4fe1\u7684\u672c\u5730\u8f6c\u53d1\u9002\u5408\u672c\u6765\u5c31\u5728\u7528\u5b83\u7684\uff0c\u63a5\u8d77\u6765\u6700\u76f4\u63a5\u3002\u518d\u9000\u4e00\u6b65\uff0c\u7528 akshare \u8fd9\u7c7b\u5e93\u8f6e\u8be2\u4e5f\u80fd\u8dd1\uff0c\u65e5\u7ebf\u591f\u7528\uff0c\u5206\u949f\u7ea7\u5c31\u522b\u6307\u671b\u4e86\uff0c\u8f6e\u8be2\u7684\u95f4\u9694\u51b3\u5b9a\u4e86\u5b83\u7684\u4e0b\u9650\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e09\u79cd\u6e20\u9053\u7684\u63a5\u53e3\u957f\u76f8\u5404\u4e0d\u76f8\u540c\uff0c\u4f46\u53ea\u8981\u4f60\u7684 getBars \u548c\u8ba2\u9605\u56de\u8c03\u8fd9\u4e24\u5904\u8f93\u51fa\u683c\u5f0f\u4e0d\u53d8\uff0c\u4e0a\u9762\u8fd9\u5957\u4ee3\u7801\u4e00\u884c\u90fd\u4e0d\u7528\u6539\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e03\u3001\u503c\u4e0d\u503c\u5f97\u81ea\u5df1\u642d<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u56de\u5230\u5f00\u5934\u90a3\u4e2a\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u81ea\u5df1\u642d\u7684\u597d\u5904\u662f\u6570\u636e\u5728\u81ea\u4e2a\u513f\u624b\u4e0a\u3002\u56fe\u8868\u957f\u4ec0\u4e48\u6837\u3001\u52a0\u4ec0\u4e48\u6307\u6807\u3001\u7559\u591a\u4e45\u7684\u5386\u53f2\uff0c\u5168\u662f\u4f60\u8bf4\u4e86\u7b97\u3002\u54ea\u5929\u60f3\u6362\u4e00\u5bb6\u6570\u636e\u6e90\uff0c\u52a8\u7684\u53ea\u662f\u6700\u4e0b\u9762\u90a3\u4e00\u5c42\uff0c\u4e0a\u9762\u51e0\u5c42\u7684\u4ee3\u7801\u4e0d\u7528\u78b0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6210\u672c\u4e5f\u5f97\u8bf4\u6e05\u695a\u3002\u56fe\u8868\u5e93\u672c\u8eab\u8981\u8fc7\u6388\u6743\u6d41\u7a0b\uff0c\u8fd9\u662f\u6700\u786c\u7684\u4e00\u9053\u95e8\u69db\u3002\u4e4b\u540e\u662f\u8fd0\u7ef4\uff0c\u65ad\u7ebf\u91cd\u8fde\u3001\u5fc3\u8df3\u3001\u8ba2\u9605\u6062\u590d\u8fd9\u4e9b\u6d3b\uff0c\u4e0a\u7ebf\u4e4b\u540e\u4f1a\u4e00\u76f4\u8ddf\u7740\u4f60\u3002\u518d\u5f80\u540e\u662f\u6807\u7684\u548c\u5468\u671f\u7684\u6269\u5f20\uff0c\u6bcf\u52a0\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u8ba2\u9605\u8868\u7684\u89c4\u6a21\u90fd\u8981\u5f80\u4e0a\u8d70\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\u6211\u7684\u5224\u65ad\u5206\u4e24\u79cd\u60c5\u51b5\u3002\u5982\u679c\u4f60\u53ea\u662f\u60f3\u8981\u4e00\u5f20\u597d\u770b\u7684 K \u7ebf\u56fe\uff0c\u73b0\u6210\u7684\u7f51\u9875\u7248\u5b8c\u5168\u591f\u7528\uff0c\u771f\u6ca1\u5fc5\u8981\u6298\u817e\u3002\u5982\u679c\u4f60\u662f\u8981\u628a\u884c\u60c5\u63a5\u8fdb\u81ea\u5df1\u7684\u7b56\u7565\u6d41\u7a0b\uff0c\u8ba9\u56de\u6d4b\u548c\u770b\u76d8\u7528\u540c\u4e00\u4efd\u6570\u636e\uff0c\u90a3\u8fd9\u4e00\u5957\u5c31\u503c\u5f97\u505a\uff0c\u7701\u6389\u7684\u662f\u4e00\u6574\u6761\u6570\u636e\u642c\u8fd0\u7684\u94fe\u8def\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u4e00\u4e2a\u95ee\u9898\u7559\u7ed9\u4f60\u3002\u4f60\u81ea\u5df1\u90a3\u5957\u884c\u60c5\u770b\u677f\u6216\u8005\u7b56\u7565\u811a\u672c\uff0c\u6570\u636e\u662f\u4ece\u54ea\u4e00\u5c42\u8fdb\u6765\u7684\uff0c\u6709\u6ca1\u6709\u4e00\u4e2a\u5730\u65b9\u80fd\u7edf\u4e00\u7ba1\u4f4f\u9891\u9053\u540d\u7684\u751f\u6210\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u89c9\u5f97\u6709\u7528\u7684\u8bdd\uff0c\u628a\u8fd9\u7bc7\u8f6c\u7ed9\u540c\u6837\u5728\u5199\u884c\u60c5\u770b\u677f\u7684\u670b\u53cb\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><a>#TradingView<\/a>&nbsp;<a>#K\u7ebf\u56fe\u8868<\/a>&nbsp;<a>#\u672c\u5730\u90e8\u7f72<\/a>&nbsp;<a>#WebSocket<\/a>&nbsp;<a>#\u53d1\u5e03\u8ba2\u9605<\/a>&nbsp;<a>#Vue<\/a>&nbsp;<a>#\u6570\u636e\u6e90\u63a5\u5165<\/a>&nbsp;<a>#\u5b9e\u65f6\u884c\u60c5<\/a>&nbsp;<a>#\u91cf\u5316\u5de5\u5177<\/a>&nbsp;<a>#\u524d\u7aef\u5de5\u7a0b<\/a>&nbsp;<a>#\u884c\u60c5\u770b\u677f<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u4e3a\u6280\u672f\u65b9\u6848\u62c6\u89e3\uff0c\u4e0d\u6784\u6210\u4efb\u4f55\u64cd\u4f5c\u5efa\u8bae\u3002\u6587\u4e2d\u4ee3\u7801\u4e3a\u901a\u7528\u5b9e\u73b0\u793a\u4f8b\uff0c\u63a5\u5165\u4efb\u4f55\u6570\u636e\u6e90\u4e4b\u524d\u8bf7\u81ea\u884c\u786e\u8ba4\u5176\u6388\u6743\u8303\u56f4\u4e0e\u4f7f\u7528\u6761\u6b3e\u3002\u91cf\u5316\u5de5\u5177\u5f00\u53d1\u5e94\u4ee5\u5b66\u4e60\u548c\u6280\u672f\u4ea4\u6d41\u4e3a\u76ee\u7684\u3002\u5e02\u573a\u6709\u98ce\u9669\uff0c\u8bf7\u5408\u6cd5\u5408\u89c4\u6295\u8d44\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c \u8005\uff1a\u8001\u4f59\u635e\u9c7c \u539f\u521b\u4e0d\u6613\uff0c\u8f6c\u8f7d\u8bf7\u6807\u660e\u51fa\u5904\u53ca\u539f\u4f5c\u8005&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/laoyulaoyu.com\/index.php\/2026\/09\/22\/%e5%9b%9b%e6%ad%a5%e6%8a%8atradingview%e5%9b%be%e8%a1%a8%e6%90%ac%e5%9b%9e%e7%94%b5%e8%84%91%ef%bc%8c%e6%8e%a5%e4%b8%8a%e8%87%aa%e5%b7%b1%e7%9a%84%e6%95%b0%e6%8d%ae%e6%ba%90\/\">Continue reading<span class=\"screen-reader-text\">\u56db\u6b65\u628aTradingView\u56fe\u8868\u642c\u56de\u7535\u8111\uff0c\u63a5\u4e0a\u81ea\u5df1\u7684\u6570\u636e\u6e90<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[17,4,5,6],"class_list":["post-4934","post","type-post","status-publish","format-standard","hentry","category-aiinvest","tag-ai","tag-6","entry"],"_links":{"self":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/4934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/comments?post=4934"}],"version-history":[{"count":1,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/4934\/revisions"}],"predecessor-version":[{"id":4941,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/4934\/revisions\/4941"}],"wp:attachment":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/media?parent=4934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/categories?post=4934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/tags?post=4934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}