{"id":439,"date":"2021-12-29T22:33:58","date_gmt":"2021-12-29T14:33:58","guid":{"rendered":"\/?p=439"},"modified":"2023-09-23T18:40:59","modified_gmt":"2023-09-23T10:40:59","slug":"ptrade%e4%ba%a4%e6%98%93%e7%a8%8b%e5%ba%8f%e4%bb%a3%e7%a0%81-%e4%bb%8e%e9%9b%b6%e5%88%b0%e5%ae%9e%e7%9b%9819","status":"publish","type":"post","link":"\/?p=439","title":{"rendered":"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819"},"content":{"rendered":"<p>\u5982\u9898\uff0c\u672c\u6587\u5c06\u4ecb\u7ecdPTrade\u5b9e\u76d8\u4ea4\u6613\u7a0b\u5e8f\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u5982\u4f55\u5728PTrade\u4e2d\u90e8\u7f72\u7b56\u7565\uff0c\u53ef\u4ee5\u53c2\u89c1<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/coderx.com.cn\/?p=423\">\u524d\u6587<\/a>\u4e2d\u201cPTrade\u90e8\u7f72\u7b56\u7565\u8fc7\u7a0b\u201d\u90e8\u5206\u5185\u5bb9\uff0c\u7136\u540e\u628a\u672c\u6587\u7684\u4ee3\u7801\u7c98\u8d34\u5230PTrade\uff0c\u5c31\u80fd\u5b8c\u6210\u201c\u53cc\u795e\u7a7f\u591a\u7ebf\u201d\u7b56\u7565\u7684\u90e8\u7f72\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u5bf9\u7a0b\u5e8f\u7684\u5404\u4e2a\u51fd\u6570\u4f9d\u6b21\u8fdb\u884c\u4ecb\u7ecd\u3002<\/p>\n<h1>\u521d\u59cb\u5316\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def initialize(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u4e3aPTrade\u7684\u4e1a\u52a1\u6d41\u7a0b\u6846\u67b6\u7684\u5fc5\u9009\u51fd\u6570\uff0c\u5b9e\u73b0\u521d\u59cb\u5316\u529f\u80fd\uff0c\u7528\u4e8e\u521d\u59cb\u5316\u4e00\u4e9b\u5168\u5c40\u53d8\u91cf\u3002\u7b56\u7565\u542f\u52a8\u540e\uff0c\u8be5\u51fd\u6570\u4ec5\u4f1a\u88ab\u8c03\u7528\u4e00\u6b21\u3002<\/p>\n<ul>\n<li>\u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-python line-numbers\">    run_interval(context, interval_handle, seconds = 3)\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u4ee5\u8bbe\u5b9a\u65f6\u95f4\u95f4\u9694\uff08\u5355\u4f4d\u4e3a\u79d2\uff09\u5468\u671f\u6027\u8fd0\u884c\u6307\u5b9a\u51fd\u6570interval_handle\uff0c\u8fd9\u91cc\u6211\u4eec\u8bbe\u7f6eseconds = 3\uff0c\u4e5f\u5c31\u662f\u6bcf\u96943\u79d2\u8c03\u7528\u4e00\u6b21\u51fd\u6570interval_handle\uff0c\u8be5\u51fd\u6570\u7528\u4e8e\u5904\u7406\u4e70\u5356\u903b\u8f91\uff0c\u5c06\u5728\u540e\u6587\u4e2d\u5b9a\u4e49\u5b9e\u73b0\u3002<br \/>\n\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cseconds\u8bbe\u7f6e\u6700\u5c0f\u65f6\u95f4\u95f4\u9694\u4e3a3\u79d2\uff0c\u5c0f\u4e8e3\u79d2\u9ed8\u8ba4\u8bbe\u5b9a\u4e3a3\u79d2\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u6bcf\u6b21\u5904\u7406\u4ea4\u6613\u7684\u6700\u5c0f\u65f6\u95f4\u95f4\u9694\u4e3a3\u79d2\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.limit_value = 5000\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u8d44\u91d1\u5c11\u4e8elimit_value\u5219\u4e0d\u4e70\u5165\uff0c\u8fd9\u91cc\u6ce8\u610f\u5230\u5168\u5c40\u53d8\u91cf\u5747\u5df2g.\u5f00\u5934\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.limit_stock_num = 3\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u6301\u4ed3\u80a1\u7968\u53ea\u6570\u9650\u5236\uff0c\u6839\u636e\u56de\u6d4b\u7ed3\u679c\u6211\u4eec\u8bbe\u7f6e\u6700\u591a\u6301\u67093\u5f20\u80a1\u7968\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.limit_hold_days = 6\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u6301\u80a1\u5929\u6570\u9650\u5236\uff0c\u6839\u636e\u56de\u6d4b\u7ed3\u679c\u6211\u4eec\u8bbe\u7f6e\u5355\u53ea\u80a1\u7968\u6700\u591a\u6301\u67096\u5929\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.security = '000300.SS'\n    set_universe(g.security)\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u8981\u64cd\u4f5c\u7684\u80a1\u7968\u6c60\uff0c\u8fd9\u91cc\u6211\u4eec\u6dfb\u52a0\u6caa\u6df1300\u3002<\/p>\n<h1>\u76d8\u524d\u521d\u59cb\u5316\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def before_trading_start(context, data):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u4f1a\u5728\u6bcf\u5929\u5f00\u59cb\u4ea4\u6613\u524d\u88ab\u8c03\u7528\uff0c\u6b64\u5904\u6dfb\u52a0\u6bcf\u5929\u90fd\u8981\u521d\u59cb\u5316\u7684\u4fe1\u606f\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<br \/>\n&#8211; \u53c2\u6570data\u4e3a\u4fdd\u7559\u5b57\u6bb5\u6682\u65e0\u6570\u636e<br \/>\n\u5728\u8be5\u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u4f1a\u5c06\u5f85\u76d1\u6d4b\u548c\u4ea4\u6613\u7684\u80a1\u7968\u6dfb\u52a0\u5230\u80a1\u7968\u6c60\uff0c\u8bfb\u53d6\u80a1\u7968\u7684\u4e70\u70b9\u3001\u5356\u70b9\u6570\u636e\uff0c\u4ee5\u53ca\u5224\u65ad\u80a1\u7968\u662f\u5426\u8fbe\u5230\u6301\u80a1\u5929\u6570\u9650\u5236\uff0c\u9700\u8981\u7acb\u5373\u5356\u51fa\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.buy_submitted_set = set() \n<\/code><\/pre>\n<p>\u5f53\u65e5\u63d0\u4ea4\u4e70\u5355\u7684\u80a1\u7968\u4ee3\u7801\u96c6\u5408\uff0c\u7528\u4e8e\u907f\u514d\u540c\u4e00\u80a1\u7968\u7684\u4e70\u5355\u88ab\u91cd\u590d\u63d0\u4ea4\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    file_path = get_research_path() + 'upload_file\/trade_data.csv'\n    g.db_df = pd.read_csv(file_path, encoding='utf-8', converters={'code': str})\n<\/code><\/pre>\n<p>\u901a\u8fc7\u524d\u9762\u6587\u7ae0\u7684\u8bbe\u7f6e\uff0c\u6211\u4eec\u5c06\u5f85\u4ea4\u6613\u6570\u636e\u81ea\u52a8\u4e0a\u4f20\u5230\u7814\u7a76\u76ee\u5f55\u4e0bupload_file\u6587\u4ef6\u5939\u4e0b\uff0c\u8fd9\u91cc\u8bfb\u53d6\u5f85\u4ea4\u6613\u6570\u636e\uff0c\u4f9b\u5b9e\u76d8\u4f7f\u7528\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.db_df['code_ptrade'] = g.db_df['code'].map(lambda x: x + '.SS' if '6' == x[0] else x + '.SZ')\n<\/code><\/pre>\n<p>\u7531\u4e8ePTrade\u7684\u80a1\u7968\u4ee3\u7801\u662f\u5728\u6570\u5b57\u540e\u6dfb\u52a0.SS\u6216\u8005.SZ\uff0c\u8fd9\u91cc\u6211\u4eec\u5bf9\u80a1\u7968\u4ee3\u7801\u8fdb\u884c\u683c\u5f0f\u8f6c\u6362\uff0c\u4ee5\u4fbf\u540e\u7eedPTrade\u4f7f\u7528\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.to_trade_df = g.db_df[1 == g.db_df['to_trade']]\n<\/code><\/pre>\n<p>\u83b7\u53d6\u5f85\u4ea4\u6613\u6570\u636e\uff0c\u5f85\u4ea4\u6613\u6570\u636e\u7684to_trade\u5b57\u6bb5\u503c\u5747\u4e3a1\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.to_buy_df = g.to_trade_df[g.to_trade_df['date_buy'].isna()]\n    g.to_buy_stock_list = g.to_buy_df['code_ptrade'].tolist()\n<\/code><\/pre>\n<p>\u83b7\u53d6\u5f85\u4e70\u5165\u6570\u636e\uff0c\u5982\u679cdate_buy\u5b57\u6bb5\u4e3a\u7a7a\uff0c\u8868\u793a\u8be5\u80a1\u7968\u5c1a\u672a\u4e70\u5165\uff0c\u9700\u5b9e\u76d8\u76d1\u6d4b\u662f\u5426\u89e6\u53d1\u4e70\u5165\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.buy_point_dict = g.to_buy_df[['code_ptrade', 'buy_point']].set_index('code_ptrade').to_dict(into=OrderedDict)['buy_point']\n    log.info('\u4e70\u70b9\u5b57\u5178\uff1a{}'.format(g.buy_point_dict))\n<\/code><\/pre>\n<p>\u751f\u6210\u4e70\u70b9\u5b57\u5178\uff0c\u5b57\u5178\u7684key\u4e3a\u80a1\u7968\u4ee3\u7801\uff0cvalue\u4e3a\u80a1\u7968\u7684\u4e70\u70b9\u4ef7\u683c\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.to_sell_df = g.to_trade_df[(~g.to_trade_df['date_buy'].isna()) &amp; (g.to_trade_df['hold_days'] &lt;= g.limit_hold_days)]\n    g.to_sell_stock_list = g.to_sell_df['code_ptrade'].tolist()\n<\/code><\/pre>\n<p>\u83b7\u53d6\u5f85\u6b62\u76c8\u3001\u6b62\u635f\u5356\u51fa\u6570\u636e\uff0c\u6b64\u7c7b\u80a1\u7968\u7684date_buy\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\uff0c\u8868\u793a\u5df2\u7ecf\u4e70\u5165\uff0c\u5e76\u4e14\u6301\u6709\u5929\u6570\u6ca1\u6709\u8fbe\u5230\u4e0a\u9650\uff0c\u8fd9\u6837\u9700\u8981\u5bf9\u6b64\u7c7b\u80a1\u7968\u7684\u4ef7\u683c\u8fdb\u884c\u76d1\u6d4b\uff0c\u89c2\u5bdf\u662f\u5426\u4f1a\u8fbe\u5230\u6b62\u76c8\u6216\u6b62\u635f\u4ef7\u683c\uff0c\u6765\u51b3\u5b9a\u662f\u5426\u9700\u8981\u5356\u51fa\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.to_sell_immi_df = g.to_trade_df[(~g.to_trade_df['date_buy'].isna()) &amp; (g.to_trade_df['hold_days'] &gt; g.limit_hold_days)]\n    g.to_sell_immi_list = g.to_sell_immi_df['code_ptrade'].tolist()\n    g.sell_immi_done = False\n<\/code><\/pre>\n<p>\u83b7\u53d6\u5f85\u7acb\u523b\u5356\u51fa\u80a1\u7968\uff0c\u6b64\u7c7b\u80a1\u7968date_buy\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\uff0c\u4e14\u5df2\u7ecf\u8fbe\u5230\u6301\u80a1\u5929\u6570\u4e0a\u9650\uff0c\u5f00\u76d8\u9700\u7acb\u5373\u5356\u51fa\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.take_profit_dict = g.to_sell_df[['code_ptrade', 'price_take_profit']].set_index('code_ptrade').to_dict()['price_take_profit']\n    log.info('\u6b62\u76c8\u5b57\u5178\uff1a{}'.format(g.take_profit_dict))\n    g.stop_loss_dict = g.to_sell_df[['code_ptrade', 'price_stop_loss']].set_index('code_ptrade').to_dict()['price_stop_loss']\n    log.info('\u6b62\u635f\u5b57\u5178\uff1a{}'.format(g.stop_loss_dict))\n<\/code><\/pre>\n<p>\u751f\u6210\u6b62\u76c8\u3001\u6b62\u635f\u5b57\u5178\uff0c\u5b57\u5178\u7684key\u4e3a\u80a1\u7968\u4ee3\u7801\uff0cvalue\u5206\u522b\u4e3a\u80a1\u7968\u7684\u6b62\u76c8\u4ef7\u548c\u6b62\u635f\u4ef7\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.security =  g.to_trade_df['code_ptrade'].tolist()\n    set_universe(g.security)\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u5f85\u4ea4\u6613\u80a1\u7968\uff0c\u5c06\u5f85\u4ea4\u6613\u80a1\u7968\u6dfb\u52a0\u5230\u80a1\u7968\u6c60\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    g.ipo_done = False\n    log.info('\u5f53\u524d\u53ef\u7528\u8d44\u91d1\uff1a{}'.format(context.portfolio.cash))\n<\/code><\/pre>\n<p>\u91cd\u7f6eipo\u6807\u8bc6\uff0c\u6bcf\u65e5\u56fa\u5b9a\u65f6\u95f4\u8fdb\u884c\u4e00\u6b21\u65b0\u80a1\u7533\u8d2d\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    log.info('\u76d8\u524d\u6301\u80a1{}\u53ea\uff1a{}'.format(get_position_count(context), get_position_list(context)))\n    log.info('\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\uff1a{}'.format(value_per_stock(context)))\n<\/code><\/pre>\n<p>\u6253\u5370\u76d8\u524d\u4fe1\u606f\u3002<\/p>\n<h1>\u5224\u65ad\u8d44\u91d1\u4f59\u989d\u662f\u5426\u5145\u8db3\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def enough_cash(context, limit_value):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u5224\u65ad\u8d44\u91d1\u4f59\u989d\u662f\u5426\u5145\u8db3\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<br \/>\n&#8211; \u53c2\u6570limit_value\u4e3a\u8d44\u91d1\u9650\u5236\uff0c\u5f53\u524d\u8d26\u6237\u4f59\u989d\u9700\u5927\u4e8e\u7b49\u4e8e\u8be5\u503c\uff0c\u624d\u5224\u65ad\u4e3a\u4f59\u989d\u5145\u8db3<\/p>\n<pre><code class=\"language-python line-numbers\">    if context.portfolio.cash &lt; limit_value:\n        log.info('\u4f59\u989d\u4e0d\u8db3')        \n        return False\n    else:\n        return True \n<\/code><\/pre>\n<p>\u5f53\u8d44\u91d1\u5145\u8db3\u5219\u8fd4\u56deTrue\uff0c\u5426\u5219\u8fd4\u56deFalse\u3002<\/p>\n<h1>\u83b7\u53d6\u5f53\u524d\u5df2\u4e70\u80a1\u7968\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def bought_stock_set(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u5df2\u4e70\u80a1\u7968\u7684\u96c6\u5408\uff0c\u5305\u542b\u5df2\u63d0\u4ea4\u4e70\u5355\u7684\u80a1\u7968\u548c\u6301\u4ed3\u80a1\u7968\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<\/p>\n<pre><code class=\"language-python line-numbers\">    return g.buy_submitted_set | set(get_position_list(context))\n<\/code><\/pre>\n<p>\u5bf9\u5df2\u63d0\u4ea4\u4e70\u5165\u7684\u80a1\u7968\u4ee3\u7801\u7684\u96c6\u5408\u3001\u6301\u4ed3\u80a1\u7968\u4ee3\u7801\u7684\u96c6\u5408\u6c42\u5e76\u96c6\uff0c\u8fbe\u5230\u5df2\u4e70\u80a1\u7968\u7684\u96c6\u5408\u3002<\/p>\n<h1>\u83b7\u53d6\u5f53\u524d\u53ef\u4e70\u80a1\u7968\u53ea\u6570\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def available_position_count(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<\/p>\n<pre><code class=\"language-python line-numbers\">    return g.limit_stock_num - len(bought_stock_set(context))\n<\/code><\/pre>\n<p>\u5bf9\u5df2\u63d0\u4ea4\u4e70\u5165\u7684\u80a1\u7968\u4ee3\u7801\u7684\u96c6\u5408\u3001\u6301\u4ed3\u80a1\u7968\u4ee3\u7801\u7684\u96c6\u5408\u6c42\u5e76\u96c6\uff0c\u518d\u7528\u6301\u80a1\u53ea\u6570\u9650\u5236\u51cf\u53bb\u4e0a\u9762\u5e76\u96c6\u4e2d\u5143\u7d20\u7684\u4e2a\u6570\uff0c\u5373\u4e3a\u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570 \u3002<\/p>\n<h1>\u83b7\u53d6\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def value_per_stock(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u8ba1\u7b97\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<\/p>\n<pre><code class=\"language-python line-numbers\">    available_count = available_position_count(context)\n<\/code><\/pre>\n<p>\u8ba1\u7b97\u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    if 0 == available_count:\n        return 0.0\n<\/code><\/pre>\n<p>\u5f53\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\u4e3a0\u65f6\u8fd4\u56de0.0\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    return context.portfolio.cash \/ available_count\n<\/code><\/pre>\n<p>\u5982\u679c\u53ef\u4e70\u5165\u80a1\u7968\u7684\u53ea\u6570\u4e0d\u4e3a0\uff0c\u5219\u7528\u8d44\u91d1\u4f59\u989d\u9664\u4ee5\u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\u5f97\u5230\u5355\u53ea\u80a1\u7968\u53ef\u4e70\u5165\u91d1\u989d\uff0c\u4f9b\u540e\u7eed\u4e0b\u4e70\u5355\u4f7f\u7528\u3002<\/p>\n<h1>\u83b7\u53d6\u5f53\u524d\u6301\u80a1\u5217\u8868\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def get_position_list(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u5f53\u524d\u6301\u80a1\u5217\u8868\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<\/p>\n<pre><code class=\"language-python line-numbers\">    return [x for x in context.portfolio.positions if context.portfolio.positions[x].amount != 0]\n<\/code><\/pre>\n<p>context.portfolio.positions\u5305\u542b\u6301\u80a1\u4fe1\u606f\uff0c\u4f46\u9700\u8981\u901a\u8fc7amount!=0\u6765\u83b7\u53d6\u771f\u5b9e\u6301\u80a1\u3002\u56e0\u4e3a\u5f53\u80a1\u7968\u5356\u51fa\u6210\u529f\u65f6\uff0c\u5f53\u65e5\u6e05\u4ed3\u7684\u80a1\u7968\u4fe1\u606f\u4ecd\u4f1a\u4fdd\u5b58\u5728context.portfolio.positions\u4e2d\uff0c\u53ea\u662famount\u7b49\u4e8e0\u3002<\/p>\n<h1>\u83b7\u53d6\u5f53\u524d\u6301\u80a1\u53ea\u6570\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def get_position_count(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u5f53\u524d\u6301\u80a1\u53ea\u6570\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<\/p>\n<pre><code class=\"language-python line-numbers\">    return len(get_position_list(context))\n<\/code><\/pre>\n<p>\u8c03\u7528get_position_list\u83b7\u53d6\u5f53\u524d\u6301\u6709\u80a1\u7968\u7684\u4ee3\u7801\u5217\u8868\uff0c\u4f7f\u7528len\u83b7\u53d6\u6301\u80a1\u53ea\u6570\u3002<\/p>\n<h1>\u5904\u7406\u5356\u51fa\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def handle_sell(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u5904\u7406\u5356\u51fa\u903b\u8f91\uff0c\u6bcf3\u79d2\u4f1a\u88ab\u8c03\u7528\u4e00\u6b21\u3002<\/p>\n<ul>\n<li>\u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<\/li>\n<\/ul>\n<pre><code class=\"language-python line-numbers\">    if not g.sell_immi_done:\n        for stock in g.to_sell_immi_list:\n            snapshot = get_snapshot(stock)\n            order_target(stock, 0, limit_price=round(snapshot[stock]['last_px'] * 0.982, 2))\n            g.sell_immi_done = True\n            log.info('{}\u6301\u4ed3\u5929\u6570\u9650\u5236\u5356\u5355\u63d0\u4ea4'.format(stock))\n<\/code><\/pre>\n<p>\u5904\u7406\u5230\u8fbe\u6301\u4ed3\u5929\u6570\u9650\u5236\u7684\u80a1\u7968\uff0c\u7528\u5f53\u524d\u4ef7\u4e0b\u8dcc1.8%\u63d0\u4ea4\u5356\u5355\uff0c\u786e\u4fdd\u5356\u51fa\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    for stock in g.to_sell_stock_list.copy():\n<\/code><\/pre>\n<p>\u904d\u5386\u5f85\u5356\u51fa\u80a1\u7968\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        snapshot = get_snapshot(stock)\n<\/code><\/pre>\n<p>\u83b7\u53d6\u5b9e\u65f6\u884c\u60c5\u5feb\u7167\uff0c\u5feb\u7167\u5305\u542b\u80a1\u7968\u7684\u5b9e\u65f6\u4ef7\u683c\u7b49\u4fe1\u606f\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        trade_status = snapshot[stock]['trade_status']\n        if trade_status == 'STOPT':\n            log.info(stock, '\u8be5\u80a1\u4e3a\u505c\u76d8\u72b6\u6001\uff0c\u4e0d\u8fdb\u884c\u4ea4\u6613\u5224\u65ad')\n            continue\n<\/code><\/pre>\n<p>\u5224\u65ad\u662f\u5426\u505c\u76d8\uff0c\u505c\u76d8\u5219\u8df3\u8fc7\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        high_price = snapshot[stock]['high_px']\n        low_price = snapshot[stock]['low_px']\n        current_price = snapshot[stock]['last_px']\n<\/code><\/pre>\n<p>\u4ece\u5feb\u7167\u4e2d\u83b7\u53d6\u80a1\u7968\u6700\u9ad8\u4ef7\u3001\u6700\u4f4e\u4ef7\u3001\u5f53\u524d\u4ef7\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        limit_price = round(current_price * 0.982, 2)\n<\/code><\/pre>\n<p>\u9650\u4ef7\uff0c\u8be5\u4ef7\u683c\u5c06\u7528\u4e8e\u5356\u51fa\u80a1\u7968\u3002\u521b\u4e1a\u677f\u548c\u79d1\u521b\u677f\u6709\u4ef7\u683c\u7b3c\u5b50\u9650\u5236\uff0c\u5356\u51fa\u7533\u62a5\u4ef7\u683c\u4e0d\u5f97\u4f4e\u4e8e\u5356\u51fa\u57fa\u51c6\u4ef7\u683c\u768498%\u3002\u6211\u4eec\u5c06\u9650\u4ef7\u540c\u4e00\u8bbe\u7f6e\u4e3a\u5f53\u524d\u4ef7\u683c\u4e0b\u8dcc1.8%\uff0c\u4ee5\u786e\u4fdd\u80fd\u591f\u6210\u529f\u5356\u51fa\uff08\u6781\u7aef\u60c5\u51b5\u53ef\u80fd\u4ecd\u65e0\u6cd5\u5356\u51fa\uff09\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        if high_price &gt;= g.take_profit_dict[stock] or low_price &lt;= g.stop_loss_dict[stock]:\n            log.info('{}\u5230\u8fbe\u5356\u70b9'.format(stock))\n<\/code><\/pre>\n<p>\u5982\u679c\u8fbe\u5230\u6b62\u76c8\u6216\u8005\u6b62\u635f\u6761\u4ef6\uff0c\u5219\u80a1\u7968\u8fbe\u5230\u5356\u70b9\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">            order_target(stock, 0, limit_price=limit_price)\n<\/code><\/pre>\n<p>\u4ee5\u9650\u4ef7\u4e0b\u6307\u5b9a\u5e02\u503c\u5356\u5355\uff0c\u6e05\u7a7a\u8be5\u80a1\u7968\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">            g.to_sell_stock_list.remove(stock)\n            log.info('{}\u5356\u5355\u63d0\u4ea4'.format(stock))\n<\/code><\/pre>\n<p>\u5728\u5f85\u5356\u51fa\u80a1\u7968\u5217\u8868\u4e2d\u5220\u9664\u8be5\u80a1\u7968\u3002<\/p>\n<h1>\u5904\u7406\u4e70\u5165\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def handle_buy(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u5904\u7406\u4e70\u5165\u903b\u8f91\uff0c\u6bcf3\u79d2\u4f1a\u88ab\u8c03\u7528\u4e00\u6b21\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<\/p>\n<pre><code class=\"language-python line-numbers\">    if context.portfolio.cash &lt; g.limit_value:        \n        return\n<\/code><\/pre>\n<p>\u5224\u65ad\u5269\u4f59\u8d44\u91d1\u662f\u5426\u5927\u4e8e\u6700\u5c0f\u4e70\u5165\u91d1\u989d\u9650\u5236\uff0c\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\u592a\u5c0f\uff0c\u6ca1\u6709\u610f\u4e49\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    if available_position_count(context) &lt;= 0:\n        return\n<\/code><\/pre>\n<p>\u5224\u65ad\u5982\u679c\u5df2\u8fbe\u6700\u5927\u6301\u80a1\u53ea\u6570\uff0c\u5219\u4e0d\u4e70\u5165\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    for stock in g.to_buy_stock_list.copy():\n<\/code><\/pre>\n<p>\u904d\u5386\u6bcf\u53ea\u5019\u9009\u4e70\u5165\u80a1\u7968\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        if available_position_count(context) &lt;= 0:\n            return\n<\/code><\/pre>\n<p>\u5224\u65ad\u5982\u679c\u5df2\u8fbe\u6700\u5927\u6301\u80a1\u53ea\u6570\uff0c\u5219\u4e0d\u4e70\u5165\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        if stock in bought_stock_set(context):\n            continue\n<\/code><\/pre>\n<p>\u4e0d\u91cd\u590d\u4e70\u5165\u80a1\u7968\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        snapshot = get_snapshot(stock)\n<\/code><\/pre>\n<p>\u83b7\u53d6\u5b9e\u65f6\u884c\u60c5\u5feb\u7167\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        trade_status = snapshot[stock]['trade_status']\n        if trade_status == 'STOPT':\n            log.info((stock, '\u8be5\u80a1\u4e3a\u505c\u76d8\u72b6\u6001\uff0c\u4e0d\u8fdb\u884c\u4ea4\u6613\u5224\u65ad'))\n            continue\n<\/code><\/pre>\n<p>\u5224\u65ad\u662f\u5426\u505c\u76d8\uff0c\u505c\u76d8\u5219\u8df3\u8fc7\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        low_price = snapshot[stock]['low_px']\n        current_price = snapshot[stock]['last_px']\n<\/code><\/pre>\n<p>\u83b7\u53d6\u80a1\u7968\u6700\u4f4e\u4ef7\u548c\u5f53\u524d\u4ef7\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        target_value = value_per_stock(context)\n<\/code><\/pre>\n<p>\u83b7\u53d6\u8ba1\u7b97\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        if target_value &lt; current_price * 100 * 1.0003: \n            continue\n<\/code><\/pre>\n<p>\u5982\u679c\u4f59\u989d\u4e0d\u8db3\u4e701\u624b\uff0c\u5219\u8df3\u8fc7\u8be5\u80a1\u7968\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        limit_price = round(current_price * 1.018, 2)\n<\/code><\/pre>\n<p>\u8ba1\u7b97\u9650\u4ef7\uff0c\u521b\u4e1a\u677f\u548c\u79d1\u521b\u677f\u6709\u4ef7\u683c\u7b3c\u5b50\u9650\u5236\uff0c\u4e70\u5165\u7533\u62a5\u4ef7\u683c\u4e0d\u5f97\u9ad8\u4e8e\u4e70\u5165\u57fa\u51c6\u4ef7\u683c\u7684102%\uff0c\u6211\u4eec\u8fd9\u91cc\u5c06\u9650\u4ef7\u8bbe\u7f6e\u4e3a\u5f53\u524d\u4ef7\u4e0a\u6da81.8%\uff0c\u7528\u4e8e\u540e\u7eed\u4e0b\u4e70\u5355\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        if (low_price &lt;= g.buy_point_dict[stock]) and (limit_price \/ g.buy_point_dict[stock] &lt;= 1.0382):\n            log.info('{}\u5230\u8fbe\u4e70\u70b9'.format(stock))\n<\/code><\/pre>\n<p>\u5f53\u6700\u4f4e\u4ef7\u4f4e\u4e8e\u4e70\u70b9\uff0c\u8868\u793a\u80a1\u7968\u5df2\u7ecf\u5230\u8fbe\u4e70\u70b9\u3002\u6b64\u5916\u7ea6\u675flimit_price\u4e0d\u8d85\u8fc7\u4e70\u70b9\u76843.82%\uff0c\u518d\u4e0b\u4e70\u5355\uff0c\u907f\u514d\u6709\u80a1\u7968\u5356\u51fa\u540e\uff0c\u4f59\u989d\u5145\u8db3\u540e\u4e70\u5165\u65b0\u80a1\u7968\u7684\u4ef7\u683c\u8fc7\u9ad8\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">            g.buy_submitted_set.add(stock)\n<\/code><\/pre>\n<p>\u5c06\u80a1\u7968\u4ee3\u7801\u6dfb\u52a0\u5230\u5df2\u63d0\u4ea4\u4e70\u5355\u5b57\u5178\uff0c\u907f\u514d\u540e\u7eed\u91cd\u590d\u63d0\u4ea4\u8be5\u80a1\u7968\u4e70\u5355\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">            log.info('targe_value={}, limit_price={}'.format(target_value, limit_price))\n            order_target_value(stock, target_value, limit_price=limit_price)\n<\/code><\/pre>\n<p>\u4e0b\u6307\u5b9a\u5e02\u503c\u4e70\u5355\uff0c\u7528\u9650\u4ef7\u63d0\u4ea4\uff0corder_target_value\u51fd\u6570\u4f1a\u5b9e\u73b0\u4ee5\u9650\u4ef7\u8c03\u6574\u80a1\u7968\u4ed3\u4f4d\u5230value\u4ef7\u503c\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">            g.to_buy_stock_list.remove(stock)\n            log.info('{}\u4e70\u5355\u63d0\u4ea4'.format(stock))\n<\/code><\/pre>\n<p>\u5728\u5f85\u4e70\u5165\u80a1\u7968\u5217\u8868\u4e2d\u5220\u9664\u8be5\u80a1\u7968\uff0c\u540e\u7eed\u4e0d\u518d\u5224\u65ad\u662f\u5426\u8fd8\u9700\u4e70\u5165\u3002<\/p>\n<h1>\u5904\u7406\u6253\u65b0\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def handle_ipo():\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u7528\u4e8e\u5904\u7406\u6253\u65b0\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    if not g.ipo_done and datetime.datetime.now().time() &gt;= datetime.time(11, 13, 0):\n<\/code><\/pre>\n<p>\u5982\u679c\u5c1a\u672a\u7533\u8d2d\uff0c\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff0c\u572811:13\u8fdb\u884c\u7533\u8d2d\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        ipo_stocks_order(market_type=0)\n<\/code><\/pre>\n<p>\u7533\u8d2d\u4e0a\u8bc1\u666e\u901a\u65b0\u80a1\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        ipo_stocks_order(market_type=2)\n<\/code><\/pre>\n<p>\u7533\u8d2d\u6df1\u8bc1\u666e\u901a\u65b0\u80a1\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        ipo_stocks_order(market_type=3)\n<\/code><\/pre>\n<p>\u7533\u8d2d\u4e0a\u8bc1\u666e\u901a\u65b0\u80a1\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">        g.ipo_done = True\n<\/code><\/pre>\n<p>\u6807\u8bb0\u5f53\u65e5\u5df2\u7533\u8d2d\u3002<\/p>\n<h1>\u5468\u671f\u5904\u7406\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def interval_handle(context):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u4e3a\u5468\u671f\u5904\u7406\u51fd\u6570\uff0c\u6bcf3\u79d2\u88ab\u8c03\u7528\u4e00\u6b21\uff0c\u4f9d\u6b21\u8c03\u7528\u524d\u6587\u5b9e\u73b0\u7684\u51fd\u6570\u5904\u7406\u4e70\u5165\u3001\u5356\u51fa\u53ca\u6253\u65b0\u7533\u8d2d\u3002<\/p>\n<ul>\n<li>\u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<\/li>\n<\/ul>\n<pre><code class=\"language-python line-numbers\">    handle_sell(context)\n<\/code><\/pre>\n<p>\u5148\u5904\u7406\u5356\u51fa\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    handle_buy(context)\n<\/code><\/pre>\n<p>\u518d\u5904\u7406\u4e70\u5165\u3002<\/p>\n<pre><code class=\"language-python line-numbers\">    handle_ipo()\n<\/code><\/pre>\n<p>\u6700\u540e\u5904\u7406\u6253\u65b0\u3002<\/p>\n<h1>\u59d4\u6258\u54cd\u5e94\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def on_order_response(context, order_list):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u4f1a\u5728\u59d4\u6258\u56de\u62a5\u8fd4\u56de\u65f6\u54cd\u5e94\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<br \/>\n&#8211; \u53c2\u6570order_list\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u5f53\u524d\u59d4\u6258\u5355\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u53d1\u751f\u53d8\u5316\u7684\u59d4\u6258\u5355\u5217\u8868\u3002\u59d4\u6258\u5355\u4ee5\u5b57\u5178\u5f62\u5f0f\u5c55\u73b0\uff0c\u5185\u5bb9\u5305\u62ec\uff1a&#8217;entrust_no'(\u59d4\u6258\u5355\u53f7), &#8216;order_time'(\u59d4\u6258\u65f6\u95f4), &#8216;stock_code'(\u80a1\u7968\u4ee3\u7801), &#8216;amount'(\u59d4\u6258\u6570\u91cf), &#8216;price'(\u59d4\u6258\u4ef7\u683c), &#8216;business_amount'(\u6210\u4ea4\u6570\u91cf), &#8216;status'(\u59d4\u6258\u72b6\u6001), &#8216;order_id'(\u59d4\u6258\u8ba2\u5355\u53f7), &#8216;entrust_type'(\u59d4\u6258\u7c7b\u522b), &#8216;entrust_prop'(\u59d4\u6258\u5c5e\u6027)<\/p>\n<pre><code class=\"language-python line-numbers\">    for order in order_list:\n        bs = '\u4e70\u5165' if order['amount'] &gt; 0 else '\u5356\u51fa'\n        info = '\u8ba2\u5355\u63d0\u4ea4\uff0c\u80a1\u7968\u4ee3\u7801\uff1a{}\uff0c\u6570\u91cf\uff1a{}{:.0f}'.format(order['stock_code'], bs, abs(order['amount']))\n        log.info(info)\n<\/code><\/pre>\n<p>\u6253\u5370\u59d4\u6258\u6570\u636e\u3002<\/p>\n<h1>\u6210\u4ea4\u54cd\u5e94\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def on_trade_response(context, trade_list):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u4f1a\u5728\u6210\u4ea4\u56de\u62a5\u8fd4\u56de\u65f6\u54cd\u5e94\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<br \/>\n&#8211; \u53c2\u6570trade_list\u662f\u4e00\u4e2a\u5217\u8868\uff0c\u5f53\u524d\u6210\u4ea4\u5355\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u53d1\u751f\u53d8\u5316\u7684\u6210\u4ea4\u5355\u5217\u8868\u3002\u6210\u4ea4\u5355\u4ee5\u5b57\u5178\u5f62\u5f0f\u5c55\u73b0\uff0c\u5185\u5bb9\u5305\u62ec\uff1a&#8217;entrust_no'(\u59d4\u6258\u5355\u53f7), &#8216;business_time'(\u6210\u4ea4\u65f6\u95f4), &#8216;stock_code'(\u80a1\u7968\u4ee3\u7801), &#8216;entrust_bs'(\u6210\u4ea4\u65b9\u5411), &#8216;business_amount'(\u6210\u4ea4\u6570\u91cf), &#8216;business_price'(\u6210\u4ea4\u4ef7\u683c), &#8216;business_balance'(\u6210\u4ea4\u989d), &#8216;business_id'(\u6210\u4ea4\u7f16\u53f7), &#8216;status'(\u59d4\u6258\u72b6\u6001)<\/p>\n<pre><code class=\"language-python line-numbers\">    for trade in trade_list:\n        bs = '\u4e70\u5165' if trade['business_amount'] &gt; 0 else '\u5356\u51fa'    \n        info = '\u8ba2\u5355\u6210\u4ea4\uff0c\u80a1\u7968\u4ee3\u7801\uff1a{}\uff0c\u6570\u91cf\uff1a{}{:.0f}'.format(trade['stock_code'], bs, abs(trade['business_amount']))\n        log.info(info)\n<\/code><\/pre>\n<p>\u6253\u5370\u6210\u4ea4\u6570\u636e\u3002<\/p>\n<h1>\u76d8\u540e\u603b\u7ed3\u51fd\u6570<\/h1>\n<pre><code class=\"language-python line-numbers\">def after_trading_end(context, data):\n<\/code><\/pre>\n<p>\u8be5\u51fd\u6570\u4f1a\u5728\u6bcf\u5929\u4ea4\u6613\u7ed3\u675f\u4e4b\u540e\u8c03\u7528\uff0c\u7528\u6765\u5904\u7406\u6bcf\u5929\u6536\u76d8\u540e\u7684\u64cd\u4f5c\u3002<br \/>\n&#8211; \u53c2\u6570context\u4e3a<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/101.230.215.13:7766\/hub\/help\/api#Context\">Context\u5bf9\u8c61<\/a>\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f<br \/>\n&#8211; \u53c2\u6570data\u4e3a\u4fdd\u7559\u5b57\u6bb5\u6682\u65e0\u6570\u636e<\/p>\n<pre><code class=\"language-python line-numbers\">    log.info('\u76d8\u540e\u6301\u80a1{}\u53ea\uff1a{}'.format(get_position_count(context), get_position_list(context)))\n<\/code><\/pre>\n<p>\u6253\u5370\u76d8\u540e\u6301\u80a1\u6570\u636e\u3002<\/p>\n<h1>\u5c0f\u7ed3<\/h1>\n<p>\u672c\u6587\u5b8c\u6210\u4e86PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u7684\u4ecb\u7ecd\u3002\u6211\u4eec\u7684\u5168\u81ea\u52a8\u5316\u4ea4\u6613\u4e5f\u53ea\u5dee\u6700\u540e\u4e00\u6b65\uff0c\u5c06\u5728\u4e0b\u4e00\u7bc7\u6587\u7ae0\u4e2d\u4ecb\u7ecd\u3002\u4e0b\u4e00\u7bc7\u6587\u7ae0\u4e5f\u5c06\u662f\u201c\u4ece\u96f6\u5230\u5b9e\u76d8\u201d\u7cfb\u5217\u6587\u7ae0\u7684\u6700\u540e\u4e00\u7bc7\u3002<\/p>\n<hr \/>\n<p>PTrade\u4ea4\u6613\u7a0b\u5e8f\u7684\u5168\u90e8\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python line-numbers\">import pandas as pd\nimport datetime\nfrom collections import OrderedDict \n\n\ndef initialize(context):\n    \"\"\"\u521d\u59cb\u5316\uff0c\u542f\u52a8\u7a0b\u5e8f\u540e\u53ea\u8c03\u7528\u4e00\u6b21\n\n    :param context: Context\u5bf9\u8c61\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: None\n    \"\"\"\n\n    # \u5b9a\u4e49\u4e00\u4e2a\u5468\u671f\u5904\u7406\u51fd\u6570\uff0c\u6bcf3\u79d2\u6267\u884c\u4e00\u6b21\n    run_interval(context, interval_handle, seconds = 3)\n    # \u8d44\u91d1\u5c11\u4e8elimit_value\u5219\u4e0d\u4e70\u5165\n    g.limit_value = 5000\n    # \u6301\u4ed3\u80a1\u7968\u53ea\u6570\u9650\u5236\n    g.limit_stock_num = 3\n    # \u6301\u80a1\u5929\u6570\u9650\u5236\n    g.limit_hold_days = 6\n    g.security = '000300.SS'\n    set_universe(g.security)\n\n\ndef before_trading_start(context, data):\n    \"\"\"\u5728\u6bcf\u5929\u5f00\u59cb\u4ea4\u6613\u524d\u88ab\u8c03\u7528\uff0c\u6b64\u5904\u6dfb\u52a0\u6bcf\u5929\u90fd\u8981\u521d\u59cb\u5316\u7684\u4fe1\u606f\n\n    :param context: Context\u5bf9\u8c61\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :param data: \u4fdd\u7559\u5b57\u6bb5\u6682\u65e0\u6570\u636e\n    :return: None    \n    \"\"\"\n\n    # \u5f53\u65e5\u63d0\u4ea4\u4e70\u5355\u7684\u80a1\u7968\u4ee3\u7801\u96c6\u5408\n    g.buy_submitted_set = set() \n\n    # \u8bfb\u53d6\u6570\u636e\u5e93\u6587\u4ef6\n    file_path = get_research_path() + 'upload_file\/trade_data.csv'\n    g.db_df = pd.read_csv(file_path, encoding='utf-8', converters={'code': str})\n\n    # code\u8f6c\u6362\n    g.db_df['code_ptrade'] = g.db_df['code'].map(lambda x: x + '.SS' if '6' == x[0] else x + '.SZ')\n\n    # \u83b7\u53d6\u5f85\u4ea4\u6613\u6570\u636e\n    g.to_trade_df = g.db_df[1 == g.db_df['to_trade']]\n\n    # \u83b7\u53d6\u5f85\u4e70\u5165\u6570\u636e    \n    g.to_buy_df = g.to_trade_df[g.to_trade_df['date_buy'].isna()]\n    g.to_buy_stock_list = g.to_buy_df['code_ptrade'].tolist()\n\n    # \u751f\u6210\u4e70\u70b9\u5b57\u5178\n    g.buy_point_dict = g.to_buy_df[['code_ptrade', 'buy_point']].set_index('code_ptrade').to_dict(into=OrderedDict)['buy_point']\n    log.info('\u4e70\u70b9\u5b57\u5178\uff1a{}'.format(g.buy_point_dict))\n\n    # \u83b7\u53d6\u5f85\u6b62\u76c8\u3001\u6b62\u635f\u5356\u51fa\u6570\u636e\n    g.to_sell_df = g.to_trade_df[(~g.to_trade_df['date_buy'].isna()) &amp; (g.to_trade_df['hold_days'] &lt;= g.limit_hold_days)]\n    g.to_sell_stock_list = g.to_sell_df['code_ptrade'].tolist()\n\n    # \u83b7\u53d6\u5f85\u7acb\u523b\u5356\u51fa\u80a1\u7968\n    g.to_sell_immi_df = g.to_trade_df[(~g.to_trade_df['date_buy'].isna()) &amp; (g.to_trade_df['hold_days'] &gt; g.limit_hold_days)]\n    g.to_sell_immi_list = g.to_sell_immi_df['code_ptrade'].tolist()\n    g.sell_immi_done = False\n\n    # \u751f\u6210\u6b62\u76c8\u3001\u6b62\u635f\u5b57\u5178\n    g.take_profit_dict = g.to_sell_df[['code_ptrade', 'price_take_profit']].set_index('code_ptrade').to_dict()['price_take_profit']\n    log.info('\u6b62\u76c8\u5b57\u5178\uff1a{}'.format(g.take_profit_dict))\n    g.stop_loss_dict = g.to_sell_df[['code_ptrade', 'price_stop_loss']].set_index('code_ptrade').to_dict()['price_stop_loss']\n    log.info('\u6b62\u635f\u5b57\u5178\uff1a{}'.format(g.stop_loss_dict))\n\n    # \u8bbe\u7f6e\u5f85\u4ea4\u6613\u80a1\u7968    \n    g.security =  g.to_trade_df['code_ptrade'].tolist()\n    set_universe(g.security)\n\n    # \u91cd\u7f6eipo\u6807\u8bc6\n    g.ipo_done = False\n    log.info('\u5f53\u524d\u53ef\u7528\u8d44\u91d1\uff1a{}'.format(context.portfolio.cash))\n\n    # \u76d8\u524d\u4fe1\u606f\n    log.info('\u76d8\u524d\u6301\u80a1{}\u53ea\uff1a{}'.format(get_position_count(context), get_position_list(context)))\n    log.info('\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\uff1a{}'.format(value_per_stock(context)))\n\n\ndef enough_cash(context, limit_value):\n    \"\"\"\u5224\u65ad\u8d44\u91d1\u4f59\u989d\u662f\u5426\u5145\u8db3\n\n    :param context: Context\u5bf9\u8c61\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :param limit_value: \u8d44\u91d1\u9650\u5236\uff0c\u5f53\u524d\u8d26\u6237\u4f59\u989d\u9700\u5927\u4e8e\u7b49\u4e8e\u8be5\u503c\uff0c\u624d\u5224\u65ad\u4e3a\u4f59\u989d\u5145\u8db3\n    :return: \u8d44\u91d1\u5145\u8db3\u5219\u8fd4\u56deTrue\uff0c\u5426\u5219\u8fd4\u56deFalse        \n    \"\"\"\n\n    if context.portfolio.cash &lt; limit_value:\n        log.info('\u4f59\u989d\u4e0d\u8db3')        \n        return False\n    else:\n        return True    \n\n\ndef bought_stock_set(context):\n    \"\"\"\u5df2\u4e70\u80a1\u7968\u7684\u96c6\u5408\n\n    \u5bf9\u5df2\u63d0\u4ea4\u4e70\u5165\u7684\u80a1\u7968\u4ee3\u7801\u7684\u96c6\u5408\u3001\u6301\u4ed3\u80a1\u7968\u4ee3\u7801\u7684\u96c6\u5408\u6c42\u5e76\u96c6\n\n    :param context: Context\u5bf9\u8c61\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: \u5df2\u4e70\u80a1\u7968\u7684\u96c6\u5408\n    \"\"\"\n    return g.buy_submitted_set | set(get_position_list(context))\n\n\ndef available_position_count(context):\n    \"\"\"\u8ba1\u7b97\u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\n\n    \u5bf9\u5df2\u63d0\u4ea4\u4e70\u5165\u7684\u80a1\u7968\u4ee3\u7801\u7684\u96c6\u5408\u3001\u6301\u4ed3\u80a1\u7968\u4ee3\u7801\u7684\u96c6\u5408\u6c42\u5e76\u96c6\n    \u518d\u7528\u6301\u80a1\u53ea\u6570\u9650\u5236\u51cf\u53bb\u4e0a\u9762\u5e76\u96c6\u4e2d\u5143\u7d20\u7684\u4e2a\u6570\uff0c\u5373\u4e3a\u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570 \n\n    :param context: Context\u5bf9\u8c61\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: \u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\n    \"\"\"\n\n    return g.limit_stock_num - len(bought_stock_set(context))\n\n\ndef value_per_stock(context):\n    \"\"\"\u8ba1\u7b97\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\n\n    \u8d44\u91d1\u4f59\u989d\u9664\u4ee5\u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\n    \u5f53\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\u4e3a0\u65f6\u8fd4\u56de0.0\n\n    :param context: Context\u5bf9\u8c61\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: \u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\uff0c\u5f53\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\u4e3a0\u65f6\u8fd4\u56de0.0\n    \"\"\"\n\n    # \u8ba1\u7b97\u5f53\u524d\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\n    available_count = available_position_count(context)\n\n    # \u5f53\u53ef\u4e70\u7684\u80a1\u7968\u53ea\u6570\u4e3a0\u65f6\u8fd4\u56de0.0\n    if 0 == available_count:\n        return 0.0\n\n    return context.portfolio.cash \/ available_count\n\n\ndef get_position_count(context):\n    \"\"\"\u83b7\u53d6\u5f53\u524d\u6301\u80a1\u53ea\u6570\n\n    \u8c03\u7528get_position_list\u83b7\u53d6\u5f53\u524d\u6301\u6709\u80a1\u7968\u7684\u4ee3\u7801\u5217\u8868\n    \u4f7f\u7528len\u83b7\u53d6\u6301\u80a1\u53ea\u6570\n\n    :param context: \u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: \u5f53\u524d\u6301\u6709\u80a1\u7968\u7684\u53ea\u6570\n    \"\"\"\n\n    return len(get_position_list(context))\n\n\ndef get_position_list(context):\n    \"\"\"\u83b7\u53d6\u5f53\u524d\u6301\u80a1\u5217\u8868\n\n    context.portfolio.positions\u5305\u542b\u6301\u80a1\u4fe1\u606f\uff0c\u4f46\u9700\u8981\u901a\u8fc7amount!=0\u6765\u83b7\u53d6\u771f\u5b9e\u6301\u80a1\n    \u56e0\u4e3a\u5f53\u80a1\u7968\u5356\u51fa\u6210\u529f\u65f6\uff0c\u5f53\u65e5\u6e05\u4ed3\u7684\u80a1\u7968\u4fe1\u606f\u4ecd\u4f1a\u4fdd\u5b58\u5728context.portfolio.positions\u4e2d\uff0c\u53ea\u662famount\u7b49\u4e8e0\n\n    :param context: \u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: \u5f53\u524d\u6301\u6709\u80a1\u7968\u7684\u4ee3\u7801\u5217\u8868\n    \"\"\"\n\n    return [x for x in context.portfolio.positions if context.portfolio.positions[x].amount != 0]\n\n\ndef handle_sell(context):\n    \"\"\"\u5904\u7406\u5356\u51fa\u903b\u8f91\n\n    :param context: Context\u5bf9\u8c61\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: None\n    \"\"\"\n\n    # \u5904\u7406\u5230\u8fbe\u6301\u4ed3\u5929\u6570\u9650\u5236\u7684\u80a1\u7968\uff0c\u7528\u5f53\u524d\u4ef7\u4e0b\u8dcc1.8%\u63d0\u4ea4\u5356\u5355\uff0c\u786e\u4fdd\u5356\u51fa\n    if not g.sell_immi_done:\n        for stock in g.to_sell_immi_list:\n            snapshot = get_snapshot(stock)\n            order_target(stock, 0, limit_price=round(snapshot[stock]['last_px'] * 0.982, 2))\n            g.sell_immi_done = True\n            log.info('{}\u6301\u4ed3\u5929\u6570\u9650\u5236\u5356\u5355\u63d0\u4ea4'.format(stock))\n\n    # \u904d\u5386\u5f85\u5356\u51fa\u80a1\u7968\n    for stock in g.to_sell_stock_list.copy():\n\n        # \u83b7\u53d6\u5b9e\u65f6\u884c\u60c5\u5feb\u7167\n        snapshot = get_snapshot(stock)\n\n        # \u5224\u65ad\u662f\u5426\u505c\u76d8\uff0c\u505c\u76d8\u5219\u8df3\u8fc7\n        trade_status = snapshot[stock]['trade_status']\n        if trade_status == 'STOPT':\n            log.info(stock, '\u8be5\u80a1\u4e3a\u505c\u76d8\u72b6\u6001\uff0c\u4e0d\u8fdb\u884c\u4ea4\u6613\u5224\u65ad')\n            continue\n\n        # \u83b7\u53d6\u80a1\u7968\u6700\u9ad8\u4ef7\u3001\u6700\u4f4e\u4ef7\u3001\u5f53\u524d\u4ef7\n        high_price = snapshot[stock]['high_px']\n        low_price = snapshot[stock]['low_px']\n        current_price = snapshot[stock]['last_px']\n\n        # \u9650\u4ef7\uff0c\u521b\u4e1a\u677f\u548c\u79d1\u521b\u677f\u6709\u4ef7\u683c\u7b3c\u5b50\u9650\u5236\uff0c\u5356\u51fa\u7533\u62a5\u4ef7\u683c\u4e0d\u5f97\u4f4e\u4e8e\u5356\u51fa\u57fa\u51c6\u4ef7\u683c\u768498%\n        limit_price = round(current_price * 0.982, 2)\n\n        # \u5982\u679c\u8fbe\u5230\u6b62\u76c8\u6216\u8005\u6b62\u635f\u6761\u4ef6\uff0c\u5219\u6302\u9650\u4ef7\u5356\u51fa\n        if high_price &gt;= g.take_profit_dict[stock] or low_price &lt;= g.stop_loss_dict[stock]:\n            log.info('{}\u5230\u8fbe\u5356\u70b9'.format(stock))\n\n            # \u4e0b\u6307\u5b9a\u5e02\u503c\u5356\u5355\n            order_target(stock, 0, limit_price=limit_price)\n\n            # \u5728\u5f85\u5356\u51fa\u80a1\u7968\u5217\u8868\u4e2d\u5220\u9664\u8be5\u80a1\u7968\n            g.to_sell_stock_list.remove(stock)\n            log.info('{}\u5356\u5355\u63d0\u4ea4'.format(stock))\n\n\ndef handle_buy(context):\n    \"\"\"\u5904\u7406\u4e70\u5165\u903b\u8f91\n\n    :param context: Context\u5bf9\u8c61\uff0c\u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: None\n    \"\"\"\n\n    # \u5224\u65ad\u5269\u4f59\u8d44\u91d1\u662f\u5426\u5927\u4e8e\u6700\u5c0f\u4e70\u5165\u91d1\u989d\u9650\u5236\uff0c\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\u592a\u5c0f\uff0c\u6ca1\u6709\u610f\u4e49\n    if context.portfolio.cash &lt; g.limit_value:        \n        return\n\n    # \u5224\u65ad\u5982\u679c\u5df2\u8fbe\u6700\u5927\u6301\u80a1\u53ea\u6570\uff0c\u5219\u4e0d\u4e70\u5165\n    if available_position_count(context) &lt;= 0:\n        return\n\n\n    # \u904d\u5386\u6bcf\u53ea\u5019\u9009\u4e70\u5165\u80a1\u7968    \n    for stock in g.to_buy_stock_list.copy():\n\n        # \u5224\u65ad\u5982\u679c\u5df2\u8fbe\u6700\u5927\u6301\u80a1\u53ea\u6570\uff0c\u5219\u4e0d\u4e70\u5165\n        if available_position_count(context) &lt;= 0:\n            return\n\n        # \u4e0d\u91cd\u590d\u4e70\u5165\u80a1\u7968\n        if stock in bought_stock_set(context):\n            continue\n\n        # \u83b7\u53d6\u5b9e\u65f6\u884c\u60c5\u5feb\u7167\n        snapshot = get_snapshot(stock)\n\n        # \u5224\u65ad\u662f\u5426\u505c\u76d8\uff0c\u505c\u76d8\u5219\u8df3\u8fc7\n        trade_status = snapshot[stock]['trade_status']\n        if trade_status == 'STOPT':\n            log.info((stock, '\u8be5\u80a1\u4e3a\u505c\u76d8\u72b6\u6001\uff0c\u4e0d\u8fdb\u884c\u4ea4\u6613\u5224\u65ad'))\n            continue\n\n        # \u83b7\u53d6\u80a1\u7968\u6700\u4f4e\u4ef7\u548c\u5f53\u524d\u4ef7\n        low_price = snapshot[stock]['low_px']\n        current_price = snapshot[stock]['last_px']\n\n        # \u83b7\u53d6\u8ba1\u7b97\u5355\u53ea\u80a1\u7968\u4e70\u5165\u91d1\u989d\n        target_value = value_per_stock(context)\n\n        # \u5982\u679c\u4f59\u989d\u4e0d\u8db3\u4e701\u624b\uff0c\u5219\u8df3\u8fc7\u8be5\u80a1\u7968\n        if target_value &lt; current_price * 100 * 1.0003: \n            continue\n\n        # \u9650\u4ef7\uff0c\u521b\u4e1a\u677f\u548c\u79d1\u521b\u677f\u6709\u4ef7\u683c\u7b3c\u5b50\u9650\u5236\uff0c\u4e70\u5165\u7533\u62a5\u4ef7\u683c\u4e0d\u5f97\u9ad8\u4e8e\u4e70\u5165\u57fa\u51c6\u4ef7\u683c\u7684102%\n        limit_price = round(current_price * 1.018, 2)\n\n        # \u6700\u4f4e\u4ef7\u4f4e\u4e8e\u4e70\u70b9\uff0c\u4e14limit_price\u4e0d\u8d85\u8fc7\u4e70\u70b9\u76843.82%\uff0c\u518d\u4e0b\u4e70\u5355\u3002\u907f\u514d\u6709\u80a1\u7968\u5356\u51fa\u540e\uff0c\u4f59\u989d\u5145\u8db3\u540e\u4e70\u5165\u65b0\u80a1\u7968\u7684\u4ef7\u683c\u8fc7\u9ad8\n        if (low_price &lt;= g.buy_point_dict[stock]) and (limit_price \/ g.buy_point_dict[stock] &lt;= 1.0382):\n            log.info('{}\u5230\u8fbe\u4e70\u70b9'.format(stock))\n\n            # \u5c06\u80a1\u7968\u4ee3\u7801\u6dfb\u52a0\u5230\u5df2\u63d0\u4ea4\u4e70\u5355\u5b57\u5178\n            g.buy_submitted_set.add(stock)\n\n            # \u4e0b\u6307\u5b9a\u5e02\u503c\u4e70\u5355\uff0c\u7528\u9650\u4ef7\u63d0\u4ea4\n            log.info('targe_value={}, limit_price={}'.format(target_value, limit_price))\n            order_target_value(stock, target_value, limit_price=limit_price)\n\n            # \u5728\u5f85\u4e70\u5165\u80a1\u7968\u5217\u8868\u4e2d\u5220\u9664\u8be5\u80a1\u7968\n            g.to_buy_stock_list.remove(stock)\n            log.info('{}\u4e70\u5355\u63d0\u4ea4'.format(stock))\n\n\ndef handle_ipo():\n    \"\"\"\u5904\u7406\u6253\u65b0\n\n    11:13\u7533\u8d2d\n\n    :return: None\n    \"\"\"\n\n    # \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\n    if not g.ipo_done and datetime.datetime.now().time() &gt;= datetime.time(11, 13, 0):\n\n        # \u7533\u8d2d\u4e0a\u8bc1\u666e\u901a\u65b0\u80a1\n        ipo_stocks_order(market_type=0)\n\n        # \u7533\u8d2d\u6df1\u8bc1\u666e\u901a\u65b0\u80a1\n        ipo_stocks_order(market_type=2)\n\n        # \u7533\u8d2d\u4e0a\u8bc1\u666e\u901a\u65b0\u80a1\n        ipo_stocks_order(market_type=3)\n\n        # \u6807\u8bb0\u5f53\u65e5\u5df2\u7533\u8d2d\n        g.ipo_done = True\n\n\ndef interval_handle(context):\n    \"\"\"\u5468\u671f\u5904\u7406\u51fd\u6570\n\n    :param context: \u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :return: None\n    \"\"\"\n\n    # \u5356\u51fa\n    handle_sell(context)\n\n    # \u4e70\u5165\n    handle_buy(context)\n\n    # \u6253\u65b0\n    handle_ipo()\n\n\ndef on_order_response(context, order_list):\n    \"\"\"\u5728\u59d4\u6258\u56de\u62a5\u8fd4\u56de\u65f6\u54cd\u5e94\n\n    :param context: \u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :param order_list: \u4e00\u4e2a\u5217\u8868\uff0c\u5f53\u524d\u59d4\u6258\u5355\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u53d1\u751f\u53d8\u5316\u7684\u59d4\u6258\u5355\u5217\u8868\u3002\u59d4\u6258\u5355\u4ee5\u5b57\u5178\u5f62\u5f0f\u5c55\u73b0\uff0c\u5185\u5bb9\u5305\u62ec\uff1a'entrust_no'(\u59d4\u6258\u5355\u53f7), \n                       'order_time'(\u59d4\u6258\u65f6\u95f4), 'stock_code'(\u80a1\u7968\u4ee3\u7801), 'amount'(\u59d4\u6258\u6570\u91cf), 'price'(\u59d4\u6258\u4ef7\u683c), 'business_amount'(\u6210\u4ea4\u6570\u91cf), \n                       'status'(\u59d4\u6258\u72b6\u6001), 'order_id'(\u59d4\u6258\u8ba2\u5355\u53f7), 'entrust_type'(\u59d4\u6258\u7c7b\u522b), 'entrust_prop'(\u59d4\u6258\u5c5e\u6027)\n    :return: None\n    \"\"\"\n\n    # \u6253\u5370\u59d4\u6258\u6570\u636e\n    for order in order_list:\n        bs = '\u4e70\u5165' if order['amount'] &gt; 0 else '\u5356\u51fa'\n        info = '\u8ba2\u5355\u63d0\u4ea4\uff0c\u80a1\u7968\u4ee3\u7801\uff1a{}\uff0c\u6570\u91cf\uff1a{}{:.0f}'.format(order['stock_code'], bs, abs(order['amount']))\n        log.info(info)\n\n\ndef on_trade_response(context, trade_list):\n    \"\"\"\u5728\u6210\u4ea4\u56de\u62a5\u8fd4\u56de\u65f6\u54cd\u5e94\n\n    :param context: \u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :param trade_list\uff1a \u4e00\u4e2a\u5217\u8868\uff0c\u5f53\u524d\u6210\u4ea4\u5355\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u53d1\u751f\u53d8\u5316\u7684\u6210\u4ea4\u5355\u5217\u8868\u3002\u6210\u4ea4\u5355\u4ee5\u5b57\u5178\u5f62\u5f0f\u5c55\u73b0\uff0c\u5185\u5bb9\u5305\u62ec\uff1a'entrust_no'(\u59d4\u6258\u5355\u53f7),\n                        'business_time'(\u6210\u4ea4\u65f6\u95f4), 'stock_code'(\u80a1\u7968\u4ee3\u7801), 'entrust_bs'(\u6210\u4ea4\u65b9\u5411), 'business_amount'(\u6210\u4ea4\u6570\u91cf), \n                        'business_price'(\u6210\u4ea4\u4ef7\u683c), 'business_balance'(\u6210\u4ea4\u989d), 'business_id'(\u6210\u4ea4\u7f16\u53f7), 'status'(\u59d4\u6258\u72b6\u6001)\n    :return: None\n    \"\"\"\n\n    # \u6253\u5370\u6210\u4ea4\u6570\u636e\n    for trade in trade_list:\n        bs = '\u4e70\u5165' if trade['business_amount'] &gt; 0 else '\u5356\u51fa'    \n        info = '\u8ba2\u5355\u6210\u4ea4\uff0c\u80a1\u7968\u4ee3\u7801\uff1a{}\uff0c\u6570\u91cf\uff1a{}{:.0f}'.format(trade['stock_code'], bs, abs(trade['business_amount']))\n        log.info(info)\n\n\ndef after_trading_end(context, data):\n    \"\"\"\u5728\u6bcf\u5929\u4ea4\u6613\u7ed3\u675f\u4e4b\u540e\u8c03\u7528\uff0c\u7528\u6765\u5904\u7406\u6bcf\u5929\u6536\u76d8\u540e\u7684\u64cd\u4f5c\n\n    :param context: \u5b58\u653e\u6709\u5f53\u524d\u7684\u8d26\u6237\u53ca\u6301\u4ed3\u4fe1\u606f\n    :param data\uff1a \u4fdd\u7559\u5b57\u6bb5\u6682\u65e0\u6570\u636e\n    :return: None\n    \"\"\"\n\n    # \u6253\u5370\u76d8\u540e\u6301\u80a1\u6570\u636e\n    log.info('\u76d8\u540e\u6301\u80a1{}\u53ea\uff1a{}'.format(get_position_count(context), get_position_list(context)))\n<\/code><\/pre>\n<hr \/>\n<p><strong>\u535a\u5ba2\u5185\u5bb9\u53ea\u7528\u4e8e\u4ea4\u6d41\u5b66\u4e60\uff0c\u4e0d\u6784\u6210\u6295\u8d44\u5efa\u8bae\uff0c\u76c8\u4e8f\u81ea\u8d1f\uff01<\/strong><\/p>\n<p>\u6b22\u8fce\u5927\u5bb6\u8f6c\u53d1\u3001\u7559\u8a00\u3002\u5df2\u5efa\u5fae\u4fe1\u7fa4\u7528\u4e8e\u5b66\u4e60\u4ea4\u6d41\uff0c\u7fa41\u5df2\u6ee1\uff0c\u7fa42\u5df2\u521b\u5efa\uff0c\u611f\u5174\u8da3\u7684\u8bfb\u8005\u8bf7\u626b\u7801\u52a0\u5fae\u4fe1\uff01<br \/>\n\u9879\u76ee\u6700\u65b0\u4ee3\u7801\uff1ahttps:\/\/gitee.com\/sl\/quant_from_scratch<br \/>\n\u5982\u679c\u8ba4\u4e3a\u535a\u5ba2\u5bf9\u60a8\u6709\u5e2e\u52a9\uff0c\u53ef\u4ee5\u626b\u7801\u8fdb\u884c\u6350\u8d60\uff0c\u611f\u8c22\uff01<\/p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">\u5fae\u4fe1\u4e8c\u7ef4\u7801<\/th>\n<th align=\"center\">\u5fae\u4fe1\u6350\u8d60\u4e8c\u7ef4\u7801<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td align=\"center\"><img decoding=\"async\" src=\"http:\/\/coderx.com.cn\/wordpress\/wp-content\/uploads\/2021\/11\/wechat_margin.png\" alt=\"\u5fae\u4fe1\u4e8c\u7ef4\u7801\" \/><\/td>\n<td align=\"center\"><img decoding=\"async\" src=\"http:\/\/coderx.com.cn\/\/wordpress\/wp-content\/uploads\/2021\/09\/wechatpay.png\" alt=\"\u6350\u8d60\u4e8c\u7ef4\u7801\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<style>\npre{\n    white-space: pre;\n    overflow-x: auto;\n    overflow-y: auto;\n    max-height: 300px;\n}\n.table-wrapper {\n    overflow-x: auto;\n    overflow-y: auto;\n    white-space: nowrap;\n    max-height: 300px;\n}\n<\/style>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u9898\uff0c\u672c\u6587\u5c06\u4ecb\u7ecdPTrade\u5b9e\u76d8\u4ea4\u6613\u7a0b\u5e8f\u7684\u4ee3\u7801\u3002 \u5982\u4f55\u5728PTrade\u4e2d\u90e8\u7f72\u7b56\u7565\uff0c\u53ef\u4ee5\u53c2\u89c1\u524d\u6587\u4e2d\u201cPTrade\u90e8 &#8230; <a title=\"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819\" class=\"read-more\" href=\"\/?p=439\" aria-label=\"\u7ee7\u7eed\u9605\u8bfbPTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2],"tags":[],"class_list":["post-439","post","type-post","status-publish","format-standard","hentry","category-ptrade","category-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/coderx.com.cn\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab\" \/>\n<meta property=\"og:description\" content=\"\u5982\u9898\uff0c\u672c\u6587\u5c06\u4ecb\u7ecdPTrade\u5b9e\u76d8\u4ea4\u6613\u7a0b\u5e8f\u7684\u4ee3\u7801\u3002 \u5982\u4f55\u5728PTrade\u4e2d\u90e8\u7f72\u7b56\u7565\uff0c\u53ef\u4ee5\u53c2\u89c1\u524d\u6587\u4e2d\u201cPTrade\u90e8 ... \u9605\u8bfb\u66f4\u591a\" \/>\n<meta property=\"og:url\" content=\"\/?p=439\" \/>\n<meta property=\"og:site_name\" content=\"Python\u91cf\u5316\u6280\u672f\u5206\u4eab\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-29T14:33:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-23T10:40:59+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/coderx.com.cn\/wordpress\/wp-content\/uploads\/2021\/11\/wechat_margin.png\" \/>\n<meta name=\"author\" content=\"mnj\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"mnj\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/coderx.com.cn\/#article\",\"isPartOf\":{\"@id\":\"\/?p=439\"},\"author\":{\"name\":\"mnj\",\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/78b42c511f286896ba4b458160bdabc6\"},\"headline\":\"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819\",\"datePublished\":\"2021-12-29T14:33:58+00:00\",\"dateModified\":\"2023-09-23T10:40:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"\/?p=439\"},\"wordCount\":149,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/78b42c511f286896ba4b458160bdabc6\"},\"articleSection\":[\"ptrade\",\"\u4ece\u96f6\u5230\u5b9e\u76d8\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/coderx.com.cn\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"\/?p=439\",\"url\":\"http:\/\/coderx.com.cn\/\",\"name\":\"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab\",\"isPartOf\":{\"@id\":\"http:\/\/coderx.com.cn\/#website\"},\"datePublished\":\"2021-12-29T14:33:58+00:00\",\"dateModified\":\"2023-09-23T10:40:59+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/coderx.com.cn\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/coderx.com.cn\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/coderx.com.cn\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/coderx.com.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/coderx.com.cn\/#website\",\"url\":\"http:\/\/coderx.com.cn\/\",\"name\":\"Python\u91cf\u5316\u6280\u672f\u5206\u4eab-\u7801\u519c\u7532\u7684\u5b66\u4e60\u7b14\u8bb0\",\"description\":\"\u7801\u519c\u7532\u7684\u5b66\u4e60\u7b14\u8bb0\",\"publisher\":{\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/78b42c511f286896ba4b458160bdabc6\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/coderx.com.cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/78b42c511f286896ba4b458160bdabc6\",\"name\":\"mnj\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/image\/\",\"url\":\"\/wordpress\/wp-content\/uploads\/2021\/09\/cropped-1-2.jpg\",\"contentUrl\":\"\/wordpress\/wp-content\/uploads\/2021\/09\/cropped-1-2.jpg\",\"width\":951,\"height\":189,\"caption\":\"mnj\"},\"logo\":{\"@id\":\"http:\/\/coderx.com.cn\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/coderx.com.cn\/","og_locale":"zh_CN","og_type":"article","og_title":"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab","og_description":"\u5982\u9898\uff0c\u672c\u6587\u5c06\u4ecb\u7ecdPTrade\u5b9e\u76d8\u4ea4\u6613\u7a0b\u5e8f\u7684\u4ee3\u7801\u3002 \u5982\u4f55\u5728PTrade\u4e2d\u90e8\u7f72\u7b56\u7565\uff0c\u53ef\u4ee5\u53c2\u89c1\u524d\u6587\u4e2d\u201cPTrade\u90e8 ... \u9605\u8bfb\u66f4\u591a","og_url":"\/?p=439","og_site_name":"Python\u91cf\u5316\u6280\u672f\u5206\u4eab","article_published_time":"2021-12-29T14:33:58+00:00","article_modified_time":"2023-09-23T10:40:59+00:00","og_image":[{"url":"http:\/\/coderx.com.cn\/wordpress\/wp-content\/uploads\/2021\/11\/wechat_margin.png"}],"author":"mnj","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"mnj","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/coderx.com.cn\/#article","isPartOf":{"@id":"\/?p=439"},"author":{"name":"mnj","@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/78b42c511f286896ba4b458160bdabc6"},"headline":"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819","datePublished":"2021-12-29T14:33:58+00:00","dateModified":"2023-09-23T10:40:59+00:00","mainEntityOfPage":{"@id":"\/?p=439"},"wordCount":149,"commentCount":0,"publisher":{"@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/78b42c511f286896ba4b458160bdabc6"},"articleSection":["ptrade","\u4ece\u96f6\u5230\u5b9e\u76d8"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/coderx.com.cn\/#respond"]}]},{"@type":"WebPage","@id":"\/?p=439","url":"http:\/\/coderx.com.cn\/","name":"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819 - Python\u91cf\u5316\u6280\u672f\u5206\u4eab","isPartOf":{"@id":"http:\/\/coderx.com.cn\/#website"},"datePublished":"2021-12-29T14:33:58+00:00","dateModified":"2023-09-23T10:40:59+00:00","breadcrumb":{"@id":"http:\/\/coderx.com.cn\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/coderx.com.cn\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/coderx.com.cn\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/coderx.com.cn\/"},{"@type":"ListItem","position":2,"name":"PTrade\u4ea4\u6613\u7a0b\u5e8f\u4ee3\u7801\u2014\u2014\u4ece\u96f6\u5230\u5b9e\u76d819"}]},{"@type":"WebSite","@id":"http:\/\/coderx.com.cn\/#website","url":"http:\/\/coderx.com.cn\/","name":"Python\u91cf\u5316\u6280\u672f\u5206\u4eab-\u7801\u519c\u7532\u7684\u5b66\u4e60\u7b14\u8bb0","description":"\u7801\u519c\u7532\u7684\u5b66\u4e60\u7b14\u8bb0","publisher":{"@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/78b42c511f286896ba4b458160bdabc6"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/coderx.com.cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/78b42c511f286896ba4b458160bdabc6","name":"mnj","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/image\/","url":"\/wordpress\/wp-content\/uploads\/2021\/09\/cropped-1-2.jpg","contentUrl":"\/wordpress\/wp-content\/uploads\/2021\/09\/cropped-1-2.jpg","width":951,"height":189,"caption":"mnj"},"logo":{"@id":"http:\/\/coderx.com.cn\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=439"}],"version-history":[{"count":4,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/439\/revisions"}],"predecessor-version":[{"id":490,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/439\/revisions\/490"}],"wp:attachment":[{"href":"http:\/\/coderx.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/coderx.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}