{"id":10617,"date":"2026-01-21T18:18:28","date_gmt":"2026-01-21T10:18:28","guid":{"rendered":"https:\/\/blog.alltick.co\/zh-CN\/?p=10617"},"modified":"2026-01-21T18:22:39","modified_gmt":"2026-01-21T10:22:39","slug":"python-%e6%8e%a5%e5%85%a5%e5%a4%96%e6%b1%87%e8%a1%8c%e6%83%85api%ef%bc%9a%e9%ab%98%e9%a2%91%e6%95%b0%e6%8d%ae%e4%b8%8e%e7%ad%96%e7%95%a5%e5%8f%af%e8%a7%86%e5%8c%96%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/blog.alltick.co\/zh-CN\/python-%e6%8e%a5%e5%85%a5%e5%a4%96%e6%b1%87%e8%a1%8c%e6%83%85api%ef%bc%9a%e9%ab%98%e9%a2%91%e6%95%b0%e6%8d%ae%e4%b8%8e%e7%ad%96%e7%95%a5%e5%8f%af%e8%a7%86%e5%8c%96%e5%ae%9e%e8%b7%b5\/","title":{"rendered":"\u7528\u5916\u6c47\u884c\u60c5API\u8f7b\u677e\u83b7\u53d6\u9ad8\u9891\u6570\u636e\u505a\u7b56\u7565\u56de\u6d4b"},"content":{"rendered":"\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"410\" data-id=\"10618\" src=\"https:\/\/i0.wp.com\/blog.alltick.co\/zh-CN\/wp-content\/uploads\/2026\/01\/Python-%E6%8E%A5%E5%85%A5%E5%A4%96%E6%B1%87%E8%A1%8C%E6%83%85-API-%E5%8F%8A%E9%85%8D%E5%9B%BE.png?resize=800%2C410&#038;ssl=1\" alt=\"\" class=\"wp-image-10618\" srcset=\"https:\/\/i0.wp.com\/blog.alltick.co\/zh-CN\/wp-content\/uploads\/2026\/01\/Python-%E6%8E%A5%E5%85%A5%E5%A4%96%E6%B1%87%E8%A1%8C%E6%83%85-API-%E5%8F%8A%E9%85%8D%E5%9B%BE-scaled.png?resize=1024%2C525&amp;ssl=1 1024w, https:\/\/i0.wp.com\/blog.alltick.co\/zh-CN\/wp-content\/uploads\/2026\/01\/Python-%E6%8E%A5%E5%85%A5%E5%A4%96%E6%B1%87%E8%A1%8C%E6%83%85-API-%E5%8F%8A%E9%85%8D%E5%9B%BE-scaled.png?resize=300%2C154&amp;ssl=1 300w, https:\/\/i0.wp.com\/blog.alltick.co\/zh-CN\/wp-content\/uploads\/2026\/01\/Python-%E6%8E%A5%E5%85%A5%E5%A4%96%E6%B1%87%E8%A1%8C%E6%83%85-API-%E5%8F%8A%E9%85%8D%E5%9B%BE-scaled.png?resize=768%2C394&amp;ssl=1 768w, https:\/\/i0.wp.com\/blog.alltick.co\/zh-CN\/wp-content\/uploads\/2026\/01\/Python-%E6%8E%A5%E5%85%A5%E5%A4%96%E6%B1%87%E8%A1%8C%E6%83%85-API-%E5%8F%8A%E9%85%8D%E5%9B%BE-scaled.png?resize=1536%2C787&amp;ssl=1 1536w, https:\/\/i0.wp.com\/blog.alltick.co\/zh-CN\/wp-content\/uploads\/2026\/01\/Python-%E6%8E%A5%E5%85%A5%E5%A4%96%E6%B1%87%E8%A1%8C%E6%83%85-API-%E5%8F%8A%E9%85%8D%E5%9B%BE-scaled.png?resize=2048%2C1050&amp;ssl=1 2048w, https:\/\/i0.wp.com\/blog.alltick.co\/zh-CN\/wp-content\/uploads\/2026\/01\/Python-%E6%8E%A5%E5%85%A5%E5%A4%96%E6%B1%87%E8%A1%8C%E6%83%85-API-%E5%8F%8A%E9%85%8D%E5%9B%BE-scaled.png?w=1600&amp;ssl=1 1600w, https:\/\/i0.wp.com\/blog.alltick.co\/zh-CN\/wp-content\/uploads\/2026\/01\/Python-%E6%8E%A5%E5%85%A5%E5%A4%96%E6%B1%87%E8%A1%8C%E6%83%85-API-%E5%8F%8A%E9%85%8D%E5%9B%BE-scaled.png?w=2400&amp;ssl=1 2400w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>\u5728\u91cf\u5316\u4ea4\u6613\u6216\u5916\u6c47\u5de5\u5177\u5f00\u53d1\u4e2d\uff0c\u4ec5\u83b7\u53d6\u5b9e\u65f6\u6c47\u7387\u8fdc\u8fdc\u4e0d\u591f\u3002\u5f00\u53d1\u8005\u5f80\u5f80\u9700\u8981\u9ad8\u9891\u6570\u636e\u6765\u8fdb\u884c\u7b56\u7565\u56de\u6d4b\u3001\u98ce\u9669\u5206\u6790\u6216\u53ef\u89c6\u5316\u76d1\u63a7\u3002\u672c\u6587\u4ee5 <strong>Python<\/strong> \u4e3a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u63a5\u5165 <a href=\"http:\/\/alltick.co\" target=\"_blank\" rel=\"noopener\"><strong>AllTick API<\/strong> <\/a>\u83b7\u53d6\u9ad8\u9891\u5916\u6c47\u884c\u60c5\uff0c\u5e76\u5b9e\u73b0 K \u7ebf\u53ef\u89c6\u5316\u548c\u7b80\u5355\u7b56\u7565\u56de\u6d4b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u73af\u5883\u51c6\u5907\u4e0e\u4f9d\u8d56<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>pip install requests pandas matplotlib mplfinance<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>requests\uff1a\u8c03\u7528\u5916\u6c47 API<\/li>\n\n\n\n<li>pandas\uff1a\u5904\u7406\u9ad8\u9891\u6570\u636e<\/li>\n\n\n\n<li>matplotlib \u4e0e mplfinance\uff1a\u7ed8\u5236 K \u7ebf\u56fe\u548c\u884c\u60c5\u66f2\u7ebf<\/li>\n<\/ul>\n\n\n\n<p>\u786e\u4fdd\u5df2\u6ce8\u518c AllTick API \u5e76\u83b7\u53d6 API Key\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u83b7\u53d6\u9ad8\u9891\u5916\u6c47\u6570\u636e<\/strong><\/h2>\n\n\n\n<p>\u4e0b\u9762\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u83b7\u53d6 EUR\/USD \u7684\u9ad8\u9891 Tick \u6570\u636e\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>import requests<br>import pandas as pd<br><br>API_URL = &#8220;https:\/\/api.alltick.com\/forex\/tick&#8221;<br>API_KEY = &#8220;your_api_key_here&#8221;<br><br>params = {<br>&nbsp; &nbsp; &#8220;symbol&#8221;: &#8220;EURUSD&#8221;,<br>&nbsp; &nbsp; &#8220;interval&#8221;: &#8220;1s&#8221;,&nbsp; # \u6bcf\u79d2\u4e00\u4e2a tick<br>&nbsp; &nbsp; &#8220;limit&#8221;: 500,&nbsp; &nbsp; &nbsp; # \u83b7\u53d6\u6700\u8fd1 500 \u6761\u6570\u636e<br>&nbsp; &nbsp; &#8220;apikey&#8221;: API_KEY<br>}<br><br>resp = requests.get(API_URL, params=params)<br>data = resp.json()<br><br>df = pd.DataFrame(data)<br>df[&#8216;timestamp&#8217;] = pd.to_datetime(df[&#8216;timestamp&#8217;])<br>print(df.head())<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u901a\u8fc7 interval \u53c2\u6570\uff0c\u53ef\u4ee5\u83b7\u53d6\u4e0d\u540c\u9891\u7387\u7684\u6570\u636e\uff0c\u4fbf\u4e8e\u9ad8\u9891\u7b56\u7565\u56de\u6d4b\u6216\u5b9e\u65f6\u76d1\u63a7\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>K \u7ebf\u53ef\u89c6\u5316\u793a\u4f8b<\/strong><\/h2>\n\n\n\n<p>\u5c06\u9ad8\u9891 Tick \u6570\u636e\u8f6c\u6362\u4e3a K \u7ebf\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>import mplfinance as mpf<br><br># \u5c06 Tick \u6570\u636e\u6309\u5206\u949f\u805a\u5408\u4e3a OHLC<br>df_ohlc = df.resample(&#8216;1T&#8217;, on=&#8217;timestamp&#8217;).agg({<br>&nbsp; &nbsp; &#8216;price&#8217;: [&#8216;first&#8217;, &#8216;max&#8217;, &#8216;min&#8217;, &#8216;last&#8217;],<br>&nbsp; &nbsp; &#8216;volume&#8217;: &#8216;sum&#8217;<br>})<br>df_ohlc.columns = [&#8216;Open&#8217;, &#8216;High&#8217;, &#8216;Low&#8217;, &#8216;Close&#8217;, &#8216;Volume&#8217;]<br><br>mpf.plot(df_ohlc, type=&#8217;candle&#8217;, volume=True, style=&#8217;yahoo&#8217;, title=&#8217;EUR\/USD \u5206\u949fK\u7ebf&#8217;)<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 resample \u53ef\u4ee5\u7075\u6d3b\u751f\u6210\u4e0d\u540c\u5468\u671f K \u7ebf<\/li>\n\n\n\n<li>\u53ef\u76f4\u63a5\u89c2\u5bdf\u4ef7\u683c\u6ce2\u52a8\uff0c\u4e3a\u7b56\u7565\u5206\u6790\u63d0\u4f9b\u76f4\u89c2\u53c2\u8003<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u7b80\u5355\u7b56\u7565\u56de\u6d4b<\/strong><\/h2>\n\n\n\n<p>\u4ee5\u5747\u7ebf\u4ea4\u53c9\u4e3a\u4f8b\uff0c\u5b9e\u73b0\u7b80\u5355\u7684\u4ea4\u6613\u4fe1\u53f7\u56de\u6d4b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>df_ohlc[&#8216;MA5&#8217;] = df_ohlc[&#8216;Close&#8217;].rolling(5).mean()<br>df_ohlc[&#8216;MA20&#8217;] = df_ohlc[&#8216;Close&#8217;].rolling(20).mean()<br><br># \u751f\u6210\u4ea4\u6613\u4fe1\u53f7<br>df_ohlc[&#8216;signal&#8217;] = 0<br>df_ohlc.loc[df_ohlc[&#8216;MA5&#8217;] &gt; df_ohlc[&#8216;MA20&#8217;], &#8216;signal&#8217;] = 1 &nbsp; # \u4e70\u5165\u4fe1\u53f7<br>df_ohlc.loc[df_ohlc[&#8216;MA5&#8217;] &lt; df_ohlc[&#8216;MA20&#8217;], &#8216;signal&#8217;] = -1&nbsp; # \u5356\u51fa\u4fe1\u53f7<br><br>print(df_ohlc[[&#8216;Close&#8217;, &#8216;MA5&#8217;, &#8216;MA20&#8217;, &#8216;signal&#8217;]].tail())<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5747\u7ebf\u4ea4\u53c9\u4fe1\u53f7\u53ef\u7528\u4e8e\u81ea\u52a8\u5316\u4ea4\u6613\u7b56\u7565<\/li>\n\n\n\n<li>\u53ef\u4ee5\u7ed3\u5408 AllTick \u5386\u53f2\u6570\u636e\u505a\u56de\u6d4b\uff0c\u8bc4\u4f30\u7b56\u7565\u6548\u679c<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u591a\u8d27\u5e01\u5bf9\u76d1\u63a7\u4e0e\u6269\u5c55<\/strong><\/h2>\n\n\n\n<p>\u5f00\u53d1\u8005\u53ef\u4ee5\u540c\u65f6\u76d1\u63a7\u591a\u4e2a\u8d27\u5e01\u5bf9\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>symbols = [&#8216;EURUSD&#8217;, &#8216;GBPUSD&#8217;, &#8216;USDJPY&#8217;]<br>dfs = []<br><br>for s in symbols:<br>&nbsp; &nbsp; params[&#8216;symbol&#8217;] = s<br>&nbsp; &nbsp; resp = requests.get(API_URL, params=params).json()<br>&nbsp; &nbsp; dfs.append(pd.DataFrame(resp))<br><br>all_data = pd.concat(dfs)<br>all_data[&#8216;timestamp&#8217;] = pd.to_datetime(all_data[&#8216;timestamp&#8217;])<br>print(all_data.head())<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5408\u5e76\u6570\u636e\u4fbf\u4e8e\u505a\u591a\u54c1\u79cd\u5206\u6790\u6216\u8de8\u8d27\u5e01\u5bf9\u7b56\u7565\u56de\u6d4b<\/li>\n\n\n\n<li>\u4f7f\u7528 AllTick API \u7684\u9ad8\u9891\u6570\u636e\uff0c\u53ef\u5feb\u901f\u642d\u5efa\u4ea4\u6613\u76d1\u63a7\u4eea\u8868\u76d8<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5f00\u53d1\u8005\u5b9e\u8df5\u5c0f\u6280\u5de7<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u63a5\u53e3\u9650\u6d41<\/strong>\uff1a\u9ad8\u9891\u8bf7\u6c42\u65f6\uff0c\u5efa\u8bae\u52a0\u5ef6\u65f6\u6216\u4f7f\u7528\u6279\u91cf\u8bf7\u6c42<\/li>\n\n\n\n<li><strong>\u5f02\u5e38\u5904\u7406<\/strong>\uff1a\u6355\u83b7\u7f51\u7edc\u9519\u8bef\u3001\u6570\u636e\u7f3a\u5931\uff0c\u4fdd\u8bc1\u7a0b\u5e8f\u7a33\u5b9a<\/li>\n\n\n\n<li><strong>\u7f13\u5b58\u7b56\u7565<\/strong>\uff1a\u9488\u5bf9\u5386\u53f2\u6570\u636e\uff0c\u53ef\u5b58\u5165\u672c\u5730\u6570\u636e\u5e93\u63d0\u9ad8\u5206\u6790\u6548\u7387<\/li>\n\n\n\n<li><strong>\u53ef\u89c6\u5316\u4f18\u5316<\/strong>\uff1a\u7ed3\u5408 Plotly \u6216 Dash\uff0c\u53ef\u5b9e\u73b0\u4ea4\u4e92\u5f0f\u5b9e\u65f6\u76d1\u63a7<\/li>\n<\/ul>\n\n\n\n<p>\u901a\u8fc7\u8fd9\u4e00\u6d41\u7a0b\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u4ece\u9ad8\u9891 Tick \u6570\u636e\u5230 K \u7ebf\u53ef\u89c6\u5316\uff0c\u518d\u5230\u7b56\u7565\u56de\u6d4b\uff0c\u5168\u6d41\u7a0b\u5feb\u901f\u5b9e\u8df5\uff0c\u5229\u7528<a href=\"http:\/\/alltick.co\" target=\"_blank\" rel=\"noopener\"> <strong>AllTick API<\/strong> <\/a>\u9ad8\u6548\u83b7\u53d6\u53ef\u9760\u6570\u636e\uff0c\u652f\u6491\u91cf\u5316\u4ea4\u6613\u548c\u5916\u6c47\u5de5\u5177\u5f00\u53d1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u91cf\u5316\u4ea4\u6613\u6216\u5916\u6c47\u5de5\u5177\u5f00\u53d1\u4e2d\uff0c\u4ec5\u83b7\u53d6\u5b9e\u65f6\u6c47\u7387\u8fdc\u8fdc\u4e0d\u591f\u3002\u5f00\u53d1\u8005\u5f80\u5f80\u9700\u8981\u9ad8\u9891\u6570\u636e\u6765\u8fdb\u884c\u7b56\u7565\u56de\u6d4b\u3001\u98ce\u9669\u5206\u6790\u6216\u53ef\u89c6\u5316\u76d1\u63a7&#8230;<\/p>\n","protected":false},"author":5,"featured_media":10619,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-10617","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tick-data-wiki"],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/posts\/10617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/comments?post=10617"}],"version-history":[{"count":2,"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/posts\/10617\/revisions"}],"predecessor-version":[{"id":10621,"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/posts\/10617\/revisions\/10621"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/media\/10619"}],"wp:attachment":[{"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/media?parent=10617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/categories?post=10617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alltick.co\/zh-CN\/wp-json\/wp\/v2\/tags?post=10617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}