{"id":116,"date":"2025-06-17T03:43:13","date_gmt":"2025-06-17T03:43:13","guid":{"rendered":"https:\/\/blog.alltick.co\/ja-jp\/?p=116"},"modified":"2025-06-17T03:43:14","modified_gmt":"2025-06-17T03:43:14","slug":"python-quantitative-trading-how-to-access-financial-market-data","status":"publish","type":"post","link":"https:\/\/blog.alltick.co\/ja-jp\/python-quantitative-trading-how-to-access-financial-market-data\/","title":{"rendered":"Python\u306b\u3088\u308b\u91cf\u7684\u53d6\u5f15: \u91d1\u878d\u5e02\u5834\u30c7\u30fc\u30bf\u3078\u306e\u30a2\u30af\u30bb\u30b9\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Python\u3092\u4f7f\u7528\u3057\u3066\u4e8b\u524d\u30d1\u30c3\u30b1\u30fc\u30b8\u5316\u3055\u308c\u305f\u9ad8\u983b\u5ea6\u30c7\u30fc\u30bfAPI\u3092\u547c\u3073\u51fa\u3059\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001Alltick\u306e\u30c6\u30a3\u30c3\u30af\u30c7\u30fc\u30bf\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f8b\u3068\u3057\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u4e00\u90e8\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u30ed\u30fc\u30bd\u30af\u8db3\u30c7\u30fc\u30bf\u306e\u30ea\u30af\u30a8\u30b9\u30c8<\/strong><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import time\nimport requests\nimport json\n \n# Extra headers\ntest_headers = {\n    'Content-Type':'application\/json'\n}\n \n'''\ngithub\uff1ahttps:\/\/github.com\/alltick\/realtime-forex-crypto-stock-tick-finance-websocket-api\n\n{\"trace\":\"python_http_test1\",\"data\":{\"code\":\"AAPL.US\",\"kline_type\":1,\"kline_timestamp_end\":0,\"query_kline_num\":2,\"adjust_type\":0}}\n'''\ntest_url1 = 'https:\/\/quote.alltick.io\/quote-stock-b-api\/kline?token=e945d7d9-9e6e-4721-922a-7251a9d311d0-1678159756806&amp;query=%7B%22trace%22%3A%22python_http_test1%22%2C%22data%22%3A%7B%22code%22%3A%22AAPL.US%22%2C%22kline_type%22%3A1%2C%22kline_timestamp_end%22%3A0%2C%22query_kline_num%22%3A2%2C%22adjust_type%22%3A0%7D%7D'\n \nresp1 = requests.get(url=test_url1, headers=test_headers)\n \n# Decoded text returned by the request\ntext1 = resp1.text\nprint(text1)<\/pre>\n\n\n\n<p>\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001Apple\u682a\uff08AAPL.US\uff09\u3092\u4f8b\u306b\u3057\u3066\u30011\u5206\u5358\u4f4d\u306eK\u30e9\u30a4\u30f3\u30c7\u30fc\u30bf\u3092\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u3066\u3044\u307e\u3059\u3002\u4ed6\u306eK\u30e9\u30a4\u30f3\u30bf\u30a4\u30d7\u3092\u30ea\u30af\u30a8\u30b9\u30c8\u3059\u308b\u5834\u5408\u306f\u3001kline_type\u306b\u4ee5\u4e0b\u306e\u5024\u3092\u6e21\u3057\u307e\u3059\uff1a<br>1 &#8211; 1\u5206\u30012 &#8211; 5\u5206\u30013 &#8211; 15\u5206\u30014 &#8211; 30\u5206\u3001<br>5 &#8211; 1\u6642\u9593\u30016 &#8211; 2\u6642\u9593\u30017 &#8211; 4\u6642\u9593\u30018 &#8211; \u65e5\u6b21\u3001<br>9 &#8211; \u9031\u6b21\u300110 &#8211; \u6708\u6b21\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6700\u65b0\u306e\u5f15\u7528\u3068\u53d6\u5f15\u30c7\u30fc\u30bf\u306e\u30ea\u30af\u30a8\u30b9\u30c8<\/strong><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import time\nimport requests\nimport json\n \n# Extra headers\ntest_headers = {\n    'Content-Type':'application\/json'\n}\n \n'''\ngithub\uff1ahttps:\/\/github.com\/alltick\/realtime-forex-crypto-stock-tick-finance-websocket-api\n\n{\"trace\":\"python_http_test2\",\"data\":{\"symbol_list\":[{\"code\": \"700.HK\"},{\"code\": \"UNH.US\"},{\"code\": \"600416.SH\"}]}}\n'''\ntest_url1 = 'https:\/\/quote.alltick.io\/quote-stock-b-api\/trade-tick?token=e945d7d9-9e6e-4721-922a-7251a9d311d0-1678159756806&amp;query=%7B%22trace%22%3A%22python_http_test2%22%2C%22data%22%3A%7B%22symbol_list%22%3A%5B%7B%22code%22%3A%20%22700.HK%22%7D%2C%7B%22code%22%3A%20%22UNH.US%22%7D%2C%7B%22code%22%3A%20%22600416.SH%22%7D%5D%7D%7D'\n \nresp1 = requests.get(url=test_url1, headers=test_headers)\n \n# Decoded text returned by the request\ntext1 = resp1.text\nprint(text1)<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001symbol_list\u306b\u306f\u8907\u6570\u306e\u30b7\u30f3\u30dc\u30eb\u3092\u542b\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u7570\u306a\u308b\u5e02\u5834\u306e\u88fd\u54c1\u3082\u542b\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u6700\u65b0\u306e\u6ce8\u6587\u7c3f\u306e\u5f15\u7528\u30c7\u30fc\u30bf\u306e\u53d6\u5f97<\/strong><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import time\nimport requests\nimport json\n \n# Extra headers\ntest_headers = {\n    'Content-Type':'application\/json'\n}\n \n'''\ngithub\uff1ahttps:\/\/github.com\/alltick\/realtime-forex-crypto-stock-tick-finance-websocket-api\n\n{\"trace\":\"python_http_test2\",\"data\":{\"symbol_list\":[{\"code\": \"700.HK\"},{\"code\": \"UNH.US\"},{\"code\": \"600416.SH\"}]}}\n'''\ntest_url1 = 'https:\/\/quote.alltick.io\/quote-stock-b-api\/depth-tick?token=e945d7d9-9e6e-4721-922a-7251a9d311d0-1678159756806&amp;query=%7B%22trace%22%3A%22python_http_test2%22%2C%22data%22%3A%7B%22symbol_list%22%3A%5B%7B%22code%22%3A%20%22700.HK%22%7D%2C%7B%22code%22%3A%20%22UNH.US%22%7D%2C%7B%22code%22%3A%20%22600416.SH%22%7D%5D%7D%7D'\n \nresp1 = requests.get(url=test_url1, headers=test_headers)\n \n# Decoded text returned by the request\ntext1 = resp1.text\nprint(text1)<\/pre>\n\n\n\n<p>\u540c\u69d8\u306b\u3001symbol_list\u306f\u8907\u6570\u306e\u30a8\u30f3\u30c8\u30ea\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>WebSocket\u3092\u901a\u3058\u305f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u5e02\u5834\u30c7\u30fc\u30bf\u306e\u8cfc\u8aad<\/strong><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import json\nimport websocket    # pip install websocket-client\n \nclass Feed(object):\n \n    def __init__(self):\n        self.url = 'wss:\/\/quote.alltick.io\/quote-stock-b-ws-api?token=e945d7d9-9e6e-4721-922a-7251a9d311d0-1678159756806'  \n        self.ws = None\n \n    def on_open(self, ws):\n        \"\"\"\n        Callback object which is called at opening websocket.\n        1 argument:\n        @ ws: the WebSocketApp object\n        \"\"\"\n        print('A new WebSocketApp is opened!')\n \n        sub_param = {\n            \"cmd_id\": 22002, \n            \"seq_id\": 123,\n            \"trace\":\"3baaa938-f92c-4a74-a228-fd49d5e2f8bc-1678419657806\",\n            \"data\":{\n                \"symbol_list\":[\n                    {\n                        \"code\": \"700.HK\",\n                        \"depth_level\": 5,\n                    },\n                    {\n                        \"code\": \"UNH.US\",\n                        \"depth_level\": 5,\n                    },\n                    {\n                        \"code\": \"600416.SH\",\n                        \"depth_level\": 5,\n                    }\n                ]\n            }\n        }\n        \n        sub_str = json.dumps(sub_param)\n        ws.send(sub_str)\n        print(\"depth quote are subscribed!\")\n \n    def on_data(self, ws, string, type, continue_flag):\n        \"\"\"\n        4 argument.\n        The 1st argument is this class object.\n        The 2nd argument is utf-8 string which we get from the server.\n        The 3rd argument is data type. ABNF.OPCODE_TEXT or ABNF.OPCODE_BINARY will be came.\n        The 4th argument is continue flag. If 0, the data continue\n        \"\"\"\n \n    def on_message(self, ws, message):\n        \"\"\"\n        Callback object which is called when received data.\n        2 arguments:\n        @ ws: the WebSocketApp object\n        @ message: utf-8 data received from the server\n        \"\"\"\n        result = eval(message)\n        print(result)\n \n    def on_error(self, ws, error):\n        \"\"\"\n        Callback object which is called when got an error.\n        2 arguments:\n        @ ws: the WebSocketApp object\n        @ error: exception object\n        \"\"\"\n        print(error)\n \n    def on_close(self, ws, close_status_code, close_msg):\n        \"\"\"\n        Callback object which is called when the connection is closed.\n        2 arguments:\n        @ ws: the WebSocketApp object\n        @ close_status_code\n        @ close_msg\n        \"\"\"\n        print('The connection is closed!')\n \n    def start(self):\n        self.ws = websocket.WebSocketApp(\n            self.url,\n            on_open=self.on_open,\n            on_message=self.on_message,\n            on_data=self.on_data,\n            on_error=self.on_error,\n            on_close=self.on_close,\n        )\n        self.ws.run_forever()\n \n \nif __name__ == \"__main__\":\n    feed = Feed()\n    feed.start()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Python\u3092\u4f7f\u7528\u3057\u3066\u4e8b\u524d\u30d1\u30c3\u30b1\u30fc\u30b8\u5316\u3055\u308c\u305f\u9ad8\u983b\u5ea6\u30c7\u30fc\u30bfAPI\u3092\u547c\u3073\u51fa\u3059\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001Alltick\u306e\u30c6\u30a3\u30c3\u30af\u30c7\u30fc\u30bf\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f8b\u3068\u3057\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u4e00\u90e8\u3067\u3059\u3002 \u30ed\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":117,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-116","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide"],"featured_image_src":"https:\/\/i0.wp.com\/blog.alltick.co\/ja-jp\/wp-content\/uploads\/sites\/2\/2025\/06\/python-website-may-16-2022.webp?fit=1600%2C1067&ssl=1","author_info":{"display_name":"admin","author_link":"https:\/\/blog.alltick.co\/ja-jp\/author\/admin\/"},"_links":{"self":[{"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":1,"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/posts\/116\/revisions\/118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/media\/117"}],"wp:attachment":[{"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alltick.co\/ja-jp\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}