id: 2cb776bf69724a07865a05bb3990a849
parent_id: 
item_type: 1
item_id: 506caf56137e4a8e9b662879dc21b5da
item_updated_time: 1764345627114
title_diff: "[{\"diffs\":[[1,\"如何绕过交易所 API 限制，高效获取数据？这些技巧你必须知道！\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":32}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>如何绕过交易所 API 限制，高效获取数据？这些技巧你必须知道！</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"content-class\\\" content=\\\"yinxiang.peso.superNote\\\"/>\\\r\\\n  <meta name=\\\"application-data:yinxiang.noteLayout\\\" content=\\\"{\\\"lineSpace\\\":\\\"recommend\\\",\\\"paragraphSpace\\\":\\\"recommend\\\"}\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"39698\\\"></a>\\\r\\\n<h1>如何绕过交易所 API 限制，高效获取数据？这些技巧你必须知道！</h1>\\\r\\\n\\\r\\\n<div><span style=\\\"margin:0px;\\\"><div style=\\\"padding:8px 0px;margin:8px auto;max-width:700px;\\\"> <div><span></span></div>\\\n<p></p>\\\n<div style=\\\"--en-blockquote:true;box-sizing: border-box; padding-left: 19px; padding-top: 6px; padding-bottom: 6px; border-left: 3px solid #b4c0cc; background-position: initial initial; background-repeat: initial initial; margin-top: 6px\\\"><div>原文链接: <a href=\\\"http://mp.weixin.qq.com/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247487468&amp;idx=1&amp;sn=4402373d9076af8bdf48044ec57d8c38&amp;chksm=c33455fe3d642712c96b661688f5cc5a53ee9640195c1bd3db3bba2086180096129f7c77cdd4&amp;mpshare=1&amp;scene=1&amp;srcid=0410ruIex5ubURMrJgs107k2&amp;sharer_shareinfo=8bb618430c41cf4a12a63f4a15ba5279&amp;sharer_shareinfo_first=8bb618430c41cf4a12a63f4a15ba5279#rd\\\"><span>http://mp.weixin.qq.com/s?__biz=MzkzNzY0NjIyNQ==&amp;mid=2247487...</span></a></div></div>\\\n<p></p>\\\n<div><span></span></div>\\\n<div style=\\\"\\\"><div><div><h1 style=\\\"margin:0\\\"> 如何绕过交易所 API 限制，高效获取数据？这些技巧你必须知道！ </h1><div><span style=\\\"position:relative\\\">原创</span><span><span style=\\\"position:relative\\\">老余捞鱼</span></span><span><a style=\\\"position:relative\\\"> 老余捞鱼 </a></span><span><em></em></span></div><div style=\\\";\\\"><div style=\\\"margin-bottom: 0px;\\\"><div style=\\\"\\\"><div style=\\\"\\\"><div style=\\\"\\\"><div style=\\\"\\\"><div style=\\\"margin-top: 8px;margin-bottom: 8px;\\\"><div style=\\\"\\\"><div style=\\\"margin: 10px auto;\\\"><div style=\\\"display: flex;align-items: center;\\\"><div style=\\\"\\\"><div style=\\\"display: flex;justify-content: center;\\\"><div style=\\\"width: 35px;\\\"><img src=\\\":/9fec161f14d54764bb8edcfa0a6f2c38\\\" type=\\\"image/gif\\\" data-filename=\\\"640.gif\\\" alt=\\\"图片\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;display: block;vertical-align: baseline;width: 100%;__visibility: visible !important;\\\"/></div></div></div><div style=\\\"color: rgb(31, 75, 149);font-size: 14px;line-height: 1.75em;border-bottom: 2px solid rgb(31, 75, 149);width: 100%;margin-left: -30px;\\\"><strong style=\\\"__visibility: visible;\\\"><span style=\\\"__visibility: visible;\\\"> <span style=\\\"font-weight: normal;\\\">点击上方蓝字 | 关注更多好文</span></span></strong></div></div></div></div><div style=\\\"max-inline-size: 100%;margin-bottom: -17px;display: flex;justify-content: flex-end;align-items: center;\\\"><div style=\\\"max-inline-size: 100%;z-index: 9;\\\"><div style=\\\"max-inline-size: 100%;padding-right: 5px;padding-left: 5px;font-size: 16px;letter-spacing: 1.5px;color: rgb(206, 42, 27);text-align: center;background-color: rgb(255, 255, 255);transform: skew(-10deg);\\\"><strong style=\\\"max-inline-size: 100%;__visibility: visible;\\\"><span style=\\\"font-size: 18px;__visibility: visible;\\\">写在前面的话</span></strong></div></div></div><div style=\\\"max-inline-size: 100%;padding-top: 20px;padding-bottom: 13px;padding-left: 13px;border-top: 1px dashed rgb(217, 203, 161);border-left: 1px dashed rgb(217, 203, 161);border-bottom: 1px dashed rgb(217, 203, 161);\\\"><div style=\\\"text-align: center;\\\"><img src=\\\":/3e28813e85404a92a99048677054757a\\\" type=\\\"image/jpeg\\\" data-filename=\\\"640.jpg\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;\\\"/></div><div style=\\\"width: 100%;max-inline-size: 100%;\\\"><span style=\\\"border-bottom: 1px dashed rgb(115, 210, 202);line-height: 1.71em;font-size: 14px;__visibility: visible;\\\"><span style=\\\"font-size: 15px;\\\">在数字金融领域，全球较大规模的交易所都有API为开发者提供了丰富的数据接口。然而，API的时间和请求限制常常让开发者和数据分析师头疼不已。今天，</span><span style=\\\"font-size: 15px;color: rgb(0, 128, 255);\\\">我将分享几种绕过API限制的高效方法（以Binance.币安为例），助你轻松获取海量数据</span>。</span></div></div><div style=\\\"\\\"><div style=\\\"margin: 16px auto 20px;\\\"><div style=\\\"display: flex;justify-content: space-between;align-items: center;\\\"><div style=\\\"\\\"><div style=\\\"text-align: left;letter-spacing: 1.5px;\\\"><strong style=\\\"__visibility: visible;\\\"><span style=\\\"font-size: 24px;letter-spacing: 1px;color: rgb(217, 33, 66);__visibility: visible;\\\"><span>①什么是</span><strong><span> API 限制</span></strong><span> </span><strong><span>？</span></strong></span></strong></div><div style=\\\"display: flex;align-items: center;\\\"><div style=\\\"flex-shrink: 0;\\\"><div style=\\\"width: 14px;height: 14px;background-color: rgb(255, 205, 69);\\\"><p style=\\\"margin:0;__visibility:visible\\\"><span><br/></span></p></div></div><div style=\\\"font-size: 14px;color: rgb(222, 222, 222);text-align: left;padding-right: 4px;padding-left: 4px;\\\"><strong style=\\\"__visibility: visible;\\\"><span> What is it ?</span></strong></div></div></div><div style=\\\"flex-shrink: 0;\\\"><div style=\\\"font-size: 30px;letter-spacing: 1.5px;color: rgb(255, 255, 255);width: 45px;height: 45px;line-height: 45px;text-align: center;background-color: rgb(255, 215, 106);\\\"><strong style=\\\"__visibility: visible;\\\"><span>0</span></strong><strong style=\\\"__visibility: visible;\\\"><span>1</span></strong></div></div></div></div></div><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><span>API 限制是指在使用应用程序编程接口（API）时，对请求数量、频率或数据访问的限制。API 限制的类型大致会分成以下几种类型：</span></p><div><span><img src=\\\":/1bd5e936905440bf955c7b23dcb334c3\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;width:583px;height:auto;\\\"/></span></div><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><span>Binance和大多数交易所的API都会设置这个限制，以确保系统的稳定性、安全性和公平性。API 限制可以帮助防止滥用、保护服务器资源，并确保所有用户都能获得良好的服务体验。</span></p><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><span>比如Binance API就限制每次请求最多返回 1000 条数据，并对每分钟请求次数设定上限为1200次。为了高效获取更多数据，并为AI量化交易提供更好的数据环境，我们需要找到合适的突破口。</span></p></div></div></div></div></div><div><div style=\\\"margin: 16px auto 20px;\\\"><div style=\\\"display: flex;justify-content: space-between;align-items: center;\\\"><div><div style=\\\"text-align: left;letter-spacing: 1.5px;\\\"><strong><span style=\\\"font-size: 24px;color: rgb(217, 33, 66);\\\"><strong><span>② </span></strong><span>几种有效方式</span></span></strong></div><div style=\\\"display: flex;align-items: center;\\\"><div style=\\\"flex-shrink: 0;\\\"><div style=\\\"width: 14px;height: 14px;background-color: rgb(255, 205, 69);\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div><div style=\\\"font-size: 14px;color: rgb(222, 222, 222);text-align: left;padding-right: 4px;padding-left: 4px;\\\"><strong><span>Several Effective Methods</span></strong></div></div></div><div style=\\\"flex-shrink: 0;\\\"><div style=\\\"font-size: 30px;letter-spacing: 1.5px;color: rgb(255, 255, 255);width: 45px;height: 45px;line-height: 45px;text-align: center;background-color: rgb(255, 215, 106);\\\"><strong><span>02</span></strong><strong><span><br/></span></strong></div></div></div></div></div><div style=\\\"border-width: 0px;border-style: none;border-color: initial;z-index: 0;color: rgb(0, 3, 51);caret-color: rgb(255, 0, 0);background-color: rgb(255, 255, 255);max-inline-size: 100%;font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;\\\"><div style=\\\"margin: 10px auto;display: flex;max-inline-size: 100%;\\\"><div style=\\\"flex-shrink: 0;background-color: rgb(41, 108, 212);display: flex;max-inline-size: 100%;\\\"><div style=\\\"padding: 4px 4px 4px 10px;font-size: 16px;letter-spacing: 1.5px;color: rgb(255, 255, 255);max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>2.</span></strong><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>1</span></strong></span></div><div style=\\\"flex-shrink: 0;max-inline-size: 100%;\\\"><div style=\\\"width: 6px;height: 6px;background-color: rgb(255, 193, 73);max-inline-size: 100%;\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div></div><div style=\\\"border-top: 1px solid rgb(41, 108, 212);border-right: 1px solid rgb(41, 108, 212);border-bottom: 1px solid rgb(41, 108, 212);display: flex;align-items: center;width: 100%;border-left: none;max-inline-size: 100%;\\\"><div style=\\\"padding-right: 10px;padding-left: 10px;font-size: 16px;color: rgb(41, 108, 212);text-align: left;letter-spacing: 1.5px;max-inline-size: 100%;\\\"><span style=\\\"font-size: 18px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><strong><span>使用代理IP：分散请求来源</span></strong></strong></span></div></div></div></div><p style=\\\"margin:0;margin-top:16px;margin-bottom:16px\\\"><span>如果你的请求过于集中，Binance等交易所可能会认为你在进行恶意操作，从而限制你的IP。</span></p><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><span><span style=\\\"font-weight: bold;\\\">解决方案：</span></span><span> 使用代理IP池，将请求分散到不同的IP地址上。这样不仅可以绕过IP限制，还能提高请求的成功率。</span></p><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><strong><span>推荐工具：</span></strong></p><ul style=\\\"margin:0;list-style-type:disc\\\"><li><p style=\\\"margin:0;margin-top:0;margin-bottom:0\\\"><strong><span>ScraperAPI</span></strong><span>：提供高质量的代理IP服务。</span></p></li><li><p style=\\\"margin:0;margin-top:0;margin-bottom:16px\\\"><strong><span>ProxyMesh</span></strong><span>：支持动态IP切换，适合大规模数据抓取。</span></p></li></ul><div style=\\\"margin: 10px auto;display: flex;max-inline-size: 100%;\\\"><div style=\\\"flex-shrink: 0;background-color: rgb(41, 108, 212);display: flex;max-inline-size: 100%;\\\"><div style=\\\"padding: 4px 4px 4px 10px;font-size: 16px;letter-spacing: 1.5px;color: rgb(255, 255, 255);max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>2.</span></strong><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>2</span></strong></span></div><div style=\\\"flex-shrink: 0;max-inline-size: 100%;\\\"><div style=\\\"width: 6px;height: 6px;background-color: rgb(255, 193, 73);max-inline-size: 100%;\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div></div><div style=\\\"border-top: 1px solid rgb(41, 108, 212);border-right: 1px solid rgb(41, 108, 212);border-bottom: 1px solid rgb(41, 108, 212);display: flex;align-items: center;width: 100%;border-left: none;max-inline-size: 100%;\\\"><div style=\\\"padding-right: 10px;padding-left: 10px;font-size: 16px;color: rgb(41, 108, 212);text-align: left;letter-spacing: 1.5px;max-inline-size: 100%;\\\"><span style=\\\"font-size: 18px;\\\"><strong><span>调整请求频率：避免触发风控</span></strong></span></div></div></div><p style=\\\"margin:0;margin-top:16px;margin-bottom:8px\\\"><span>即使你分批次请求，如果频率过高，仍然可能触发Binance的风控机制。</span></p><p style=\\\"margin:0;margin-top:16px;margin-bottom:8px\\\"><span><span style=\\\"font-weight: bold;\\\">解决方案：</span></span><span> 在代码中加入随机延迟，模拟人类操作。例如，在每次请求后随机等待1-3秒。</span></p><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><strong><span>代码示例：</span></strong></p></div><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>import</span> random</span><div><span><br/></span></div><div><span><span>def</span> <span>fetch_data_with_delay</span>(<span>symbol, limit=</span><span><span>1000</span></span>):</span></div><div><span>    url = <span>f&quot;https://api.binance.com/api/v3/trades?symbol=</span><span><span>{symbol}</span></span><span>&amp;limit=</span><span><span>{limit}</span></span><span>&quot;</span></span></div><div><span>    response = requests.get(url)</span></div><div><span>    time.sleep(random.uniform(<span>1</span>, <span>3</span>))  <span># 随机延迟1-3秒</span></span></div><div><span>    <span>return</span> response.json()</span></div></div></pre></div><div style=\\\"margin-bottom: 0px;\\\"><div style=\\\"margin: 10px auto;display: flex;max-inline-size: 100%;\\\"><div style=\\\"flex-shrink: 0;background-color: rgb(41, 108, 212);display: flex;max-inline-size: 100%;\\\"><div style=\\\"padding: 4px 4px 4px 10px;font-size: 16px;letter-spacing: 1.5px;color: rgb(255, 255, 255);max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>2.</span></strong><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>3</span></strong></span></div><div style=\\\"flex-shrink: 0;max-inline-size: 100%;\\\"><div style=\\\"width: 6px;height: 6px;background-color: rgb(255, 193, 73);max-inline-size: 100%;\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div></div><div style=\\\"border-top: 1px solid rgb(41, 108, 212);border-right: 1px solid rgb(41, 108, 212);border-bottom: 1px solid rgb(41, 108, 212);display: flex;align-items: center;width: 100%;border-left: none;max-inline-size: 100%;\\\"><div style=\\\"padding-right: 10px;padding-left: 10px;font-size: 16px;color: rgb(41, 108, 212);text-align: left;letter-spacing: 1.5px;max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><strong><span><span style=\\\"font-size: 18px;\\\">利用WebSocket：实时数据获取</span></span></strong></strong></span></div></div></div><p style=\\\"margin:0;margin-bottom:8px;margin-top:16px\\\"><span>如果你需要实时数据，WebSocket 是更好的选择。WebSocket 是一种双向通信协议，可以实时接收Binance的更新数据，而不需要频繁发送HTTP请求。</span></p><p style=\\\"margin:0\\\"><strong><span>代码示例：</span></strong></p></div><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span><span>from</span> websocket <span>import</span> create_connection</span><div><span><span>import</span> json</span></div><div><span><br/></span></div><div><span><span>def</span> <span>websocket_example</span>():</span></div><div><span>    ws = create_connection(<span>&quot;wss://stream.binance.com:9443/ws/btcusdt@trade&quot;</span>)</span></div><div><span>    <span>while</span> <span>True</span>:</span></div><div><span>        data = ws.recv()</span></div><div><span>        <span>print</span>(json.loads(data))</span></div></div></pre></div><div style=\\\"margin-bottom: 0px;\\\"><div style=\\\"border-width: 0px;border-style: none;border-color: initial;z-index: 0;color: rgb(0, 3, 51);caret-color: rgb(255, 0, 0);background-color: rgb(255, 255, 255);max-inline-size: 100%;font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;\\\"><div style=\\\"margin: 10px auto;display: flex;max-inline-size: 100%;\\\"><div style=\\\"flex-shrink: 0;background-color: rgb(41, 108, 212);display: flex;max-inline-size: 100%;\\\"><div style=\\\"padding: 4px 4px 4px 10px;font-size: 16px;letter-spacing: 1.5px;color: rgb(255, 255, 255);max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>2.4</span></strong></span></div><div style=\\\"flex-shrink: 0;max-inline-size: 100%;\\\"><div style=\\\"width: 6px;height: 6px;background-color: rgb(255, 193, 73);max-inline-size: 100%;\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div></div><div style=\\\"border-top: 1px solid rgb(41, 108, 212);border-right: 1px solid rgb(41, 108, 212);border-bottom: 1px solid rgb(41, 108, 212);display: flex;align-items: center;width: 100%;border-left: none;max-inline-size: 100%;\\\"><div style=\\\"padding-right: 10px;padding-left: 10px;font-size: 16px;color: rgb(41, 108, 212);text-align: left;letter-spacing: 1.5px;max-inline-size: 100%;\\\"><span style=\\\"font-size: 18px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><strong><span>多账户轮换：分散请求压力</span></strong></strong></span></div></div></div></div><p style=\\\"margin:0\\\"><span>如果你有多个Binance账户，可以轮换使用这些账户的API密钥，分散请求压力。</span></p><p style=\\\"margin:0\\\"><strong><span>注意：</span></strong><span> 使用多账户时，务必遵守Binance的使用条款，避免违规操作。</span></p></div><div><div style=\\\"margin: 16px auto 20px;\\\"><div style=\\\"display: flex;justify-content: space-between;align-items: center;\\\"><div><div style=\\\"text-align: left;letter-spacing: 1.5px;\\\"><strong><span style=\\\"font-size: 24px;color: rgb(217, 33, 66);\\\"><strong><span>③ </span></strong><strong><span>我推荐的方法</span></strong></span></strong></div><div style=\\\"display: flex;align-items: center;\\\"><div style=\\\"flex-shrink: 0;\\\"><div style=\\\"width: 14px;height: 14px;background-color: rgb(255, 205, 69);\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div><div style=\\\"font-size: 14px;color: rgb(222, 222, 222);text-align: left;padding-right: 4px;padding-left: 4px;\\\"><strong><span>The Methods I Recommend</span></strong></div></div></div><div style=\\\"flex-shrink: 0;\\\"><div style=\\\"font-size: 30px;letter-spacing: 1.5px;color: rgb(255, 255, 255);width: 45px;height: 45px;line-height: 45px;text-align: center;background-color: rgb(255, 215, 106);\\\"><strong><span>03</span></strong><strong><span><br/></span></strong></div></div></div></div></div><p style=\\\"margin:0;margin-top:16px;margin-bottom:8px\\\"><span>我比较推荐的是一种<span style=\\\"font-weight: bold;\\\">能</span></span><strong><span>结合自己量化软件的自动化分页技术</span></strong><span>，可以获取超过1000个K线数据，通过分页技术实现。这种方法</span><strong><span>适合于实战</span></strong><span>，适用于：</span></p><ul style=\\\"margin:0;list-style-type:disc\\\"><li><p style=\\\"margin:0\\\"><strong><span>高频交易策略</span></strong><span>：快速提取分钟级数据，助力短线交易决策。</span></p></li><li><p style=\\\"margin:0\\\"><strong><span>历史数据分析</span></strong><span>：完整市场数据有助于模型训练和回测。</span></p></li><li><p style=\\\"margin:0;margin-bottom:16px\\\"><strong><span>市场监测与风控</span></strong><span>：及时抓取数据，确保实时监控市场波动。</span></p></li></ul><div style=\\\"border-width: 0px;border-style: none;border-color: initial;z-index: 0;color: rgb(0, 3, 51);caret-color: rgb(255, 0, 0);background-color: rgb(255, 255, 255);max-inline-size: 100%;font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;\\\"><div style=\\\"margin: 10px auto;display: flex;max-inline-size: 100%;\\\"><div style=\\\"flex-shrink: 0;background-color: rgb(41, 108, 212);display: flex;max-inline-size: 100%;\\\"><div style=\\\"padding: 4px 4px 4px 10px;font-size: 16px;letter-spacing: 1.5px;color: rgb(255, 255, 255);max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>3.</span></strong><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>1</span></strong></span></div><div style=\\\"flex-shrink: 0;max-inline-size: 100%;\\\"><div style=\\\"width: 6px;height: 6px;background-color: rgb(255, 193, 73);max-inline-size: 100%;\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div></div><div style=\\\"border-top: 1px solid rgb(41, 108, 212);border-right: 1px solid rgb(41, 108, 212);border-bottom: 1px solid rgb(41, 108, 212);display: flex;align-items: center;width: 100%;border-left: none;max-inline-size: 100%;\\\"><div style=\\\"padding-right: 10px;padding-left: 10px;font-size: 16px;color: rgb(41, 108, 212);text-align: left;letter-spacing: 1.5px;max-inline-size: 100%;\\\"><span style=\\\"font-size: 18px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><strong><span>具体方法</span></strong></strong></span></div></div></div></div><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><span>具体方法简单来说就是八个字：“</span><strong><span>化整为零，突破限制</span></strong><span>”。</span></p><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><span>我们可以分批请求每次获取最多1000个K线，然后根据上一次请求的最后K线的关闭时间（close_time）调整下一次请求的起始时间（startTime）。这种方法确保数据连续性，并能逐步获取所有所需历史数据。</span></p><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><span>以下是使用Python实现的分步指南，代码示例基于requests库：</span></p><ul style=\\\"margin:0;list-style-type:disc\\\"><li><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><strong><span>定义参数</span></strong><span>：设置交易对（如ETHUSDT）、时间间隔（如每日数据'1d'）、起始日期和结束日期。</span></p></li><li><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><strong><span>转换时间</span></strong><span>：将日期转换为UTC时间的毫秒数，符合API要求。</span></p></li><li><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><strong><span>循环请求</span></strong><span>：通过循环，每次请求获取最多1000个K线，记录最后一条K线的关闭时间。</span></p></li><li><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><strong><span>更新起始时间</span></strong><span>：将下一次请求的起始时间设置为上一次最后K线的关闭时间加1毫秒，确保连续性。</span></p></li><li><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><strong><span>合并数据</span></strong><span>：将每次请求的结果合并，直到所有数据获取完成或达到结束日期。</span></p></li></ul><p style=\\\"margin:0;margin-top:8px;margin-bottom:8px\\\"><span>部分示例代码如下：</span></p><div><pre><div style=\\\"--en-codeblock:true;--en-meta:{&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true};box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial; margin-top: 6px;\\\"><span>import requests</span><div><span>import pandas <span>as</span> pd</span></div><div><span><br/></span></div><div><span><span># Binance K线数据请求函数</span></span></div><div><span><span>def </span><span><span>fetch_binance_data</span></span><span>(</span><span><span>symbol, interval, start_time, end_time</span></span><span>):</span></span></div><div><span>    url = f<span>&quot;https://api.binance.com/api/v3/klines&quot;</span></span></div><div><span>    all_data = []</span></div><div><span><br/></span></div><div><span>    <span>while</span> start_time &lt; end_time:</span></div><div><span>        <span>params</span> = {</span></div><div><span>            <span>&quot;symbol&quot;</span>: symbol,</span></div><div><span>            <span>&quot;interval&quot;</span>: interval,</span></div><div><span>            <span>&quot;startTime&quot;</span>: start_time,</span></div><div><span>            <span>&quot;limit&quot;</span>: <span>1000</span></span></div><div><span>        }</span></div><div><span>        response = requests.<span>get</span>(url, <span>params</span>=<span>params</span>)</span></div><div><span>        data = response.json()</span></div><div><span><br/></span></div><div><span>        <span>if</span> <span>not</span> data:</span></div><div><span>            <span>break</span>  <span># 数据获取完毕</span></span></div><div><span><br/></span></div><div><span>        all_data.extend(data)</span></div><div><span>        start_time = data[<span>-1</span>][<span>0</span>] + <span>1</span>  <span># 更新 `startTime`</span></span></div><div><span><br/></span></div><div><span>    df = pd.DataFrame(all_data, columns=[<span>'Time'</span>, <span>'Open'</span>, <span>'High'</span>, <span>'Low'</span>, <span>'Close'</span>, <span>'Volume'</span>, <span>'CloseTime'</span>, <span>'QuoteAssetVolume'</span>, <span>'NumberOfTrades'</span>, <span>'TakerBuyBaseVolume'</span>, <span>'TakerBuyQuoteVolume'</span>, <span>'Ignore'</span>])</span></div><div><span>    <span>return</span> df</span></div><div><span><br/></span></div><div><span><span># 示例调用</span></span></div><div><span>df = fetch_binance_data(<span>'BTCUSDT'</span>, <span>'1h'</span>, <span>1640995200000</span>, <span>1648684800000</span>)</span></div><div><span>print(df.head())</span></div></div></pre></div><div style=\\\"margin: 10px auto;display: flex;max-inline-size: 100%;\\\"><div style=\\\"flex-shrink: 0;background-color: rgb(41, 108, 212);display: flex;max-inline-size: 100%;\\\"><div style=\\\"padding: 4px 4px 4px 10px;font-size: 16px;letter-spacing: 1.5px;color: rgb(255, 255, 255);max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>3.</span></strong><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>2</span></strong></span></div><div style=\\\"flex-shrink: 0;max-inline-size: 100%;\\\"><div style=\\\"width: 6px;height: 6px;background-color: rgb(255, 193, 73);max-inline-size: 100%;\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div></div><div style=\\\"border-top: 1px solid rgb(41, 108, 212);border-right: 1px solid rgb(41, 108, 212);border-bottom: 1px solid rgb(41, 108, 212);display: flex;align-items: center;width: 100%;border-left: none;max-inline-size: 100%;\\\"><div style=\\\"padding-right: 10px;padding-left: 10px;font-size: 16px;color: rgb(41, 108, 212);text-align: left;letter-spacing: 1.5px;max-inline-size: 100%;\\\"><span style=\\\"font-size: 18px;\\\"><strong><strong><span>注意事项</span></strong></strong></span></div></div></div><ul style=\\\"margin:0;list-style-type:disc\\\"><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:16px\\\"><strong><span>时间对齐</span></strong><span>：确保起始时间和结束时间与K线间隔对齐，API会自动调整非对齐的时间，但建议手动处理以提高效率。</span></p></li><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>不同间隔的处理</span></strong><span>：上述方法适用于所有时间间隔（如1小时'1h'、1分钟'1m'），只需根据间隔调整close_time加法的单位（例如1小时加3600000毫秒）。</span></p></li><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>性能考虑</span></strong><span>：多次请求可能导致较长执行时间，建议在非高峰期操作，并考虑使用异步请求库如aiohttp以提高效率。</span></p></li><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>数据存储</span></strong><span>：获取大量数据后，建议保存为CSV或数据库，方便后续分析，避免重复请求。</span></p></li><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>API变更风险</span></strong><span>：限制可能随Binance政策更新而变化，建议定期查阅</span><span>Binance API Documentation</span><span>以获取最新信息。</span></p></li></ul><p style=\\\"margin:0;margin-bottom:16px;margin-top:8px\\\"><span>最后，建议你实时监控API请求的状态，记录成功率和响应时间。根据监控结果，动态调整请求策略，确保数据获取的稳定性和效率。</span></p><div style=\\\"margin: 10px auto;display: flex;max-inline-size: 100%;\\\"><div style=\\\"flex-shrink: 0;background-color: rgb(41, 108, 212);display: flex;max-inline-size: 100%;\\\"><div style=\\\"padding: 4px 4px 4px 10px;font-size: 16px;letter-spacing: 1.5px;color: rgb(255, 255, 255);max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>3.</span></strong><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><span>3</span></strong></span></div><div style=\\\"flex-shrink: 0;max-inline-size: 100%;\\\"><div style=\\\"width: 6px;height: 6px;background-color: rgb(255, 193, 73);max-inline-size: 100%;\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div></div><div style=\\\"border-top: 1px solid rgb(41, 108, 212);border-right: 1px solid rgb(41, 108, 212);border-bottom: 1px solid rgb(41, 108, 212);display: flex;align-items: center;width: 100%;border-left: none;max-inline-size: 100%;\\\"><div style=\\\"padding-right: 10px;padding-left: 10px;font-size: 16px;color: rgb(41, 108, 212);text-align: left;letter-spacing: 1.5px;max-inline-size: 100%;\\\"><span style=\\\"font-size: 20px;\\\"><strong style=\\\"cursor: text;max-inline-size: 100%;\\\"><strong><span><span style=\\\"font-size: 18px;\\\">实战源代码下载</span></span></strong></strong></span></div></div></div><p style=\\\"margin:0;margin-top:16px;margin-bottom:8px\\\"><span>以上源代码请在我的Google Colab中申请下载，内附详细的中文代码构建与执行说明。</span></p><div><span><img src=\\\":/f36b027459e744709abaef2a4fcf3e57\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;\\\"/></span></div><div style=\\\"margin-top: 8px;margin-bottom: 24px;letter-spacing: 0.578px;\\\"><span style=\\\"font-weight: normal;font-size: 16px;\\\"><span style=\\\"font-weight: normal;font-size: 16px;\\\"><span style=\\\"font-weight: normal;font-size: 16px;\\\"><span style=\\\"font-weight: normal;font-size: 16px;\\\"><span><span style=\\\"font-size: 17px;\\\">如对您所帮助，</span></span></span></span><span><span style=\\\"font-size: 17px;\\\">记得请我喝杯咖啡</span><img src=\\\"如何绕过交易所 API 限制，高效获取数据？这些技巧你必须知道！_files/Expression_61@2x.png.\\\" type=\\\"image/webp\\\" data-filename=\\\"Expression_61@2x.png.\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;display:inline-block;width:20px;vertical-align:middle;background-size:cover;\\\"/></span><span><span style=\\\"font-size: 17px;\\\">就好</span></span><span><span style=\\\"font-size: 17px;\\\">。</span></span></span><span><br/></span></span><span style=\\\"font-weight: normal;font-size: 16px;\\\"><span><span style=\\\"font-size: 15px;font-style: italic;text-decoration: underline;\\\">https://colab.research.google.com/drive/1Og2QRWp3t1wdVviIj4Ui0CAkWQOMG1aI?usp=sharing</span></span></span><span><br/></span><div><div style=\\\"margin: 16px auto 20px;\\\"><div style=\\\"display: flex;justify-content: space-between;align-items: center;\\\"><div><div style=\\\"text-align: left;letter-spacing: 1.5px;\\\"><strong><span style=\\\"font-size: 24px;color: rgb(217, 33, 66);\\\"><span>④观点总结</span></span></strong></div><div style=\\\"display: flex;align-items: center;\\\"><div style=\\\"flex-shrink: 0;\\\"><div style=\\\"width: 14px;height: 14px;background-color: rgb(255, 205, 69);\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div><div style=\\\"font-size: 14px;color: rgb(222, 222, 222);text-align: left;padding-right: 4px;padding-left: 4px;\\\"><strong><span> Summary of Views</span></strong></div></div></div><div style=\\\"flex-shrink: 0;\\\"><div style=\\\"font-size: 30px;letter-spacing: 1.5px;color: rgb(255, 255, 255);width: 45px;height: 45px;line-height: 45px;text-align: center;background-color: rgb(255, 215, 106);\\\"><strong><span>04</span></strong><strong><span><br/></span></strong></div></div></div></div></div><p style=\\\"margin:0;margin-bottom:16px;margin-top:8px\\\"><span>本文详细介绍了如何绕过API（以Binance为例）的请求限制，高效获取数据。通过分批请求和分页技术，再结合前面提到的多账户、多IP技术，数字金融从业者可以有效绕过各个交易所 API的K线数据限制，获取所需的历史市场数据。结合上述代码和最佳实践，用户可轻松实现自动化数据获取，助力交易策略回测和市场分析。以下是关键点总结：</span></p><ul style=\\\"margin:0;list-style-type:disc\\\"><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>多账户轮换</span></strong><span>：轮换使用多个API密钥，分散请求压力，提升效率。</span></p></li><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>使用代理IP</span></strong><span>：通过代理IP池分散请求来源，避免IP被封禁。</span></p></li><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>调整请求频率</span></strong><span>：加入随机延迟，模拟人类操作，降低触发风控的风险。</span></p></li><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>利用WebSocket</span></strong><span>：使用WebSocket协议实时获取数据，减少HTTP请求频率。</span></p></li><li><p style=\\\"margin:0;margin-bottom:8px;margin-top:8px\\\"><strong><span>分批次请求</span></strong><span>：将大请求拆分为多个小请求，分散在不同时间窗口内完成。</span></p></li></ul><h2 style=\\\"margin:0;margin-top:16px;margin-bottom:8px;font-size:17px\\\"><span><br/></span></h2><div style=\\\"color: rgb(51, 51, 51);font-size: 14px;text-shadow: none;letter-spacing: 1.5px;margin-top: 4px;margin-bottom: 4px;line-height: 1.75em;font-family: 微软雅黑;\\\"><span style=\\\"border-bottom: 1px dashed rgb(115, 210, 202);line-height: 1.71em;font-size: 15px;\\\"><span>感谢阅读！愿本文为您带来新启发与实用知识。若觉有益，请点赞分享，您的支持是我创作的动力，欢迎留言必复。祝投资顺利，收益丰厚！</span></span></div><div><div style=\\\"margin: 10px auto;background-color: #f7f7f7;\\\"><div style=\\\"display: flex;align-items: center;\\\"><div style=\\\"width: 40%;max-width: 40% !important;\\\"><div style=\\\"width: 7em;margin-right: auto;margin-left: auto;\\\"><img src=\\\":/1d91b25a34e741739d490957cbbedc3d\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" alt=\\\"图片\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;vertical-align: baseline;text-align: center;font-size: var(--articleFontsize);letter-spacing: 0.034em;width: 100%;\\\"/></div></div><div style=\\\"width: 60%;display: flex;align-items: center;max-width: 60% !important;\\\"><div style=\\\"width: 100%;\\\"><span style=\\\"display: block;\\\"><span><span><span><span style=\\\"fill:#234aa5;fill-rule:evenodd;\\\"></span></span><span><span style=\\\"fill:#2a53b1;fill-rule:evenodd;\\\"></span></span></span></span></span></div><div style=\\\"width: 100%;margin-left: -100.1%;z-index: 4;display: flex;justify-content: center;align-items: center;\\\"><div><div style=\\\"display: flex;justify-content: flex-start;align-items: center;\\\"><div style=\\\"flex-shrink: 0;padding-right: 10px;\\\"><div style=\\\"width: 8px;height: 8px;background-color: rgb(255, 239, 183);\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div><div><div style=\\\"font-size: 12px;color: rgb(255, 255, 255);letter-spacing: 1.5px;line-height: 1.75em;\\\"><span>微信号 | 老余捞鱼</span></div></div></div><div style=\\\"display: flex;justify-content: flex-start;align-items: center;\\\"><div style=\\\"flex-shrink: 0;padding-right: 10px;\\\"><div style=\\\"width: 8px;height: 8px;background-color: rgb(255, 239, 183);\\\"><p style=\\\"margin:0\\\"><span><br/></span></p></div></div><div><div style=\\\"font-size: 12px;color: #ffffff;text-align: right;letter-spacing: 1.5px;line-height: 1.75em;\\\"><span>www.LaoYuLaoyu.com</span></div></div></div></div></div></div></div></div></div><div style=\\\"color: rgb(51, 51, 51);font-size: 14px;text-shadow: none;letter-spacing: 1.5px;margin-bottom: 4px;line-height: 1.75em;text-indent: 0em;text-align: center;font-family: 微软雅黑;\\\"><span style=\\\"line-height: 1.6;letter-spacing: 0.034em;font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;font-size: 13px;color: rgb(136, 136, 136);\\\">本文内容仅限技术探讨和学习，不构成任何投资建议。</span></div><div><div style=\\\"text-align: right;padding-top: 10px;padding-bottom: 10px;\\\"><div style=\\\"display: flex;justify-content: flex-end;align-items: center;padding-right: 6px;padding-left: 6px;\\\"><div style=\\\"width: 30px;overflow: hidden;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(118, 199, 235);transform: rotate(0deg);\\\"><img src=\\\":/a1fd1e28d3a54ceca74369beaddf259c\\\" type=\\\"image/gif\\\" data-filename=\\\"640.gif\\\" alt=\\\"图片\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;display: block;vertical-align: baseline;width: 100%;\\\" width=\\\"100%\\\"/></div><div style=\\\"display: inline-block;margin-left:10px;\\\"><div style=\\\"letter-spacing: 1.5px;margin-left:-6px;font-size:30px;color: #01c7f4;text-align: center;\\\"><span>财神都在点赞</span></div><div style=\\\"margin-top: -33px;letter-spacing: 1.5px;font-size: 14px;color: #01c7f4;text-align: center;transform: rotate(0deg);-webkit-transform: rotate(0deg);-moz-transform: rotate(0deg);-o-transform: rotate(0deg);\\\"><span>请用您发财的手：分享、在看和赞一下，谢谢！</span></div><div style=\\\"width: 15px;float: right;margin-top: 5px;margin-right: 10px;\\\"><img src=\\\":/2729e3dead0e4fa0908edecb775f0c1a\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" alt=\\\"图片\\\" style=\\\"--en-marks:%7B%22align%22%3A%22center%22%7D;display: block;background: none rgb(1, 199, 244);opacity: 1;;.1;vertical-align: baseline;width: 100%;\\\"/></div></div></div></div></div><div><span></span></div></div></div></div></div></div></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":34732}]"
metadata_diff: {"new":{"id":"506caf56137e4a8e9b662879dc21b5da","parent_id":"f67288c3a0be4374b5d532b5dcc3aabc","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764348846674,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T21:04:33.548Z
created_time: 2025-11-28T21:04:33.548Z
type_: 13