{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import dolphindb as ddb\n", "import dolphindb.settings as keys\n", "import numpy as np\n", "import pandas as pd\n", "\n", "\n", "sess = ddb.session('192.168.64.3',8848)\n", "sess.login('admin','123456')\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sess.clearAllCache()" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'/hft_fm_combo': 'pt:2:0:pt_2; ',\n", " '/db_compo_test': 'pt:2:0:pt_2; ',\n", " '/compoDB': 'pt:2:0:pt_2; ',\n", " '/daily_futuremarket_ts': 'db_daily_kline:2:0:db_daily_kline_2; '}" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sess.run('getAllDBs()')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
StockIDopenhighlowclosevolsectional_volcjbssectional_cjbspriceyclosebuy_volbuy_amountsale_volsale_amountzmmamountdatetime1
17AP22128387.08387.08387.08387.09.09.0-9.0195658387.08413.04.537741.54.537741.5375483.02022-09-1908:59:00
18AP22128361.08361.08361.08361.08.017.00.0195658361.08387.00.00.08.066892.0266892.02022-09-1909:00:00
19AP22128356.08356.08356.08356.06.023.00.0195658356.08361.00.00.06.050158.0250158.02022-09-1909:00:00
25AP22128356.08356.08356.08356.01.024.00.0195658356.08356.00.00.01.08347.028347.02022-09-1909:00:05
30AP22128397.08397.08397.08397.01.025.0-1.0195648397.08356.01.08395.00.00.018395.02022-09-1909:00:09
............................................................
2336544AP22128744.08744.08744.08744.01.02583.00.0137188744.08756.00.00.01.08722.028722.02022-11-0109:25:28
2336547AP22128746.08746.08746.08746.01.02584.00.0137188746.08744.00.00.01.08722.028722.02022-11-0109:25:34
2336549AP22128743.08743.08743.08743.01.02585.00.0137188743.08746.00.00.01.08722.028722.02022-11-0109:25:37
2336592AP22128747.08747.08747.08747.02.02587.00.0137188747.08743.00.00.02.017444.0217444.02022-11-0109:26:59
2336594AP22128747.08747.08747.08747.03.02590.03.0137218747.08747.03.026166.00.00.0126166.02022-11-0109:27:03
\n", "

40456 rows × 19 columns

\n", "
" ], "text/plain": [ " StockID open high low close vol sectional_vol cjbs \\\n", "17 AP2212 8387.0 8387.0 8387.0 8387.0 9.0 9.0 -9.0 \n", "18 AP2212 8361.0 8361.0 8361.0 8361.0 8.0 17.0 0.0 \n", "19 AP2212 8356.0 8356.0 8356.0 8356.0 6.0 23.0 0.0 \n", "25 AP2212 8356.0 8356.0 8356.0 8356.0 1.0 24.0 0.0 \n", "30 AP2212 8397.0 8397.0 8397.0 8397.0 1.0 25.0 -1.0 \n", "... ... ... ... ... ... ... ... ... \n", "2336544 AP2212 8744.0 8744.0 8744.0 8744.0 1.0 2583.0 0.0 \n", "2336547 AP2212 8746.0 8746.0 8746.0 8746.0 1.0 2584.0 0.0 \n", "2336549 AP2212 8743.0 8743.0 8743.0 8743.0 1.0 2585.0 0.0 \n", "2336592 AP2212 8747.0 8747.0 8747.0 8747.0 2.0 2587.0 0.0 \n", "2336594 AP2212 8747.0 8747.0 8747.0 8747.0 3.0 2590.0 3.0 \n", "\n", " sectional_cjbs price yclose buy_vol buy_amount sale_vol \\\n", "17 19565 8387.0 8413.0 4.5 37741.5 4.5 \n", "18 19565 8361.0 8387.0 0.0 0.0 8.0 \n", "19 19565 8356.0 8361.0 0.0 0.0 6.0 \n", "25 19565 8356.0 8356.0 0.0 0.0 1.0 \n", "30 19564 8397.0 8356.0 1.0 8395.0 0.0 \n", "... ... ... ... ... ... ... \n", "2336544 13718 8744.0 8756.0 0.0 0.0 1.0 \n", "2336547 13718 8746.0 8744.0 0.0 0.0 1.0 \n", "2336549 13718 8743.0 8746.0 0.0 0.0 1.0 \n", "2336592 13718 8747.0 8743.0 0.0 0.0 2.0 \n", "2336594 13721 8747.0 8747.0 3.0 26166.0 0.0 \n", "\n", " sale_amount zmm amount date time1 \n", "17 37741.5 3 75483.0 2022-09-19 08:59:00 \n", "18 66892.0 2 66892.0 2022-09-19 09:00:00 \n", "19 50158.0 2 50158.0 2022-09-19 09:00:00 \n", "25 8347.0 2 8347.0 2022-09-19 09:00:05 \n", "30 0.0 1 8395.0 2022-09-19 09:00:09 \n", "... ... ... ... ... ... \n", "2336544 8722.0 2 8722.0 2022-11-01 09:25:28 \n", "2336547 8722.0 2 8722.0 2022-11-01 09:25:34 \n", "2336549 8722.0 2 8722.0 2022-11-01 09:25:37 \n", "2336592 17444.0 2 17444.0 2022-11-01 09:26:59 \n", "2336594 0.0 1 26166.0 2022-11-01 09:27:03 \n", "\n", "[40456 rows x 19 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "df = pd.read_csv('data/trade_AP2211+AP2212+AP2301+AP2303+AP2304+AP2305+AP2310+CF2211+CF2301+CF2303+CF2305+CF2307+CF2309_20220919_20221101.csv',index_col=None)\n", "df.drop(columns=['Unnamed: 0'],inplace=True)\n", "df=df[df['time1']<'09:30:00']\n", "df = df[df['vol']>0]\n", "df['date']=df['date'].astype('datetime64[D]')\n", "df" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "df['init']=df['init'].astype('str')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "df['init']=df['StockID'].apply(lambda x:x[:-4])\n", "df['finishm']=df['StockID'].apply(lambda x:x[-4:])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['AP'], dtype=object)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df['init'].unique()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "71" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all_init={'sc', 'v', 'TS', 'MA', 'AP', 'jm', 'bc', 'bb', 'fu', 'IM', 'IF', 'a', 'lu', 'FG', 'cu', 'al', 'IH', 'RS', 'pg', 'CF', 'SF', 'ni', 'hc', 'UR', 'm', 'SR', 'j', 'PF', 'RM', 'T', 'c', 'JR', 'l', 'p', 'sp', 'CY', 'pb', 'TF', 'b', 'eg', 'rb', 'PK', 'sn', 'nr', 'pp', 'CJ', 'eb', 'SA', 'y', 'RI', 'lh', 'jd', 'OI', 'WH', 'ss', 'ru', 'zn', 'fb', 'rr', 'PM', 'au', 'TA', 'ZC', 'IC', 'bu', 'SM', 'wr', 'cs', 'LR', 'ag', 'i'}\n", "len(all_init)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "db_init = sess.database(dbName='db_init', partitionType=keys.VALUE, partitions=list(all_init),dbPath='')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "db_code = sess.database(dbName='db_code', partitionType=keys.HASH, partitions=list(all_init),dbPath='')" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "DatetimeIndex(['1990-01-31', '1990-02-28', '1990-03-31', '1990-04-30',\n", " '1990-05-31', '1990-06-30', '1990-07-31', '1990-08-31',\n", " '1990-09-30', '1990-10-31',\n", " ...\n", " '2050-03-31', '2050-04-30', '2050-05-31', '2050-06-30',\n", " '2050-07-31', '2050-08-31', '2050-09-30', '2050-10-31',\n", " '2050-11-30', '2050-12-31'],\n", " dtype='datetime64[ns]', length=732, freq='M')\n" ] } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "dr = pd.date_range(start='1990-01-01', end='2050-12-31', freq=\"M\")\n", "months=np.array(dr, dtype=\"datetime64[M]\")\n", "print(dr)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['1990-01' '1990-02' '1990-03' '1990-04' '1990-05' '1990-06' '1990-07'\n", " '1990-08' '1990-09' '1990-10' '1990-11' '1990-12' '1991-01' '1991-02'\n", " '1991-03' '1991-04' '1991-05' '1991-06' '1991-07' '1991-08' '1991-09'\n", " '1991-10' '1991-11' '1991-12' '1992-01' '1992-02' '1992-03' '1992-04'\n", " '1992-05' '1992-06' '1992-07' '1992-08' '1992-09' '1992-10' '1992-11'\n", " '1992-12' '1993-01' '1993-02' '1993-03' '1993-04' '1993-05' '1993-06'\n", " '1993-07' '1993-08' '1993-09' '1993-10' '1993-11' '1993-12' '1994-01'\n", " '1994-02' '1994-03' '1994-04' '1994-05' '1994-06' '1994-07' '1994-08'\n", " '1994-09' '1994-10' '1994-11' '1994-12' '1995-01' '1995-02' '1995-03'\n", " '1995-04' '1995-05' '1995-06' '1995-07' '1995-08' '1995-09' '1995-10'\n", " '1995-11' '1995-12' '1996-01' '1996-02' '1996-03' '1996-04' '1996-05'\n", " '1996-06' '1996-07' '1996-08' '1996-09' '1996-10' '1996-11' '1996-12'\n", " '1997-01' '1997-02' '1997-03' '1997-04' '1997-05' '1997-06' '1997-07'\n", " '1997-08' '1997-09' '1997-10' '1997-11' '1997-12' '1998-01' '1998-02'\n", " '1998-03' '1998-04' '1998-05' '1998-06' '1998-07' '1998-08' '1998-09'\n", " '1998-10' '1998-11' '1998-12' '1999-01' '1999-02' '1999-03' '1999-04'\n", " '1999-05' '1999-06' '1999-07' '1999-08' '1999-09' '1999-10' '1999-11'\n", " '1999-12' '2000-01' '2000-02' '2000-03' '2000-04' '2000-05' '2000-06'\n", " '2000-07' '2000-08' '2000-09' '2000-10' '2000-11' '2000-12' '2001-01'\n", " '2001-02' '2001-03' '2001-04' '2001-05' '2001-06' '2001-07' '2001-08'\n", " '2001-09' '2001-10' '2001-11' '2001-12' '2002-01' '2002-02' '2002-03'\n", " '2002-04' '2002-05' '2002-06' '2002-07' '2002-08' '2002-09' '2002-10'\n", " '2002-11' '2002-12' '2003-01' '2003-02' '2003-03' '2003-04' '2003-05'\n", " '2003-06' '2003-07' '2003-08' '2003-09' '2003-10' '2003-11' '2003-12'\n", " '2004-01' '2004-02' '2004-03' '2004-04' '2004-05' '2004-06' '2004-07'\n", " '2004-08' '2004-09' '2004-10' '2004-11' '2004-12' '2005-01' '2005-02'\n", " '2005-03' '2005-04' '2005-05' '2005-06' '2005-07' '2005-08' '2005-09'\n", " '2005-10' '2005-11' '2005-12' '2006-01' '2006-02' '2006-03' '2006-04'\n", " '2006-05' '2006-06' '2006-07' '2006-08' '2006-09' '2006-10' '2006-11'\n", " '2006-12' '2007-01' '2007-02' '2007-03' '2007-04' '2007-05' '2007-06'\n", " '2007-07' '2007-08' '2007-09' '2007-10' '2007-11' '2007-12' '2008-01'\n", " '2008-02' '2008-03' '2008-04' '2008-05' '2008-06' '2008-07' '2008-08'\n", " '2008-09' '2008-10' '2008-11' '2008-12' '2009-01' '2009-02' '2009-03'\n", " '2009-04' '2009-05' '2009-06' '2009-07' '2009-08' '2009-09' '2009-10'\n", " '2009-11' '2009-12' '2010-01' '2010-02' '2010-03' '2010-04' '2010-05'\n", " '2010-06' '2010-07' '2010-08' '2010-09' '2010-10' '2010-11' '2010-12'\n", " '2011-01' '2011-02' '2011-03' '2011-04' '2011-05' '2011-06' '2011-07'\n", " '2011-08' '2011-09' '2011-10' '2011-11' '2011-12' '2012-01' '2012-02'\n", " '2012-03' '2012-04' '2012-05' '2012-06' '2012-07' '2012-08' '2012-09'\n", " '2012-10' '2012-11' '2012-12' '2013-01' '2013-02' '2013-03' '2013-04'\n", " '2013-05' '2013-06' '2013-07' '2013-08' '2013-09' '2013-10' '2013-11'\n", " '2013-12' '2014-01' '2014-02' '2014-03' '2014-04' '2014-05' '2014-06'\n", " '2014-07' '2014-08' '2014-09' '2014-10' '2014-11' '2014-12' '2015-01'\n", " '2015-02' '2015-03' '2015-04' '2015-05' '2015-06' '2015-07' '2015-08'\n", " '2015-09' '2015-10' '2015-11' '2015-12' '2016-01' '2016-02' '2016-03'\n", " '2016-04' '2016-05' '2016-06' '2016-07' '2016-08' '2016-09' '2016-10'\n", " '2016-11' '2016-12' '2017-01' '2017-02' '2017-03' '2017-04' '2017-05'\n", " '2017-06' '2017-07' '2017-08' '2017-09' '2017-10' '2017-11' '2017-12'\n", " '2018-01' '2018-02' '2018-03' '2018-04' '2018-05' '2018-06' '2018-07'\n", " '2018-08' '2018-09' '2018-10' '2018-11' '2018-12' '2019-01' '2019-02'\n", " '2019-03' '2019-04' '2019-05' '2019-06' '2019-07' '2019-08' '2019-09'\n", " '2019-10' '2019-11' '2019-12' '2020-01' '2020-02' '2020-03' '2020-04'\n", " '2020-05' '2020-06' '2020-07' '2020-08' '2020-09' '2020-10' '2020-11'\n", " '2020-12' '2021-01' '2021-02' '2021-03' '2021-04' '2021-05' '2021-06'\n", " '2021-07' '2021-08' '2021-09' '2021-10' '2021-11' '2021-12' '2022-01'\n", " '2022-02' '2022-03' '2022-04' '2022-05' '2022-06' '2022-07' '2022-08'\n", " '2022-09' '2022-10' '2022-11' '2022-12' '2023-01' '2023-02' '2023-03'\n", " '2023-04' '2023-05' '2023-06' '2023-07' '2023-08' '2023-09' '2023-10'\n", " '2023-11' '2023-12' '2024-01' '2024-02' '2024-03' '2024-04' '2024-05'\n", " '2024-06' '2024-07' '2024-08' '2024-09' '2024-10' '2024-11' '2024-12'\n", " '2025-01' '2025-02' '2025-03' '2025-04' '2025-05' '2025-06' '2025-07'\n", " '2025-08' '2025-09' '2025-10' '2025-11' '2025-12' '2026-01' '2026-02'\n", " '2026-03' '2026-04' '2026-05' '2026-06' '2026-07' '2026-08' '2026-09'\n", " '2026-10' '2026-11' '2026-12' '2027-01' '2027-02' '2027-03' '2027-04'\n", " '2027-05' '2027-06' '2027-07' '2027-08' '2027-09' '2027-10' '2027-11'\n", " '2027-12' '2028-01' '2028-02' '2028-03' '2028-04' '2028-05' '2028-06'\n", " '2028-07' '2028-08' '2028-09' '2028-10' '2028-11' '2028-12' '2029-01'\n", " '2029-02' '2029-03' '2029-04' '2029-05' '2029-06' '2029-07' '2029-08'\n", " '2029-09' '2029-10' '2029-11' '2029-12' '2030-01' '2030-02' '2030-03'\n", " '2030-04' '2030-05' '2030-06' '2030-07' '2030-08' '2030-09' '2030-10'\n", " '2030-11' '2030-12' '2031-01' '2031-02' '2031-03' '2031-04' '2031-05'\n", " '2031-06' '2031-07' '2031-08' '2031-09' '2031-10' '2031-11' '2031-12'\n", " '2032-01' '2032-02' '2032-03' '2032-04' '2032-05' '2032-06' '2032-07'\n", " '2032-08' '2032-09' '2032-10' '2032-11' '2032-12' '2033-01' '2033-02'\n", " '2033-03' '2033-04' '2033-05' '2033-06' '2033-07' '2033-08' '2033-09'\n", " '2033-10' '2033-11' '2033-12' '2034-01' '2034-02' '2034-03' '2034-04'\n", " '2034-05' '2034-06' '2034-07' '2034-08' '2034-09' '2034-10' '2034-11'\n", " '2034-12' '2035-01' '2035-02' '2035-03' '2035-04' '2035-05' '2035-06'\n", " '2035-07' '2035-08' '2035-09' '2035-10' '2035-11' '2035-12' '2036-01'\n", " '2036-02' '2036-03' '2036-04' '2036-05' '2036-06' '2036-07' '2036-08'\n", " '2036-09' '2036-10' '2036-11' '2036-12' '2037-01' '2037-02' '2037-03'\n", " '2037-04' '2037-05' '2037-06' '2037-07' '2037-08' '2037-09' '2037-10'\n", " '2037-11' '2037-12' '2038-01' '2038-02' '2038-03' '2038-04' '2038-05'\n", " '2038-06' '2038-07' '2038-08' '2038-09' '2038-10' '2038-11' '2038-12'\n", " '2039-01' '2039-02' '2039-03' '2039-04' '2039-05' '2039-06' '2039-07'\n", " '2039-08' '2039-09' '2039-10' '2039-11' '2039-12' '2040-01' '2040-02'\n", " '2040-03' '2040-04' '2040-05' '2040-06' '2040-07' '2040-08' '2040-09'\n", " '2040-10' '2040-11' '2040-12' '2041-01' '2041-02' '2041-03' '2041-04'\n", " '2041-05' '2041-06' '2041-07' '2041-08' '2041-09' '2041-10' '2041-11'\n", " '2041-12' '2042-01' '2042-02' '2042-03' '2042-04' '2042-05' '2042-06'\n", " '2042-07' '2042-08' '2042-09' '2042-10' '2042-11' '2042-12' '2043-01'\n", " '2043-02' '2043-03' '2043-04' '2043-05' '2043-06' '2043-07' '2043-08'\n", " '2043-09' '2043-10' '2043-11' '2043-12' '2044-01' '2044-02' '2044-03'\n", " '2044-04' '2044-05' '2044-06' '2044-07' '2044-08' '2044-09' '2044-10'\n", " '2044-11' '2044-12' '2045-01' '2045-02' '2045-03' '2045-04' '2045-05'\n", " '2045-06' '2045-07' '2045-08' '2045-09' '2045-10' '2045-11' '2045-12'\n", " '2046-01' '2046-02' '2046-03' '2046-04' '2046-05' '2046-06' '2046-07'\n", " '2046-08' '2046-09' '2046-10' '2046-11' '2046-12' '2047-01' '2047-02'\n", " '2047-03' '2047-04' '2047-05' '2047-06' '2047-07' '2047-08' '2047-09'\n", " '2047-10' '2047-11' '2047-12' '2048-01' '2048-02' '2048-03' '2048-04'\n", " '2048-05' '2048-06' '2048-07' '2048-08' '2048-09' '2048-10' '2048-11'\n", " '2048-12' '2049-01' '2049-02' '2049-03' '2049-04' '2049-05' '2049-06'\n", " '2049-07' '2049-08' '2049-09' '2049-10' '2049-11' '2049-12' '2050-01'\n", " '2050-02' '2050-03' '2050-04' '2050-05' '2050-06' '2050-07' '2050-08'\n", " '2050-09' '2050-10' '2050-11' '2050-12']\n" ] } ], "source": [ "months=np.array(pd.date_range(start='2000-01-01', end='2050-12-31', freq=\"M\"), dtype=\"datetime64[M]\")\n", "print(months)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "\n", "db_date = sess.database('db_date', partitionType=keys.VALUE, partitions=months, dbPath='')\n" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "dbPath = 'dfs://hft_fm_combo'\n", "if sess.existsDatabase(dbPath): \n", " sess.dropDatabase(dbPath)\n", "db = sess.database(dbName='db_hft_fm_3', partitionType=keys.COMPO, partitions=[db_date, db_init], dbPath=dbPath)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# sess.run(\"\"\"\n", "# {dbName} = database(\n", "# directory = '{dbPath}', \n", "# partitionType = COMPO, \n", "# partitionScheme = [db_date, db_init])\n", "# \"\"\".format(\n", "# dbName = 'db_hft_fm_3',\n", "# dbPath = 'hft_futuremarket_ts_combo'\n", "# ))" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "t = sess.table(data=df,tableAliasName='table')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sess.run(\"\"\"\n", " {ddb_dbname}.createPartitionedTable(\n", " table = {memory_table_name}, \n", " tableName = `{partition_table_name}, \n", " partitionColumns = `date`StockID, \n", " sortColumns = `StockID`date,\n", " compressMethods = {{date:\"delta\"}}\n", " )\n", " \"\"\".format(\n", " ddb_dbname = 'db_hft_fm_3',\n", " memory_table_name = 'testData',\n", " partition_table_name = 'pt3'\n", " ))" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "pt =db.createPartitionedTable(table=t, tableName=\"pt\", partitionColumns=['date', 'init'])" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pt.append(t)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'/hft_fm_combo': 'pt:2:0:pt_2; ',\n", " '/db_compo_test': 'pt:2:0:pt_2; ',\n", " '/compoDB': 'pt:2:0:pt_2; ',\n", " '/daily_futuremarket_ts': 'db_daily_kline:2:0:db_daily_kline_2; '}" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sess.run('getAllDBs()')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame({'date': np.array(['2012-01-01', '2012-02-01', '2012-05-01', '2012-06-01'], dtype=\"datetime64\"), 'val':[1,2,3,4],'code':['AP2313','FD1023','AP1023','ED2333']})\n", "df\n", "df['init']=df['code'].apply(lambda x: x[:2])\n", "df\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "dbPath=\"dfs://db_compo_test\"\n", "if sess.existsDatabase(dbPath):\n", " sess.dropDatabase(dbPath)\n", "\n", "months=np.array(pd.date_range(start='2012-01', end='2012-10', freq=\"M\"), dtype=\"datetime64[M]\")\n", "\n", "db1 = sess.database('db1', partitionType=keys.VALUE,partitions=months, dbPath='')\n", "\n", "db2 = sess.database('db2', partitionType=keys.RANGE,partitions=[1, 6, 11], dbPath='')\n", "# dbPath=\"dfs://db_compo_test\"\n", "if sess.existsDatabase(dbPath):\n", " sess.dropDatabase(dbPath)\n", "db = sess.database(dbName='mydb', partitionType=keys.COMPO, partitions=[db1, db2], dbPath=dbPath)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df2 = pd.DataFrame({'date':np.array(['2012-01-01', '2012-01-01', '2012-02-06', '2012-03-06'], dtype='datetime64'), 'val': [1, 6, 1, 6]})\n", "t = sess.table(data=df2)\n", "# df['date'].dtype()\n", "df2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "db.createPartitionedTable(table=t, tableName='pt', partitionColumns=['date', 'val']).append(t)\n", "re = sess.loadTable(tableName='pt', dbPath=dbPath).toDF()" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2022-11-09 15:44:17.606 | INFO | src.TSLfm:__enter__:18 - Logging in TSL.\n", "2022-11-09 15:44:17.762 | DEBUG | src.TSLfm:get_trade_tick:136 - \n", " stock_list := Array('CF2211', 'CF2301', 'CF2303', 'CF2305', 'CF2307', 'CF2309');\n", " r := select \n", " ['StockID'] as 'code',\n", " DateTimeToStr(['date']) as 'm_nDatetime',\n", "\n", " ['price'] as 'm_nPrice',\n", " ['open'] as 'm_nOpen',\n", " ['high'] as 'm_nHigh',\n", " ['low'] as 'm_nLow',\n", " ['close'] as 'm_nClose',\n", "\n", " ['sectional_high'] as 'm_nAccHigh',\n", " ['sectional_low'] as 'm_nAccLow',\n", "\n", " ['vol'] as 'm_iVolume', //成交量\n", " ['sectional_vol'] as 'm_iAccVolume', //时点当日累计成交量\n", "\n", " ['cjbs'] as 'm_nMatchItems', // 成交笔数 周期内的持仓的变动量\n", " ['sectional_cjbs'] as 'm_nAccMatchItems',\n", "\n", " ['amount'] as 'm_iTurnover', //成交金额\n", " ['sectional_amount'] as 'm_iAccTurnover', \n", "\n", " ['yclose'] as 'm_nPreClose', //上一周期的收盘价\n", " ['sectional_yclose'] as 'm_nAccPreClose', // 前日收盘\n", " \n", " ['buy1'] as 'm_nBidPrice', //买一价?叫卖价?\n", " ['bc1'] as 'm_nBidVolume', //买一量 当前以买一价出价的委买量\n", " ['sale1'] as 'm_nAskPrice', \n", " ['sc1'] as 'm_nAskVolume', \n", "\n", " ['zmm'] as 'm_iABFlag', //买卖标识\n", "\n", " ['buy_vol'] as 'm_nActBidVolume', //主买量\n", " ['sectional_buy_vol'] as 'm_nAccActBidVolume', //时点当日累计主买量\n", " ['buy_amount'] as 'm_nActBidTurnover', //主买金额\n", " ['sectional_buy_amount'] as 'm_nAccActBidTurnover', \n", "\n", " ['sale_vol'] as 'm_nActAskVolume', \n", " ['sectional_sale_vol'] as 'm_nAccActAskVolume', \n", " ['sale_amount'] as 'm_nActAskTurnover',\n", " ['sectional_sale_amount'] as 'm_nAccActAskTurnover', \n", "\n", " ['w_buy'] as 'm_nBidOrder', //委买\n", " ['sectional_w_buy'] as 'm_nAccBidOrder', \n", " ['w_sale'] as 'm_nAskOrder',\n", " ['sectional_w_sale'] as 'm_nAccAskOrder',\n", "\n", " ['wb'] as 'm_nABOrderRate', //委比\n", " ['sectional_wb'] as 'm_nAccABOrderRate', //时点当日累计委比\n", " ['lb'] as 'm_nMItemsVolRate'//量比\n", "\n", " from tradetable\n", " datekey 20221101T to 20221101T+0.999 \n", " of stock_list\n", " end;\n", " \n", " return r; \n", " \n", "2022-11-09 15:44:37.198 | INFO | src.TSLfm:process_result_data_type:215 - Processing new df of shape (112175, 37), which looks like\n", " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", "0 CF2303 2022-11-01 09:00:00 12365.0 12365.0 12365.0 12365.0 12365.0 \n", "1 CF2303 2022-11-01 09:00:01 12375.0 12375.0 12375.0 12375.0 12375.0 \n", "2 CF2303 2022-11-01 09:00:02 12370.0 12370.0 12370.0 12370.0 12370.0 \n", "3 CF2303 2022-11-01 09:00:02 12370.0 12370.0 12370.0 12370.0 12370.0 \n", "4 CF2303 2022-11-01 09:00:03 12350.0 12350.0 12350.0 12350.0 12350.0 \n", "\n", " m_nAccHigh m_nAccLow m_iVolume m_iAccVolume m_nMatchItems \\\n", "0 12370.0 12250.0 13.0 20959.0 -7.0 \n", "1 12375.0 12250.0 6.0 20965.0 2.0 \n", "2 12375.0 12250.0 2.0 20967.0 -2.0 \n", "3 12375.0 12250.0 1.0 20968.0 -1.0 \n", "4 12375.0 12250.0 21.0 20989.0 0.0 \n", "\n", " m_nAccMatchItems m_iTurnover m_iAccTurnover m_nPreClose m_nAccPreClose \\\n", "0 163532 159965.0 257900495.0 12270.0 12390.0 \n", "1 163534 73830.0 257974325.0 12365.0 12390.0 \n", "2 163532 24610.0 257998935.0 12375.0 12390.0 \n", "3 163531 12305.0 258011240.0 12370.0 12390.0 \n", "4 163531 258405.0 258269645.0 12370.0 12390.0 \n", "\n", " m_nBidPrice m_nBidVolume m_nAskPrice m_nAskVolume m_iABFlag \\\n", "0 12365.0 2 12370.0 1 1 \n", "1 12360.0 2 12370.0 111 1 \n", "2 12345.0 3 12355.0 98 1 \n", "3 12340.0 1 12350.0 97 1 \n", "4 12340.0 10 12350.0 19 1 \n", "\n", " m_nActBidVolume m_nAccActBidVolume m_nActBidTurnover \\\n", "0 13.0 10529.0 159965.0 \n", "1 6.0 10535.0 73830.0 \n", "2 2.0 10537.0 24610.0 \n", "3 1.0 10538.0 12305.0 \n", "4 21.0 10559.0 258405.0 \n", "\n", " m_nAccActBidTurnover m_nActAskVolume m_nAccActAskVolume \\\n", "0 129574875.0 0.0 10430.0 \n", "1 129648705.0 0.0 10430.0 \n", "2 129673315.0 0.0 10430.0 \n", "3 129685620.0 0.0 10430.0 \n", "4 129944025.0 0.0 10430.0 \n", "\n", " m_nActAskTurnover m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder \\\n", "0 0.0 128325620.0 2.0 405687.0 \n", "1 0.0 128325620.0 2.0 405689.0 \n", "2 0.0 128325620.0 3.0 405692.0 \n", "3 0.0 128325620.0 1.0 405693.0 \n", "4 0.0 128325620.0 10.0 405703.0 \n", "\n", " m_nAskOrder m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate \\\n", "0 1.0 352340.0 2.000000 1.151408 \n", "1 111.0 352451.0 0.018018 1.151051 \n", "2 98.0 352549.0 0.030612 1.150739 \n", "3 97.0 352646.0 0.010309 1.150426 \n", "4 19.0 352665.0 0.526316 1.150392 \n", "\n", " m_nMItemsVolRate \n", "0 0.0 \n", "1 0.0 \n", "2 0.0 \n", "3 0.0 \n", "4 0.0 \n", "2022-11-09 15:44:37.288 | INFO | src.TSLfm:process_result_data_type:229 - Processing done, new df looks like\n", " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", "0 CF2303 2022-11-01 09:00:00 12365.0 12365.0 12365.0 12365.0 12365.0 \n", "1 CF2303 2022-11-01 09:00:01 12375.0 12375.0 12375.0 12375.0 12375.0 \n", "2 CF2303 2022-11-01 09:00:02 12370.0 12370.0 12370.0 12370.0 12370.0 \n", "3 CF2303 2022-11-01 09:00:02 12370.0 12370.0 12370.0 12370.0 12370.0 \n", "4 CF2303 2022-11-01 09:00:03 12350.0 12350.0 12350.0 12350.0 12350.0 \n", "\n", " m_nAccHigh m_nAccLow m_iVolume m_iAccVolume m_nMatchItems \\\n", "0 12370.0 12250.0 13 20959 -7 \n", "1 12375.0 12250.0 6 20965 2 \n", "2 12375.0 12250.0 2 20967 -2 \n", "3 12375.0 12250.0 1 20968 -1 \n", "4 12375.0 12250.0 21 20989 0 \n", "\n", " m_nAccMatchItems m_iTurnover m_iAccTurnover m_nPreClose m_nAccPreClose \\\n", "0 32460 159965.0 257900495.0 12270.0 12390.0 \n", "1 32462 73830.0 257974325.0 12365.0 12390.0 \n", "2 32460 24610.0 257998935.0 12375.0 12390.0 \n", "3 32459 12305.0 258011240.0 12370.0 12390.0 \n", "4 32459 258405.0 258269645.0 12370.0 12390.0 \n", "\n", " m_nBidPrice m_nBidVolume m_nAskPrice m_nAskVolume m_iABFlag \\\n", "0 12365.0 2 12370.0 1 1 \n", "1 12360.0 2 12370.0 111 1 \n", "2 12345.0 3 12355.0 98 1 \n", "3 12340.0 1 12350.0 97 1 \n", "4 12340.0 10 12350.0 19 1 \n", "\n", " m_nActBidVolume m_nAccActBidVolume m_nActBidTurnover \\\n", "0 13 10529 159965.0 \n", "1 6 10535 73830.0 \n", "2 2 10537 24610.0 \n", "3 1 10538 12305.0 \n", "4 21 10559 258405.0 \n", "\n", " m_nAccActBidTurnover m_nActAskVolume m_nAccActAskVolume \\\n", "0 129574875.0 0 10430 \n", "1 129648705.0 0 10430 \n", "2 129673315.0 0 10430 \n", "3 129685620.0 0 10430 \n", "4 129944025.0 0 10430 \n", "\n", " m_nActAskTurnover m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder \\\n", "0 0.0 128325620.0 2.0 405687.0 \n", "1 0.0 128325620.0 2.0 405689.0 \n", "2 0.0 128325620.0 3.0 405692.0 \n", "3 0.0 128325620.0 1.0 405693.0 \n", "4 0.0 128325620.0 10.0 405703.0 \n", "\n", " m_nAskOrder m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate \\\n", "0 1.0 352340.0 2.000000 1.151408 \n", "1 111.0 352451.0 0.018018 1.151051 \n", "2 98.0 352549.0 0.030612 1.150739 \n", "3 97.0 352646.0 0.010309 1.150426 \n", "4 19.0 352665.0 0.526316 1.150392 \n", "\n", " m_nMItemsVolRate code_init \n", "0 0.0 CF \n", "1 0.0 CF \n", "2 0.0 CF \n", "3 0.0 CF \n", "4 0.0 CF \n", "2022-11-09 15:44:37.295 | INFO | src.TSLfm:__exit__:24 - Logging out TSL.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "(112175, 38)\n", " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", "0 CF2303 2022-11-01 09:00:00 12365.0 12365.0 12365.0 12365.0 12365.0 \n", "1 CF2303 2022-11-01 09:00:01 12375.0 12375.0 12375.0 12375.0 12375.0 \n", "2 CF2303 2022-11-01 09:00:02 12370.0 12370.0 12370.0 12370.0 12370.0 \n", "3 CF2303 2022-11-01 09:00:02 12370.0 12370.0 12370.0 12370.0 12370.0 \n", "4 CF2303 2022-11-01 09:00:03 12350.0 12350.0 12350.0 12350.0 12350.0 \n", "\n", " m_nAccHigh m_nAccLow m_iVolume m_iAccVolume m_nMatchItems \\\n", "0 12370.0 12250.0 13 20959 -7 \n", "1 12375.0 12250.0 6 20965 2 \n", "2 12375.0 12250.0 2 20967 -2 \n", "3 12375.0 12250.0 1 20968 -1 \n", "4 12375.0 12250.0 21 20989 0 \n", "\n", " m_nAccMatchItems m_iTurnover m_iAccTurnover m_nPreClose m_nAccPreClose \\\n", "0 32460 159965.0 257900495.0 12270.0 12390.0 \n", "1 32462 73830.0 257974325.0 12365.0 12390.0 \n", "2 32460 24610.0 257998935.0 12375.0 12390.0 \n", "3 32459 12305.0 258011240.0 12370.0 12390.0 \n", "4 32459 258405.0 258269645.0 12370.0 12390.0 \n", "\n", " m_nBidPrice m_nBidVolume m_nAskPrice m_nAskVolume m_iABFlag \\\n", "0 12365.0 2 12370.0 1 1 \n", "1 12360.0 2 12370.0 111 1 \n", "2 12345.0 3 12355.0 98 1 \n", "3 12340.0 1 12350.0 97 1 \n", "4 12340.0 10 12350.0 19 1 \n", "\n", " m_nActBidVolume m_nAccActBidVolume m_nActBidTurnover \\\n", "0 13 10529 159965.0 \n", "1 6 10535 73830.0 \n", "2 2 10537 24610.0 \n", "3 1 10538 12305.0 \n", "4 21 10559 258405.0 \n", "\n", " m_nAccActBidTurnover m_nActAskVolume m_nAccActAskVolume \\\n", "0 129574875.0 0 10430 \n", "1 129648705.0 0 10430 \n", "2 129673315.0 0 10430 \n", "3 129685620.0 0 10430 \n", "4 129944025.0 0 10430 \n", "\n", " m_nActAskTurnover m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder \\\n", "0 0.0 128325620.0 2.0 405687.0 \n", "1 0.0 128325620.0 2.0 405689.0 \n", "2 0.0 128325620.0 3.0 405692.0 \n", "3 0.0 128325620.0 1.0 405693.0 \n", "4 0.0 128325620.0 10.0 405703.0 \n", "\n", " m_nAskOrder m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate \\\n", "0 1.0 352340.0 2.000000 1.151408 \n", "1 111.0 352451.0 0.018018 1.151051 \n", "2 98.0 352549.0 0.030612 1.150739 \n", "3 97.0 352646.0 0.010309 1.150426 \n", "4 19.0 352665.0 0.526316 1.150392 \n", "\n", " m_nMItemsVolRate code_init \n", "0 0.0 CF \n", "1 0.0 CF \n", "2 0.0 CF \n", "3 0.0 CF \n", "4 0.0 CF \n" ] } ], "source": [ "\n", "from src.TSLfm import TSLfm\n", "import pandas as pd \n", "import numpy as np\n", "pd.set_option('display.max_columns', 100)\n", "\n", "with TSLfm() as tsl:\n", " \n", " # t_list= tsl.get_code_list()\n", " t_list=['CF2211', 'CF2301', 'CF2303', 'CF2305', 'CF2307', 'CF2309']\n", " # t_list=['AP2212']\n", " # t_list=['CF2211']\n", " df = tsl.process_result_data_type(tsl.get_trade_tick('20221101','20221101',t_list))\n", " \n", " print(df.shape)\n", " print(df.head())\n", "\n", "df.to_csv('data/CF20221101tick.csv')\n", "\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
codem_nPricem_nOpenm_nHighm_nLowm_nClosem_nAccHighm_nAccLowm_iVolumem_iAccVolumem_nMatchItemsm_nAccMatchItemsm_iTuroverm_iAccTuroverm_nPreClosem_nAccPreClosem_nBidPricem_nBidVolumem_nAskPricem_nAskVolumem_iABFlagm_nActBidVolumem_nAccActBidVolumem_nActBidTuroverm_nAccActBidTuroverm_nActAskVolumem_nAccActAskVolumem_nActAskTuroverm_nAccActAskTuroverm_nBidOrderm_nAccBidOrderm_nAskOrderm_nAccAskOrderm_nABOrderRatem_nAccABOrderRatem_nMItemsVolRatem_nDatem_nTimecode_init
0CF221113400.013550.013550.013400.013400.013645.013400.028754-22.048543759101022047013550.013580.013400.0813550.020122.0348.0294580.04718285.06.0406.081330.05502185.0266.040331.0324.04755.00.4000008.4818090.02022-10-3109:01:00CF
1CF221113435.013400.013545.013400.013435.013645.013400.03757-1.04853406651026113513400.013580.013410.06413550.02002.0350.027110.04745395.01.0407.013555.05515740.0741.041072.0388.05143.03.2000007.9860000.02022-10-3109:02:00CF
2CF221113410.013435.013435.013410.013410.013645.013400.03760-3.04850406651030180013435.013580.013410.06213545.0100.0350.00.04745395.03.0410.040665.05556405.01335.042407.0428.05571.062.0000007.6120980.02022-10-3109:03:00CF
3CF221113545.013410.013545.013410.013545.013645.013400.03763-1.04849406651034246513410.013580.013545.0913550.03702.0352.027110.04772505.01.0411.013555.05569960.0580.042987.0278.05849.00.2432437.3494610.02022-10-3109:04:00CF
4CF221113520.013545.013545.013410.013520.013645.013400.023786-16.048333117651065423013545.013580.013425.0113515.0508.0360.0108440.04880945.015.0426.0203325.05773285.0759.043746.0160.06009.00.2000007.2800800.02022-10-3109:05:00CF
........................................................................................................................
685CF221113810.013810.013810.013810.013810.013810.013725.00110.01740015136013810.013600.013710.01013800.04000.011.00.0151360.00.00.00.00.050.015596.0200.013666.00.2500001.1412260.02022-11-0122:56:00CF
686CF221113810.013810.013810.013810.013810.013810.013725.00110.01740015136013810.013600.013725.01013800.04000.011.00.0151360.00.00.00.00.052.015648.0280.013946.00.2500001.1220420.02022-11-0122:57:00CF
687CF221113810.013810.013810.013810.013810.013810.013725.00110.01740015136013810.013600.013725.01013800.04000.011.00.0151360.00.00.00.00.020.015668.080.014026.00.2500001.1170680.02022-11-0122:58:00CF
688CF221113810.013810.013810.013810.013810.013810.013725.00110.01740015136013810.013600.013725.01013800.04000.011.00.0151360.00.00.00.00.020.015688.080.014106.00.2500001.1121510.02022-11-0122:59:00CF
689CF221113810.013810.013810.013810.013810.013810.013725.00110.01740015136013810.013600.013740.01013800.04000.011.00.0151360.00.00.00.00.084.015772.0360.014466.00.2500001.0902810.02022-11-0123:00:00CF
\n", "

690 rows × 39 columns

\n", "
" ], "text/plain": [ " code m_nPrice m_nOpen m_nHigh m_nLow m_nClose m_nAccHigh \\\n", "0 CF2211 13400.0 13550.0 13550.0 13400.0 13400.0 13645.0 \n", "1 CF2211 13435.0 13400.0 13545.0 13400.0 13435.0 13645.0 \n", "2 CF2211 13410.0 13435.0 13435.0 13410.0 13410.0 13645.0 \n", "3 CF2211 13545.0 13410.0 13545.0 13410.0 13545.0 13645.0 \n", "4 CF2211 13520.0 13545.0 13545.0 13410.0 13520.0 13645.0 \n", ".. ... ... ... ... ... ... ... \n", "685 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n", "686 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n", "687 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n", "688 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n", "689 CF2211 13810.0 13810.0 13810.0 13810.0 13810.0 13810.0 \n", "\n", " m_nAccLow m_iVolume m_iAccVolume m_nMatchItems m_nAccMatchItems \\\n", "0 13400.0 28 754 -22.0 4854 \n", "1 13400.0 3 757 -1.0 4853 \n", "2 13400.0 3 760 -3.0 4850 \n", "3 13400.0 3 763 -1.0 4849 \n", "4 13400.0 23 786 -16.0 4833 \n", ".. ... ... ... ... ... \n", "685 13725.0 0 11 0.0 1740 \n", "686 13725.0 0 11 0.0 1740 \n", "687 13725.0 0 11 0.0 1740 \n", "688 13725.0 0 11 0.0 1740 \n", "689 13725.0 0 11 0.0 1740 \n", "\n", " m_iTurover m_iAccTurover m_nPreClose m_nAccPreClose m_nBidPrice \\\n", "0 375910 10220470 13550.0 13580.0 13400.0 \n", "1 40665 10261135 13400.0 13580.0 13410.0 \n", "2 40665 10301800 13435.0 13580.0 13410.0 \n", "3 40665 10342465 13410.0 13580.0 13545.0 \n", "4 311765 10654230 13545.0 13580.0 13425.0 \n", ".. ... ... ... ... ... \n", "685 0 151360 13810.0 13600.0 13710.0 \n", "686 0 151360 13810.0 13600.0 13725.0 \n", "687 0 151360 13810.0 13600.0 13725.0 \n", "688 0 151360 13810.0 13600.0 13725.0 \n", "689 0 151360 13810.0 13600.0 13740.0 \n", "\n", " m_nBidVolume m_nAskPrice m_nAskVolume m_iABFlag m_nActBidVolume \\\n", "0 8 13550.0 20 1 22.0 \n", "1 64 13550.0 20 0 2.0 \n", "2 62 13545.0 1 0 0.0 \n", "3 9 13550.0 37 0 2.0 \n", "4 1 13515.0 5 0 8.0 \n", ".. ... ... ... ... ... \n", "685 10 13800.0 40 0 0.0 \n", "686 10 13800.0 40 0 0.0 \n", "687 10 13800.0 40 0 0.0 \n", "688 10 13800.0 40 0 0.0 \n", "689 10 13800.0 40 0 0.0 \n", "\n", " m_nAccActBidVolume m_nActBidTurover m_nAccActBidTurover \\\n", "0 348.0 294580.0 4718285.0 \n", "1 350.0 27110.0 4745395.0 \n", "2 350.0 0.0 4745395.0 \n", "3 352.0 27110.0 4772505.0 \n", "4 360.0 108440.0 4880945.0 \n", ".. ... ... ... \n", "685 11.0 0.0 151360.0 \n", "686 11.0 0.0 151360.0 \n", "687 11.0 0.0 151360.0 \n", "688 11.0 0.0 151360.0 \n", "689 11.0 0.0 151360.0 \n", "\n", " m_nActAskVolume m_nAccActAskVolume m_nActAskTurover \\\n", "0 6.0 406.0 81330.0 \n", "1 1.0 407.0 13555.0 \n", "2 3.0 410.0 40665.0 \n", "3 1.0 411.0 13555.0 \n", "4 15.0 426.0 203325.0 \n", ".. ... ... ... \n", "685 0.0 0.0 0.0 \n", "686 0.0 0.0 0.0 \n", "687 0.0 0.0 0.0 \n", "688 0.0 0.0 0.0 \n", "689 0.0 0.0 0.0 \n", "\n", " m_nAccActAskTurover m_nBidOrder m_nAccBidOrder m_nAskOrder \\\n", "0 5502185.0 266.0 40331.0 324.0 \n", "1 5515740.0 741.0 41072.0 388.0 \n", "2 5556405.0 1335.0 42407.0 428.0 \n", "3 5569960.0 580.0 42987.0 278.0 \n", "4 5773285.0 759.0 43746.0 160.0 \n", ".. ... ... ... ... \n", "685 0.0 50.0 15596.0 200.0 \n", "686 0.0 52.0 15648.0 280.0 \n", "687 0.0 20.0 15668.0 80.0 \n", "688 0.0 20.0 15688.0 80.0 \n", "689 0.0 84.0 15772.0 360.0 \n", "\n", " m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate m_nMItemsVolRate \\\n", "0 4755.0 0.400000 8.481809 0.0 \n", "1 5143.0 3.200000 7.986000 0.0 \n", "2 5571.0 62.000000 7.612098 0.0 \n", "3 5849.0 0.243243 7.349461 0.0 \n", "4 6009.0 0.200000 7.280080 0.0 \n", ".. ... ... ... ... \n", "685 13666.0 0.250000 1.141226 0.0 \n", "686 13946.0 0.250000 1.122042 0.0 \n", "687 14026.0 0.250000 1.117068 0.0 \n", "688 14106.0 0.250000 1.112151 0.0 \n", "689 14466.0 0.250000 1.090281 0.0 \n", "\n", " m_nDate m_nTime code_init \n", "0 2022-10-31 09:01:00 CF \n", "1 2022-10-31 09:02:00 CF \n", "2 2022-10-31 09:03:00 CF \n", "3 2022-10-31 09:04:00 CF \n", "4 2022-10-31 09:05:00 CF \n", ".. ... ... ... \n", "685 2022-11-01 22:56:00 CF \n", "686 2022-11-01 22:57:00 CF \n", "687 2022-11-01 22:58:00 CF \n", "688 2022-11-01 22:59:00 CF \n", "689 2022-11-01 23:00:00 CF \n", "\n", "[690 rows x 39 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
codem_nDatetimem_nPricem_nOpenm_nHighm_nLowm_nClosem_nAccHighm_nAccLowm_iVolume...m_nActAskTurnoverm_nAccActAskTurnoverm_nBidOrderm_nAccBidOrderm_nAskOrderm_nAccAskOrderm_nABOrderRatem_nAccABOrderRatem_nMItemsVolRatecode_init
0CF22112022-10-11 09:01:0014480.014460.014480.014450.014480.014490.014315.0412...1019205.0212045740.01233.068627.01178.054072.00.251.2691780.0CF
\n", "

1 rows × 38 columns

\n", "
" ], "text/plain": [ " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", "0 CF2211 2022-10-11 09:01:00 14480.0 14460.0 14480.0 14450.0 14480.0 \n", "\n", " m_nAccHigh m_nAccLow m_iVolume ... m_nActAskTurnover \\\n", "0 14490.0 14315.0 412 ... 1019205.0 \n", "\n", " m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder m_nAskOrder \\\n", "0 212045740.0 1233.0 68627.0 1178.0 \n", "\n", " m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate m_nMItemsVolRate \\\n", "0 54072.0 0.25 1.269178 0.0 \n", "\n", " code_init \n", "0 CF \n", "\n", "[1 rows x 38 columns]" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from src.DDBfm import DDBfm\n", "ddb=DDBfm('dev')\n", "tb = ddb.sess.loadTable(dbPath=ddb.ddb_hft_dbPath, tableName=ddb.ddf_hft_mink_tbname)\n", "tb.select('*').where(f\"code=`CF2211\").where(f\"m_nDatetime>=2022.10.11d\").top(1).toDF()\n", "\n", "# tb.toDF()\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "db = ddb.create_ddb_database(ddb.ddb_hft_path,ddb.ddb_hft_mink_dbname)\n", "ddb.add_new_hft_table(db,ddb.ddf_hft_mink_tbname,df)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "ddb.append_hft_table(ddb.ddb_hft_path,ddb.ddf_hft_mink_tbname,df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# ddb.ddb_sess.run(\"\"\"\n", "# {table_name} = table({capacity}:0, {col_names}, [{col_types}]);\n", "# \"\"\".format(\n", "# table_name = ddb.ddf_hft_tick_tbname,\n", "# capacity = 5000 * 1000,\n", "# col_names = '`code`m_nDate',\n", "# col_types = \"SYMBOL, DATE\"\n", "# ))" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'01': ['2022-01-01',\n", " '2022-02-01',\n", " '2022-03-01',\n", " '2022-04-01',\n", " '2022-05-01',\n", " '2022-06-01',\n", " '2022-07-01',\n", " '2022-08-01',\n", " '2022-09-01',\n", " '2022-10-01',\n", " '2022-11-01'],\n", " '02': ['2022-01-02',\n", " '2022-02-02',\n", " '2022-03-02',\n", " '2022-04-02',\n", " '2022-05-02',\n", " '2022-06-02',\n", " '2022-07-02',\n", " '2022-08-02',\n", " '2022-09-02',\n", " '2022-10-02',\n", " '2022-11-02'],\n", " '03': ['2022-01-03',\n", " '2022-02-03',\n", " '2022-03-03',\n", " '2022-04-03',\n", " '2022-05-03',\n", " '2022-06-03',\n", " '2022-07-03',\n", " '2022-08-03',\n", " '2022-09-03',\n", " '2022-10-03',\n", " '2022-11-03'],\n", " '04': ['2022-01-04',\n", " '2022-02-04',\n", " '2022-03-04',\n", " '2022-04-04',\n", " '2022-05-04',\n", " '2022-06-04',\n", " '2022-07-04',\n", " '2022-08-04',\n", " '2022-09-04',\n", " '2022-10-04',\n", " '2022-11-04'],\n", " '05': ['2022-01-05',\n", " '2022-02-05',\n", " '2022-03-05',\n", " '2022-04-05',\n", " '2022-05-05',\n", " '2022-06-05',\n", " '2022-07-05',\n", " '2022-08-05',\n", " '2022-09-05',\n", " '2022-10-05',\n", " '2022-11-05'],\n", " '06': ['2022-01-06',\n", " '2022-02-06',\n", " '2022-03-06',\n", " '2022-04-06',\n", " '2022-05-06',\n", " '2022-06-06',\n", " '2022-07-06',\n", " '2022-08-06',\n", " '2022-09-06',\n", " '2022-10-06',\n", " '2022-11-06'],\n", " '07': ['2022-01-07',\n", " '2022-02-07',\n", " '2022-03-07',\n", " '2022-04-07',\n", " '2022-05-07',\n", " '2022-06-07',\n", " '2022-07-07',\n", " '2022-08-07',\n", " '2022-09-07',\n", " '2022-10-07',\n", " '2022-11-07'],\n", " '08': ['2022-01-08',\n", " '2022-02-08',\n", " '2022-03-08',\n", " '2022-04-08',\n", " '2022-05-08',\n", " '2022-06-08',\n", " '2022-07-08',\n", " '2022-08-08',\n", " '2022-09-08',\n", " '2022-10-08',\n", " '2022-11-08'],\n", " '09': ['2022-01-09',\n", " '2022-02-09',\n", " '2022-03-09',\n", " '2022-04-09',\n", " '2022-05-09',\n", " '2022-06-09',\n", " '2022-07-09',\n", " '2022-08-09',\n", " '2022-09-09',\n", " '2022-10-09'],\n", " '10': ['2022-01-10',\n", " '2022-02-10',\n", " '2022-03-10',\n", " '2022-04-10',\n", " '2022-05-10',\n", " '2022-06-10',\n", " '2022-07-10',\n", " '2022-08-10',\n", " '2022-09-10',\n", " '2022-10-10'],\n", " '11': ['2022-01-11',\n", " '2022-02-11',\n", " '2022-03-11',\n", " '2022-04-11',\n", " '2022-05-11',\n", " '2022-06-11',\n", " '2022-07-11',\n", " '2022-08-11',\n", " '2022-09-11',\n", " '2022-10-11'],\n", " '12': ['2022-01-12',\n", " '2022-02-12',\n", " '2022-03-12',\n", " '2022-04-12',\n", " '2022-05-12',\n", " '2022-06-12',\n", " '2022-07-12',\n", " '2022-08-12',\n", " '2022-09-12',\n", " '2022-10-12'],\n", " '13': ['2022-01-13',\n", " '2022-02-13',\n", " '2022-03-13',\n", " '2022-04-13',\n", " '2022-05-13',\n", " '2022-06-13',\n", " '2022-07-13',\n", " '2022-08-13',\n", " '2022-09-13',\n", " '2022-10-13'],\n", " '14': ['2022-01-14',\n", " '2022-02-14',\n", " '2022-03-14',\n", " '2022-04-14',\n", " '2022-05-14',\n", " '2022-06-14',\n", " '2022-07-14',\n", " '2022-08-14',\n", " '2022-09-14',\n", " '2022-10-14'],\n", " '15': ['2022-01-15',\n", " '2022-02-15',\n", " '2022-03-15',\n", " '2022-04-15',\n", " '2022-05-15',\n", " '2022-06-15',\n", " '2022-07-15',\n", " '2022-08-15',\n", " '2022-09-15',\n", " '2022-10-15'],\n", " '16': ['2022-01-16',\n", " '2022-02-16',\n", " '2022-03-16',\n", " '2022-04-16',\n", " '2022-05-16',\n", " '2022-06-16',\n", " '2022-07-16',\n", " '2022-08-16',\n", " '2022-09-16',\n", " '2022-10-16'],\n", " '17': ['2022-01-17',\n", " '2022-02-17',\n", " '2022-03-17',\n", " '2022-04-17',\n", " '2022-05-17',\n", " '2022-06-17',\n", " '2022-07-17',\n", " '2022-08-17',\n", " '2022-09-17',\n", " '2022-10-17'],\n", " '18': ['2022-01-18',\n", " '2022-02-18',\n", " '2022-03-18',\n", " '2022-04-18',\n", " '2022-05-18',\n", " '2022-06-18',\n", " '2022-07-18',\n", " '2022-08-18',\n", " '2022-09-18',\n", " '2022-10-18'],\n", " '19': ['2022-01-19',\n", " '2022-02-19',\n", " '2022-03-19',\n", " '2022-04-19',\n", " '2022-05-19',\n", " '2022-06-19',\n", " '2022-07-19',\n", " '2022-08-19',\n", " '2022-09-19',\n", " '2022-10-19'],\n", " '20': ['2022-01-20',\n", " '2022-02-20',\n", " '2022-03-20',\n", " '2022-04-20',\n", " '2022-05-20',\n", " '2022-06-20',\n", " '2022-07-20',\n", " '2022-08-20',\n", " '2022-09-20',\n", " '2022-10-20'],\n", " '21': ['2022-01-21',\n", " '2022-02-21',\n", " '2022-03-21',\n", " '2022-04-21',\n", " '2022-05-21',\n", " '2022-06-21',\n", " '2022-07-21',\n", " '2022-08-21',\n", " '2022-09-21',\n", " '2022-10-21'],\n", " '22': ['2022-01-22',\n", " '2022-02-22',\n", " '2022-03-22',\n", " '2022-04-22',\n", " '2022-05-22',\n", " '2022-06-22',\n", " '2022-07-22',\n", " '2022-08-22',\n", " '2022-09-22',\n", " '2022-10-22'],\n", " '23': ['2022-01-23',\n", " '2022-02-23',\n", " '2022-03-23',\n", " '2022-04-23',\n", " '2022-05-23',\n", " '2022-06-23',\n", " '2022-07-23',\n", " '2022-08-23',\n", " '2022-09-23',\n", " '2022-10-23'],\n", " '24': ['2022-01-24',\n", " '2022-02-24',\n", " '2022-03-24',\n", " '2022-04-24',\n", " '2022-05-24',\n", " '2022-06-24',\n", " '2022-07-24',\n", " '2022-08-24',\n", " '2022-09-24',\n", " '2022-10-24'],\n", " '25': ['2022-01-25',\n", " '2022-02-25',\n", " '2022-03-25',\n", " '2022-04-25',\n", " '2022-05-25',\n", " '2022-06-25',\n", " '2022-07-25',\n", " '2022-08-25',\n", " '2022-09-25',\n", " '2022-10-25'],\n", " '26': ['2022-01-26',\n", " '2022-02-26',\n", " '2022-03-26',\n", " '2022-04-26',\n", " '2022-05-26',\n", " '2022-06-26',\n", " '2022-07-26',\n", " '2022-08-26',\n", " '2022-09-26',\n", " '2022-10-26'],\n", " '27': ['2022-01-27',\n", " '2022-02-27',\n", " '2022-03-27',\n", " '2022-04-27',\n", " '2022-05-27',\n", " '2022-06-27',\n", " '2022-07-27',\n", " '2022-08-27',\n", " '2022-09-27',\n", " '2022-10-27'],\n", " '28': ['2022-01-28',\n", " '2022-02-28',\n", " '2022-03-28',\n", " '2022-04-28',\n", " '2022-05-28',\n", " '2022-06-28',\n", " '2022-07-28',\n", " '2022-08-28',\n", " '2022-09-28',\n", " '2022-10-28'],\n", " '29': ['2022-01-29',\n", " '2022-03-29',\n", " '2022-04-29',\n", " '2022-05-29',\n", " '2022-06-29',\n", " '2022-07-29',\n", " '2022-08-29',\n", " '2022-09-29',\n", " '2022-10-29'],\n", " '30': ['2022-01-30',\n", " '2022-03-30',\n", " '2022-04-30',\n", " '2022-05-30',\n", " '2022-06-30',\n", " '2022-07-30',\n", " '2022-08-30',\n", " '2022-09-30',\n", " '2022-10-30'],\n", " '31': ['2022-01-31',\n", " '2022-03-31',\n", " '2022-05-31',\n", " '2022-07-31',\n", " '2022-08-31',\n", " '2022-10-31']}" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "allDates = pd.date_range('20220101', '20221108', freq ='D')\n", "dates_dict_by_day={}\n", "\n", "for d in list(allDates.astype('str')):\n", " day = d[-2:]\n", " if day not in dates_dict_by_day:\n", " dates_dict_by_day[day] = [d]\n", " else:\n", " dates_dict_by_day[day].append(d)\n", "dates_dict_by_day" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "start_date='2022-10-01'\n", "end_date='2022-11-08'\n", "allDates = pd.date_range(start_date, end_date, freq ='D')\n", "allDates = [i.replace('-','') for i in list(allDates.astype('str'))]\n", "allDates" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'AP': ['AP2211', 'AP2212', 'AP2301', 'AP2303', 'AP2304', 'AP2305', 'AP2310'], 'CF': ['CF2211', 'CF2301', 'CF2303', 'CF2305', 'CF2307', 'CF2309'], 'CJ': ['CJ2212', 'CJ2301', 'CJ2303', 'CJ2305', 'CJ2307', 'CJ2309'], 'CY': ['CY2211', 'CY2212', 'CY2301', 'CY2302', 'CY2303', 'CY2304', 'CY2305', 'CY2306', 'CY2307', 'CY2308', 'CY2309', 'CY2310'], 'FG': ['FG2211', 'FG2212', 'FG2301', 'FG2302', 'FG2303', 'FG2304', 'FG2305', 'FG2306', 'FG2307', 'FG2308', 'FG2309', 'FG2310'], 'IC': ['IC2211', 'IC2212', 'IC2303', 'IC2306'], 'IF': ['IF2211', 'IF2212', 'IF2303', 'IF2306'], 'IH': ['IH2211', 'IH2212', 'IH2303', 'IH2306'], 'IM': ['IM2211', 'IM2212', 'IM2303', 'IM2306'], 'JR': ['JR2211', 'JR2301', 'JR2303', 'JR2305', 'JR2307', 'JR2309'], 'LR': ['LR2211', 'LR2301', 'LR2303', 'LR2305', 'LR2307', 'LR2309'], 'MA': ['MA2211', 'MA2212', 'MA2301', 'MA2302', 'MA2303', 'MA2304', 'MA2305', 'MA2306', 'MA2307', 'MA2308', 'MA2309', 'MA2310'], 'OI': ['OI2211', 'OI2301', 'OI2303', 'OI2305', 'OI2307', 'OI2309'], 'PF': ['PF2211', 'PF2212', 'PF2301', 'PF2302', 'PF2303', 'PF2304', 'PF2305', 'PF2306', 'PF2307', 'PF2308', 'PF2309', 'PF2310'], 'PK': ['PK2211', 'PK2212', 'PK2301', 'PK2303', 'PK2304', 'PK2310'], 'PM': ['PM2211', 'PM2301', 'PM2303', 'PM2305', 'PM2307', 'PM2309'], 'RI': ['RI2211', 'RI2301', 'RI2303', 'RI2305', 'RI2307', 'RI2309'], 'RM': ['RM2211', 'RM2301', 'RM2303', 'RM2305', 'RM2307', 'RM2308', 'RM2309'], 'RS': ['RS2211', 'RS2307', 'RS2308', 'RS2309'], 'SA': ['SA2211', 'SA2212', 'SA2301', 'SA2302', 'SA2303', 'SA2304', 'SA2305', 'SA2306', 'SA2307', 'SA2308', 'SA2309', 'SA2310'], 'SF': ['SF2211', 'SF2212', 'SF2301', 'SF2302', 'SF2303', 'SF2304', 'SF2305', 'SF2306', 'SF2307', 'SF2308', 'SF2309', 'SF2310'], 'SM': ['SM2211', 'SM2212', 'SM2301', 'SM2302', 'SM2303', 'SM2304', 'SM2305', 'SM2306', 'SM2307', 'SM2308', 'SM2309', 'SM2310'], 'SR': ['SR2211', 'SR2301', 'SR2303', 'SR2305', 'SR2307', 'SR2309'], 'T': ['T2212', 'T2303', 'T2306'], 'TA': ['TA2211', 'TA2212', 'TA2301', 'TA2302', 'TA2303', 'TA2304', 'TA2305', 'TA2306', 'TA2307', 'TA2308', 'TA2309', 'TA2310'], 'TF': ['TF2212', 'TF2303', 'TF2306'], 'TS': ['TS2212', 'TS2303', 'TS2306'], 'UR': ['UR2211', 'UR2212', 'UR2301', 'UR2302', 'UR2303', 'UR2304', 'UR2305', 'UR2306', 'UR2307', 'UR2308', 'UR2309', 'UR2310'], 'WH': ['WH2211', 'WH2301', 'WH2303', 'WH2305', 'WH2307', 'WH2309'], 'ZC': ['ZC2212', 'ZC2301', 'ZC2302', 'ZC2303', 'ZC2304', 'ZC2305', 'ZC2306', 'ZC2307', 'ZC2308', 'ZC2309', 'ZC2310', 'ZC2311'], 'a': ['a2211', 'a2301', 'a2303', 'a2305', 'a2307', 'a2309'], 'ag': ['ag2211', 'ag2212', 'ag2301', 'ag2302', 'ag2303', 'ag2304', 'ag2305', 'ag2306', 'ag2307', 'ag2308', 'ag2309', 'ag2310'], 'al': ['al2211', 'al2212', 'al2301', 'al2302', 'al2303', 'al2304', 'al2305', 'al2306', 'al2307', 'al2308', 'al2309', 'al2310'], 'au': ['au2211', 'au2212', 'au2301', 'au2302', 'au2304', 'au2306', 'au2308', 'au2310'], 'b': ['b2211', 'b2212', 'b2301', 'b2302', 'b2303', 'b2304', 'b2305', 'b2306', 'b2307', 'b2308', 'b2309', 'b2310'], 'bb': ['bb2211', 'bb2212', 'bb2301', 'bb2302', 'bb2303', 'bb2304', 'bb2305', 'bb2306', 'bb2307', 'bb2308', 'bb2309', 'bb2310'], 'bc': ['bc2211', 'bc2212', 'bc2301', 'bc2302', 'bc2303', 'bc2304', 'bc2305', 'bc2306', 'bc2307', 'bc2308', 'bc2309', 'bc2310'], 'bu': ['bu2211', 'bu2212', 'bu2301', 'bu2302', 'bu2303', 'bu2304', 'bu2305', 'bu2306', 'bu2307', 'bu2308', 'bu2309', 'bu2310', 'bu2312', 'bu2403', 'bu2406', 'bu2409'], 'c': ['c2211', 'c2301', 'c2303', 'c2305', 'c2307', 'c2309'], 'cs': ['cs2211', 'cs2301', 'cs2303', 'cs2305', 'cs2307', 'cs2309'], 'cu': ['cu2211', 'cu2212', 'cu2301', 'cu2302', 'cu2303', 'cu2304', 'cu2305', 'cu2306', 'cu2307', 'cu2308', 'cu2309', 'cu2310'], 'eb': ['eb2211', 'eb2212', 'eb2301', 'eb2302', 'eb2303', 'eb2304', 'eb2305', 'eb2306', 'eb2307', 'eb2308', 'eb2309', 'eb2310'], 'eg': ['eg2211', 'eg2212', 'eg2301', 'eg2302', 'eg2303', 'eg2304', 'eg2305', 'eg2306', 'eg2307', 'eg2308', 'eg2309', 'eg2310'], 'fb': ['fb2211', 'fb2212', 'fb2301', 'fb2302', 'fb2303', 'fb2304', 'fb2305', 'fb2306', 'fb2307', 'fb2308', 'fb2309', 'fb2310'], 'fu': ['fu2212', 'fu2301', 'fu2302', 'fu2303', 'fu2304', 'fu2305', 'fu2306', 'fu2307', 'fu2308', 'fu2309', 'fu2310', 'fu2311'], 'hc': ['hc2211', 'hc2212', 'hc2301', 'hc2302', 'hc2303', 'hc2304', 'hc2305', 'hc2306', 'hc2307', 'hc2308', 'hc2309', 'hc2310'], 'i': ['i2211', 'i2212', 'i2301', 'i2302', 'i2303', 'i2304', 'i2305', 'i2306', 'i2307', 'i2308', 'i2309', 'i2310'], 'j': ['j2211', 'j2212', 'j2301', 'j2302', 'j2303', 'j2304', 'j2305', 'j2306', 'j2307', 'j2308', 'j2309', 'j2310'], 'jd': ['jd2211', 'jd2212', 'jd2301', 'jd2302', 'jd2303', 'jd2304', 'jd2305', 'jd2306', 'jd2307', 'jd2308', 'jd2309', 'jd2310'], 'jm': ['jm2211', 'jm2212', 'jm2301', 'jm2302', 'jm2303', 'jm2304', 'jm2305', 'jm2306', 'jm2307', 'jm2308', 'jm2309', 'jm2310'], 'l': ['l2211', 'l2212', 'l2301', 'l2302', 'l2303', 'l2304', 'l2305', 'l2306', 'l2307', 'l2308', 'l2309', 'l2310'], 'lh': ['lh2211', 'lh2301', 'lh2303', 'lh2305', 'lh2307', 'lh2309'], 'lu': ['lu2212', 'lu2301', 'lu2302', 'lu2303', 'lu2304', 'lu2305', 'lu2306', 'lu2307', 'lu2308', 'lu2309', 'lu2310', 'lu2311'], 'm': ['m2211', 'm2212', 'm2301', 'm2303', 'm2305', 'm2307', 'm2308', 'm2309'], 'ni': ['ni2211', 'ni2212', 'ni2301', 'ni2302', 'ni2303', 'ni2304', 'ni2305', 'ni2306', 'ni2307', 'ni2308', 'ni2309', 'ni2310'], 'nr': ['nr2211', 'nr2212', 'nr2301', 'nr2302', 'nr2303', 'nr2304', 'nr2305', 'nr2306', 'nr2307', 'nr2308', 'nr2309', 'nr2310'], 'p': ['p2211', 'p2212', 'p2301', 'p2302', 'p2303', 'p2304', 'p2305', 'p2306', 'p2307', 'p2308', 'p2309', 'p2310'], 'pb': ['pb2211', 'pb2212', 'pb2301', 'pb2302', 'pb2303', 'pb2304', 'pb2305', 'pb2306', 'pb2307', 'pb2308', 'pb2309', 'pb2310'], 'pg': ['pg2211', 'pg2212', 'pg2301', 'pg2302', 'pg2303', 'pg2304', 'pg2305', 'pg2306', 'pg2307', 'pg2308', 'pg2309', 'pg2310'], 'pp': ['pp2211', 'pp2212', 'pp2301', 'pp2302', 'pp2303', 'pp2304', 'pp2305', 'pp2306', 'pp2307', 'pp2308', 'pp2309', 'pp2310'], 'rb': ['rb2211', 'rb2212', 'rb2301', 'rb2302', 'rb2303', 'rb2304', 'rb2305', 'rb2306', 'rb2307', 'rb2308', 'rb2309', 'rb2310'], 'rr': ['rr2211', 'rr2212', 'rr2301', 'rr2302', 'rr2303', 'rr2304', 'rr2305', 'rr2306', 'rr2307', 'rr2308', 'rr2309', 'rr2310'], 'ru': ['ru2211', 'ru2301', 'ru2303', 'ru2304', 'ru2305', 'ru2306', 'ru2307', 'ru2308', 'ru2309', 'ru2310'], 'sc': ['sc2212', 'sc2301', 'sc2302', 'sc2303', 'sc2304', 'sc2305', 'sc2306', 'sc2307', 'sc2308', 'sc2309', 'sc2310', 'sc2311', 'sc2312', 'sc2403', 'sc2406', 'sc2409', 'sc2412', 'sc2503', 'sc2506', 'sc2509'], 'sn': ['sn2211', 'sn2212', 'sn2301', 'sn2302', 'sn2303', 'sn2304', 'sn2305', 'sn2306', 'sn2307', 'sn2308', 'sn2309', 'sn2310'], 'sp': ['sp2211', 'sp2212', 'sp2301', 'sp2302', 'sp2303', 'sp2304', 'sp2305', 'sp2306', 'sp2307', 'sp2308', 'sp2309', 'sp2310'], 'ss': ['ss2211', 'ss2212', 'ss2301', 'ss2302', 'ss2303', 'ss2304', 'ss2305', 'ss2306', 'ss2307', 'ss2308', 'ss2309', 'ss2310'], 'v': ['v2211', 'v2212', 'v2301', 'v2302', 'v2303', 'v2304', 'v2305', 'v2306', 'v2307', 'v2308', 'v2309', 'v2310'], 'wr': ['wr2211', 'wr2212', 'wr2301', 'wr2302', 'wr2303', 'wr2304', 'wr2305', 'wr2306', 'wr2307', 'wr2308', 'wr2309', 'wr2310'], 'y': ['y2211', 'y2212', 'y2301', 'y2303', 'y2305', 'y2307', 'y2308', 'y2309'], 'zn': ['zn2211', 'zn2212', 'zn2301', 'zn2302', 'zn2303', 'zn2304', 'zn2305', 'zn2306', 'zn2307', 'zn2308', 'zn2309', 'zn2310']}\n" ] } ], "source": [ "from data.code_list import code_list_pickel\n", "# print(code_list_pickel)\n", "all_fm_init=['sc', 'v', 'TS', 'MA', 'AP', 'jm', 'bc', 'bb', 'fu', 'IM', 'IF', 'a', 'lu', 'FG', 'cu', 'al', 'IH', 'RS', 'pg', 'CF', 'SF', 'ni', 'hc', 'UR', 'm', 'SR', 'j', 'PF', 'RM', 'T', 'c', 'JR', 'l', 'p', 'sp', 'CY', 'pb', 'TF', 'b', 'eg', 'rb', 'PK', 'sn', 'nr', 'pp', 'CJ', 'eb', 'SA', 'y', 'RI', 'lh', 'jd', 'OI', 'WH', 'ss', 'ru', 'zn', 'fb', 'rr', 'PM', 'au', 'TA', 'ZC', 'IC', 'bu', 'SM', 'wr', 'cs', 'LR', 'ag', 'i']\n", "all_code_dict_by_init={}\n", "for c in code_list_pickel:\n", " init = c[:-4]\n", " if init in all_code_dict_by_init:\n", " all_code_dict_by_init[init].append(c)\n", " else:\n", " all_code_dict_by_init[init]=[c]\n", "print(all_code_dict_by_init)\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2022-11-10 13:16:00.361292: [2499840] Error: unmarshall failed\n" ] }, { "data": { "text/plain": [ "[]" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import dolphindb as ddb\n", "from src.DDBfm import DDBfm\n", "ddb = DDBfm('prd')\n", "# df = ddb.sess.run(f'select top 1 * from pt where code=`CF2301 and m_nDatetime.date()>=2022.09.30d')\n", "# df = ddb.sess.run(f'select top 1 * from pt where code=`CF2301 and m_nDatetime.date()>={curr_date_formatted}d')\n", "tb = ddb.sess.loadTable(dbPath=ddb.ddb_hft_dbPath, tableName=ddb.ddf_hft_mink_tbname)\n", "\n", "curr_code='CF2211'\n", "cuff_code='T2212'\n", "curr_date_formatted='2022.11.01'\n", "# df = tb.select('*').top(1).toDF() \n", "\n", "cond=f\"code_init=`{curr_code[:2]}, m_nDatetime.date()={curr_date_formatted}d\"\n", "# print(cond)\n", "df = tb.select('distinct code').where(cond).toDF()\n", "# df\n", "# df = tb.select('*').top(1).toDF() \n", "# df = tb.select('*').where(f\"code=`AP2301, m_nDatetime.date()=2022.09.30d\").toDF() \n", "# df[df['m_nPrice']==8274]\n", "# pool = ddb.DBConnectionPool(\"192.168.1.88\", 8848, 20, \"admin\", \"123456\")\n", "df['distinct_code'].to_list()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import dolphindb as ddb\n", "from src.DDBfm import DDBfm\n", "ddb = DDBfm('prd')\n", "# df = ddb.sess.run(f'select top 1 * from pt where code=`CF2301 and m_nDatetime.date()>=2022.09.30d')\n", "# df = ddb.sess.run(f'select top 1 * from pt where code=`CF2301 and m_nDatetime.date()>={curr_date_formatted}d')\n", "tb = ddb.sess.loadTable(dbPath=ddb.ddb_hft_dbPath, tableName=ddb.ddf_hft_mink_tbname)\n", "\n", "# curr_code='CF2211'\n", "cuff_code='T2212'\n", "curr_date_formatted='2022.11.01'\n", "# df = tb.select('*').top(1).toDF() \n", "\n", "cond=f\"code_init=`{curr_code[:2]}, m_nDatetime.date()={curr_date_formatted}d\"\n", "# print(cond)\n", "df = tb.select('distinct code').where(cond).toDF()\n", "# df\n", "# df = tb.select('*').top(1).toDF() \n", "# df = tb.select('*').where(f\"code=`AP2301, m_nDatetime.date()=2022.09.30d\").toDF() \n", "# df[df['m_nPrice']==8274]\n", "# pool = ddb.DBConnectionPool(\"192.168.1.88\", 8848, 20, \"admin\", \"123456\")\n", "df['distinct_code'].to_list()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "ename": "AttributeError", "evalue": "'DBConnectionPool' object has no attribute 'loadTable'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn [3], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m pool \u001b[39m=\u001b[39m ddb\u001b[39m.\u001b[39mDBConnectionPool(\u001b[39m\"\u001b[39m\u001b[39m192.168.1.88\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m8848\u001b[39m, \u001b[39m20\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39madmin\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39m123456\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 5\u001b[0m \u001b[39m# pool.run('getAllDBs()').value()\u001b[39;00m\n\u001b[0;32m----> 6\u001b[0m pool\u001b[39m.\u001b[39;49mloadTable(dbPath\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mdfs://hft_futuremarket_ts\u001b[39m\u001b[39m\"\u001b[39m, tableName\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mMinKlinePartitioned\u001b[39m\u001b[39m'\u001b[39m)\n", "\u001b[0;31mAttributeError\u001b[0m: 'DBConnectionPool' object has no attribute 'loadTable'" ] } ], "source": [ "import dolphindb as ddb\n", "from src.DDBfm import DDBfm\n", "\n", "pool = ddb.DBConnectionPool(\"192.168.1.88\", 8848, 20, \"admin\", \"123456\")\n", "# pool.run('getAllDBs()').value()\n", "pool.loadTable(dbPath=\"dfs://hft_futuremarket_ts\", tableName='MinKlinePartitioned')\n", "# appender = ddb.PartitionedTableAppender(\"dfs://hft_futuremarket_ts\", \"MinKlinePartitioned\", 'm_nDatetime', pool)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "df_all = pd.concat(df_list)\n", "r= appender.append(df_all)\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import dolphindb as ddb\n", "from src.DDBfm import DDBfm\n", "ddbfm=DDBfm('dev',pool=True)\n" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2022-11-10 10:58:40.946 | INFO | src.TSLfm:__enter__:18 - Logging in TSL.\n", "2022-11-10 10:58:41.103 | DEBUG | src.TSLfm:get_mkt_min_k:209 - \n", " SetSysParam(pn_cycle(), cy_1m());\n", " stock_list := Array('AP2211', 'AP2212', 'AP2301');\n", " r := select \n", " ['StockID'] as 'code',\n", " DateTimeToStr(['date']) as 'm_nDatetime',\n", "\n", " ['price'] as 'm_nPrice',\n", " ['open'] as 'm_nOpen',\n", " ['high'] as 'm_nHigh',\n", " ['low'] as 'm_nLow',\n", " ['close'] as 'm_nClose',\n", "\n", " ['sectional_high'] as 'm_nAccHigh',\n", " ['sectional_low'] as 'm_nAccLow',\n", "\n", " ['vol'] as 'm_iVolume', //成交量\n", " ['sectional_vol'] as 'm_iAccVolume', //时点当日累计成交量\n", "\n", " ['cjbs'] as 'm_nMatchItems', // 成交笔数 周期内的持仓的变动量\n", " ['sectional_cjbs'] as 'm_nAccMatchItems',\n", "\n", " ['amount'] as 'm_iTurnover', //成交金额\n", " ['sectional_amount'] as 'm_iAccTurnover', \n", "\n", " ['yclose'] as 'm_nPreClose', //上一周期的收盘价\n", " ['sectional_yclose'] as 'm_nAccPreClose', // 前日收盘\n", " \n", " ['buy1'] as 'm_nBidPrice', //买一价?叫卖价?\n", " ['bc1'] as 'm_nBidVolume', //买一量 当前以买一价出价的委买量\n", " ['sale1'] as 'm_nAskPrice', \n", " ['sc1'] as 'm_nAskVolume', \n", "\n", " ['zmm'] as 'm_iABFlag', //买卖标识\n", "\n", " ['buy_vol'] as 'm_nActBidVolume', //主买量\n", " ['sectional_buy_vol'] as 'm_nAccActBidVolume', //时点当日累计主买量\n", " ['buy_amount'] as 'm_nActBidTurnover', //主买金额\n", " ['sectional_buy_amount'] as 'm_nAccActBidTurnover', \n", "\n", " ['sale_vol'] as 'm_nActAskVolume', \n", " ['sectional_sale_vol'] as 'm_nAccActAskVolume', \n", " ['sale_amount'] as 'm_nActAskTurnover',\n", " ['sectional_sale_amount'] as 'm_nAccActAskTurnover', \n", "\n", " ['w_buy'] as 'm_nBidOrder', //委买\n", " ['sectional_w_buy'] as 'm_nAccBidOrder', \n", " ['w_sale'] as 'm_nAskOrder',\n", " ['sectional_w_sale'] as 'm_nAccAskOrder',\n", "\n", " ['wb'] as 'm_nABOrderRate', //委比\n", " ['sectional_wb'] as 'm_nAccABOrderRate', //时点当日累计委比\n", " ['lb'] as 'm_nMItemsVolRate'//量比\n", "\n", "\n", " from markettable\n", " datekey 20220902T to 20220902T+0.999 \n", " of stock_list\n", " end;\n", " \n", " return r; \n", " \n", "2022-11-10 10:58:41.551 | INFO | src.TSLfm:process_result_data_type:218 - Processing new df of shape (675, 37), which looks like\n", " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", "0 AP2211 2022-09-02 09:01:00 8950.0 8966.0 8970.0 8950.0 8950.0 \n", "1 AP2211 2022-09-02 09:02:00 8918.0 8950.0 8950.0 8917.0 8918.0 \n", "2 AP2211 2022-09-02 09:03:00 8912.0 8914.0 8914.0 8903.0 8912.0 \n", "3 AP2211 2022-09-02 09:04:00 8920.0 8924.0 8924.0 8912.0 8920.0 \n", "4 AP2211 2022-09-02 09:05:00 8908.0 8920.0 8920.0 8908.0 8908.0 \n", "\n", " m_nAccHigh m_nAccLow m_iVolume ... m_nAccActAskVolume \\\n", "0 8970.0 8950.0 3.0 ... 0.0 \n", "1 8970.0 8917.0 8.0 ... 6.0 \n", "2 8970.0 8903.0 20.0 ... 17.0 \n", "3 8970.0 8903.0 17.0 ... 29.0 \n", "4 8970.0 8903.0 3.0 ... 30.0 \n", "\n", " m_nActAskTurnover m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder \\\n", "0 0.0 0.0 65.0 65.0 \n", "1 53522.0 53522.0 65.0 130.0 \n", "2 98069.0 151591.0 77.0 207.0 \n", "3 106951.0 258542.0 64.0 271.0 \n", "4 8918.0 267460.0 67.0 338.0 \n", "\n", " m_nAskOrder m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate \\\n", "0 61.0 61.0 1.0 1.065574 \n", "1 57.0 118.0 1.0 1.101695 \n", "2 64.0 182.0 0.5 1.137363 \n", "3 63.0 245.0 1.0 1.106122 \n", "4 49.0 294.0 1.0 1.149660 \n", "\n", " m_nMItemsVolRate \n", "0 0.0 \n", "1 0.0 \n", "2 0.0 \n", "3 0.0 \n", "4 0.0 \n", "\n", "[5 rows x 37 columns]\n", "2022-11-10 10:58:41.559 | INFO | src.TSLfm:process_result_data_type:232 - Processing done, new df looks like\n", " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", "0 AP2211 2022-09-02 09:01:00 8950.0 8966.0 8970.0 8950.0 8950.0 \n", "1 AP2211 2022-09-02 09:02:00 8918.0 8950.0 8950.0 8917.0 8918.0 \n", "2 AP2211 2022-09-02 09:03:00 8912.0 8914.0 8914.0 8903.0 8912.0 \n", "3 AP2211 2022-09-02 09:04:00 8920.0 8924.0 8924.0 8912.0 8920.0 \n", "4 AP2211 2022-09-02 09:05:00 8908.0 8920.0 8920.0 8908.0 8908.0 \n", "\n", " m_nAccHigh m_nAccLow m_iVolume ... m_nActAskTurnover \\\n", "0 8970.0 8950.0 3 ... 0.0 \n", "1 8970.0 8917.0 8 ... 53522.0 \n", "2 8970.0 8903.0 20 ... 98069.0 \n", "3 8970.0 8903.0 17 ... 106951.0 \n", "4 8970.0 8903.0 3 ... 8918.0 \n", "\n", " m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder m_nAskOrder \\\n", "0 0.0 65.0 65.0 61.0 \n", "1 53522.0 65.0 130.0 57.0 \n", "2 151591.0 77.0 207.0 64.0 \n", "3 258542.0 64.0 271.0 63.0 \n", "4 267460.0 67.0 338.0 49.0 \n", "\n", " m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate m_nMItemsVolRate \\\n", "0 61.0 1.0 1.065574 0.0 \n", "1 118.0 1.0 1.101695 0.0 \n", "2 182.0 0.5 1.137363 0.0 \n", "3 245.0 1.0 1.106122 0.0 \n", "4 294.0 1.0 1.149660 0.0 \n", "\n", " code_init \n", "0 AP \n", "1 AP \n", "2 AP \n", "3 AP \n", "4 AP \n", "\n", "[5 rows x 38 columns]\n", "2022-11-10 10:58:41.559 | INFO | src.TSLfm:__exit__:24 - Logging out TSL.\n", "2022-11-10 10:58:41.559 | INFO | src.TSLfm:__enter__:18 - Logging in TSL.\n", "2022-11-10 10:58:41.711 | DEBUG | src.TSLfm:get_mkt_min_k:209 - \n", " SetSysParam(pn_cycle(), cy_1m());\n", " stock_list := Array('AP2211', 'AP2212', 'AP2301');\n", " r := select \n", " ['StockID'] as 'code',\n", " DateTimeToStr(['date']) as 'm_nDatetime',\n", "\n", " ['price'] as 'm_nPrice',\n", " ['open'] as 'm_nOpen',\n", " ['high'] as 'm_nHigh',\n", " ['low'] as 'm_nLow',\n", " ['close'] as 'm_nClose',\n", "\n", " ['sectional_high'] as 'm_nAccHigh',\n", " ['sectional_low'] as 'm_nAccLow',\n", "\n", " ['vol'] as 'm_iVolume', //成交量\n", " ['sectional_vol'] as 'm_iAccVolume', //时点当日累计成交量\n", "\n", " ['cjbs'] as 'm_nMatchItems', // 成交笔数 周期内的持仓的变动量\n", " ['sectional_cjbs'] as 'm_nAccMatchItems',\n", "\n", " ['amount'] as 'm_iTurnover', //成交金额\n", " ['sectional_amount'] as 'm_iAccTurnover', \n", "\n", " ['yclose'] as 'm_nPreClose', //上一周期的收盘价\n", " ['sectional_yclose'] as 'm_nAccPreClose', // 前日收盘\n", " \n", " ['buy1'] as 'm_nBidPrice', //买一价?叫卖价?\n", " ['bc1'] as 'm_nBidVolume', //买一量 当前以买一价出价的委买量\n", " ['sale1'] as 'm_nAskPrice', \n", " ['sc1'] as 'm_nAskVolume', \n", "\n", " ['zmm'] as 'm_iABFlag', //买卖标识\n", "\n", " ['buy_vol'] as 'm_nActBidVolume', //主买量\n", " ['sectional_buy_vol'] as 'm_nAccActBidVolume', //时点当日累计主买量\n", " ['buy_amount'] as 'm_nActBidTurnover', //主买金额\n", " ['sectional_buy_amount'] as 'm_nAccActBidTurnover', \n", "\n", " ['sale_vol'] as 'm_nActAskVolume', \n", " ['sectional_sale_vol'] as 'm_nAccActAskVolume', \n", " ['sale_amount'] as 'm_nActAskTurnover',\n", " ['sectional_sale_amount'] as 'm_nAccActAskTurnover', \n", "\n", " ['w_buy'] as 'm_nBidOrder', //委买\n", " ['sectional_w_buy'] as 'm_nAccBidOrder', \n", " ['w_sale'] as 'm_nAskOrder',\n", " ['sectional_w_sale'] as 'm_nAccAskOrder',\n", "\n", " ['wb'] as 'm_nABOrderRate', //委比\n", " ['sectional_wb'] as 'm_nAccABOrderRate', //时点当日累计委比\n", " ['lb'] as 'm_nMItemsVolRate'//量比\n", "\n", "\n", " from markettable\n", " datekey 20220903T to 20220903T+0.999 \n", " of stock_list\n", " end;\n", " \n", " return r; \n", " \n", "2022-11-10 10:58:41.789 | INFO | src.TSLfm:process_result_data_type:216 - No data on this day.\n", "2022-11-10 10:58:41.790 | INFO | src.TSLfm:__exit__:24 - Logging out TSL.\n", "2022-11-10 10:58:41.790 | INFO | src.TSLfm:__enter__:18 - Logging in TSL.\n", "2022-11-10 10:58:41.940 | DEBUG | src.TSLfm:get_mkt_min_k:209 - \n", " SetSysParam(pn_cycle(), cy_1m());\n", " stock_list := Array('AP2211', 'AP2212', 'AP2301');\n", " r := select \n", " ['StockID'] as 'code',\n", " DateTimeToStr(['date']) as 'm_nDatetime',\n", "\n", " ['price'] as 'm_nPrice',\n", " ['open'] as 'm_nOpen',\n", " ['high'] as 'm_nHigh',\n", " ['low'] as 'm_nLow',\n", " ['close'] as 'm_nClose',\n", "\n", " ['sectional_high'] as 'm_nAccHigh',\n", " ['sectional_low'] as 'm_nAccLow',\n", "\n", " ['vol'] as 'm_iVolume', //成交量\n", " ['sectional_vol'] as 'm_iAccVolume', //时点当日累计成交量\n", "\n", " ['cjbs'] as 'm_nMatchItems', // 成交笔数 周期内的持仓的变动量\n", " ['sectional_cjbs'] as 'm_nAccMatchItems',\n", "\n", " ['amount'] as 'm_iTurnover', //成交金额\n", " ['sectional_amount'] as 'm_iAccTurnover', \n", "\n", " ['yclose'] as 'm_nPreClose', //上一周期的收盘价\n", " ['sectional_yclose'] as 'm_nAccPreClose', // 前日收盘\n", " \n", " ['buy1'] as 'm_nBidPrice', //买一价?叫卖价?\n", " ['bc1'] as 'm_nBidVolume', //买一量 当前以买一价出价的委买量\n", " ['sale1'] as 'm_nAskPrice', \n", " ['sc1'] as 'm_nAskVolume', \n", "\n", " ['zmm'] as 'm_iABFlag', //买卖标识\n", "\n", " ['buy_vol'] as 'm_nActBidVolume', //主买量\n", " ['sectional_buy_vol'] as 'm_nAccActBidVolume', //时点当日累计主买量\n", " ['buy_amount'] as 'm_nActBidTurnover', //主买金额\n", " ['sectional_buy_amount'] as 'm_nAccActBidTurnover', \n", "\n", " ['sale_vol'] as 'm_nActAskVolume', \n", " ['sectional_sale_vol'] as 'm_nAccActAskVolume', \n", " ['sale_amount'] as 'm_nActAskTurnover',\n", " ['sectional_sale_amount'] as 'm_nAccActAskTurnover', \n", "\n", " ['w_buy'] as 'm_nBidOrder', //委买\n", " ['sectional_w_buy'] as 'm_nAccBidOrder', \n", " ['w_sale'] as 'm_nAskOrder',\n", " ['sectional_w_sale'] as 'm_nAccAskOrder',\n", "\n", " ['wb'] as 'm_nABOrderRate', //委比\n", " ['sectional_wb'] as 'm_nAccABOrderRate', //时点当日累计委比\n", " ['lb'] as 'm_nMItemsVolRate'//量比\n", "\n", "\n", " from markettable\n", " datekey 20221102T to 20221102T+0.999 \n", " of stock_list\n", " end;\n", " \n", " return r; \n", " \n", "2022-11-10 10:58:42.352 | INFO | src.TSLfm:process_result_data_type:218 - Processing new df of shape (675, 37), which looks like\n", " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", "0 AP2211 2022-11-02 09:01:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "1 AP2211 2022-11-02 09:02:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "2 AP2211 2022-11-02 09:03:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "3 AP2211 2022-11-02 09:04:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "4 AP2211 2022-11-02 09:05:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "\n", " m_nAccHigh m_nAccLow m_iVolume ... m_nAccActAskVolume \\\n", "0 8860.0 8860.0 0.0 ... 0.0 \n", "1 8860.0 8860.0 0.0 ... 0.0 \n", "2 8860.0 8860.0 0.0 ... 0.0 \n", "3 8860.0 8860.0 0.0 ... 0.0 \n", "4 8860.0 8860.0 0.0 ... 0.0 \n", "\n", " m_nActAskTurnover m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder \\\n", "0 0.0 0.0 1.0 1.0 \n", "1 0.0 0.0 5.0 6.0 \n", "2 0.0 0.0 0.0 6.0 \n", "3 0.0 0.0 0.0 6.0 \n", "4 0.0 0.0 0.0 6.0 \n", "\n", " m_nAskOrder m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate \\\n", "0 1.0 1.0 1.0 1.0 \n", "1 5.0 6.0 1.0 1.0 \n", "2 0.0 6.0 1.0 1.0 \n", "3 0.0 6.0 1.0 1.0 \n", "4 0.0 6.0 1.0 1.0 \n", "\n", " m_nMItemsVolRate \n", "0 0.0 \n", "1 0.0 \n", "2 0.0 \n", "3 0.0 \n", "4 0.0 \n", "\n", "[5 rows x 37 columns]\n", "2022-11-10 10:58:42.358 | INFO | src.TSLfm:process_result_data_type:232 - Processing done, new df looks like\n", " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", "0 AP2211 2022-11-02 09:01:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "1 AP2211 2022-11-02 09:02:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "2 AP2211 2022-11-02 09:03:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "3 AP2211 2022-11-02 09:04:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "4 AP2211 2022-11-02 09:05:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", "\n", " m_nAccHigh m_nAccLow m_iVolume ... m_nActAskTurnover \\\n", "0 8860.0 8860.0 0 ... 0.0 \n", "1 8860.0 8860.0 0 ... 0.0 \n", "2 8860.0 8860.0 0 ... 0.0 \n", "3 8860.0 8860.0 0 ... 0.0 \n", "4 8860.0 8860.0 0 ... 0.0 \n", "\n", " m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder m_nAskOrder \\\n", "0 0.0 1.0 1.0 1.0 \n", "1 0.0 5.0 6.0 5.0 \n", "2 0.0 0.0 6.0 0.0 \n", "3 0.0 0.0 6.0 0.0 \n", "4 0.0 0.0 6.0 0.0 \n", "\n", " m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate m_nMItemsVolRate \\\n", "0 1.0 1.0 1.0 0.0 \n", "1 6.0 1.0 1.0 0.0 \n", "2 6.0 1.0 1.0 0.0 \n", "3 6.0 1.0 1.0 0.0 \n", "4 6.0 1.0 1.0 0.0 \n", "\n", " code_init \n", "0 AP \n", "1 AP \n", "2 AP \n", "3 AP \n", "4 AP \n", "\n", "[5 rows x 38 columns]\n", "2022-11-10 10:58:42.359 | INFO | src.TSLfm:__exit__:24 - Logging out TSL.\n" ] } ], "source": [ "from src.TSLfm import TSLfm\n", "# ddbfm = DDBfm('dev')\n", "df_list = []\n", "for date in ['20220902','20220903','20221102']:\n", " with TSLfm() as tsl:\n", " df = tsl.process_result_data_type(tsl.get_mkt_min_k(date,date,['AP2211','AP2212','AP2301']))\n", " df_list.append(df)\n", " # logger.info(f'Getting a df of {df.shape}: {code_list[0][:-4]} on {date}')\n", " # ddbfm.append_hft_table(ddb.ddf_hft_mink_tbname,df)\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[ code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", " 0 AP2211 2022-09-02 09:01:00 8950.0 8966.0 8970.0 8950.0 8950.0 \n", " 1 AP2211 2022-09-02 09:02:00 8918.0 8950.0 8950.0 8917.0 8918.0 \n", " 2 AP2211 2022-09-02 09:03:00 8912.0 8914.0 8914.0 8903.0 8912.0 \n", " 3 AP2211 2022-09-02 09:04:00 8920.0 8924.0 8924.0 8912.0 8920.0 \n", " 4 AP2211 2022-09-02 09:05:00 8908.0 8920.0 8920.0 8908.0 8908.0 \n", " .. ... ... ... ... ... ... ... \n", " 670 AP2301 2022-09-02 14:56:00 9193.0 9194.0 9198.0 9190.0 9193.0 \n", " 671 AP2301 2022-09-02 14:57:00 9204.0 9192.0 9204.0 9192.0 9204.0 \n", " 672 AP2301 2022-09-02 14:58:00 9210.0 9202.0 9210.0 9200.0 9210.0 \n", " 673 AP2301 2022-09-02 14:59:00 9209.0 9206.0 9213.0 9206.0 9209.0 \n", " 674 AP2301 2022-09-02 15:00:00 9211.0 9210.0 9215.0 9207.0 9211.0 \n", " \n", " m_nAccHigh m_nAccLow m_iVolume ... m_nActAskTurnover \\\n", " 0 8970.0 8950.0 3 ... 0.0 \n", " 1 8970.0 8917.0 8 ... 53522.0 \n", " 2 8970.0 8903.0 20 ... 98069.0 \n", " 3 8970.0 8903.0 17 ... 106951.0 \n", " 4 8970.0 8903.0 3 ... 8918.0 \n", " .. ... ... ... ... ... \n", " 670 9220.0 9080.0 368 ... 1154034.0 \n", " 671 9220.0 9080.0 568 ... 952568.0 \n", " 672 9220.0 9080.0 707 ... 1951080.0 \n", " 673 9220.0 9080.0 763 ... 3968840.0 \n", " 674 9220.0 9080.0 918 ... 3979399.0 \n", " \n", " m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder m_nAskOrder \\\n", " 0 0.0 65.0 65.0 61.0 \n", " 1 53522.0 65.0 130.0 57.0 \n", " 2 151591.0 77.0 207.0 64.0 \n", " 3 258542.0 64.0 271.0 63.0 \n", " 4 267460.0 67.0 338.0 49.0 \n", " .. ... ... ... ... \n", " 670 223212226.0 739.0 106767.0 873.0 \n", " 671 224164794.0 1250.0 108017.0 3668.0 \n", " 672 226115874.0 631.0 108648.0 1723.0 \n", " 673 230084714.0 2361.0 111009.0 1079.0 \n", " 674 234064113.0 1555.0 112564.0 1902.0 \n", " \n", " m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate m_nMItemsVolRate \\\n", " 0 61.0 1.000000 1.065574 0.0 \n", " 1 118.0 1.000000 1.101695 0.0 \n", " 2 182.0 0.500000 1.137363 0.0 \n", " 3 245.0 1.000000 1.106122 0.0 \n", " 4 294.0 1.000000 1.149660 0.0 \n", " .. ... ... ... ... \n", " 670 173656.0 0.100000 0.614819 0.0 \n", " 671 177324.0 5.000000 0.609150 0.0 \n", " 672 179047.0 3.000000 0.606813 0.0 \n", " 673 180126.0 2.666667 0.616285 0.0 \n", " 674 182028.0 0.271605 0.618388 0.0 \n", " \n", " code_init \n", " 0 AP \n", " 1 AP \n", " 2 AP \n", " 3 AP \n", " 4 AP \n", " .. ... \n", " 670 AP \n", " 671 AP \n", " 672 AP \n", " 673 AP \n", " 674 AP \n", " \n", " [675 rows x 38 columns],\n", " Empty DataFrame\n", " Columns: []\n", " Index: [],\n", " code m_nDatetime m_nPrice m_nOpen m_nHigh m_nLow m_nClose \\\n", " 0 AP2211 2022-11-02 09:01:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", " 1 AP2211 2022-11-02 09:02:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", " 2 AP2211 2022-11-02 09:03:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", " 3 AP2211 2022-11-02 09:04:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", " 4 AP2211 2022-11-02 09:05:00 8860.0 8860.0 8860.0 8860.0 8860.0 \n", " .. ... ... ... ... ... ... ... \n", " 670 AP2301 2022-11-02 14:56:00 8264.0 8260.0 8269.0 8258.0 8264.0 \n", " 671 AP2301 2022-11-02 14:57:00 8271.0 8264.0 8275.0 8263.0 8271.0 \n", " 672 AP2301 2022-11-02 14:58:00 8269.0 8272.0 8276.0 8268.0 8269.0 \n", " 673 AP2301 2022-11-02 14:59:00 8269.0 8270.0 8277.0 8269.0 8269.0 \n", " 674 AP2301 2022-11-02 15:00:00 8265.0 8268.0 8270.0 8260.0 8265.0 \n", " \n", " m_nAccHigh m_nAccLow m_iVolume ... m_nActAskTurnover \\\n", " 0 8860.0 8860.0 0 ... 0.0 \n", " 1 8860.0 8860.0 0 ... 0.0 \n", " 2 8860.0 8860.0 0 ... 0.0 \n", " 3 8860.0 8860.0 0 ... 0.0 \n", " 4 8860.0 8860.0 0 ... 0.0 \n", " .. ... ... ... ... ... \n", " 670 8325.0 8190.0 523 ... 2124105.0 \n", " 671 8325.0 8190.0 998 ... 3355590.0 \n", " 672 8325.0 8190.0 435 ... 1603410.0 \n", " 673 8325.0 8190.0 942 ... 3190290.0 \n", " 674 8325.0 8190.0 1626 ... 6190485.0 \n", " \n", " m_nAccActAskTurnover m_nBidOrder m_nAccBidOrder m_nAskOrder \\\n", " 0 0.0 1.0 1.0 1.0 \n", " 1 0.0 5.0 6.0 5.0 \n", " 2 0.0 0.0 6.0 0.0 \n", " 3 0.0 0.0 6.0 0.0 \n", " 4 0.0 0.0 6.0 0.0 \n", " .. ... ... ... ... \n", " 670 682298903.0 1040.0 285907.0 1062.0 \n", " 671 685654493.0 1512.0 287419.0 2259.0 \n", " 672 687257903.0 696.0 288115.0 1567.0 \n", " 673 690448193.0 2008.0 290123.0 2516.0 \n", " 674 696638678.0 2027.0 292150.0 2496.0 \n", " \n", " m_nAccAskOrder m_nABOrderRate m_nAccABOrderRate m_nMItemsVolRate \\\n", " 0 1.0 1.000000 1.000000 0.0 \n", " 1 6.0 1.000000 1.000000 0.0 \n", " 2 6.0 1.000000 1.000000 0.0 \n", " 3 6.0 1.000000 1.000000 0.0 \n", " 4 6.0 1.000000 1.000000 0.0 \n", " .. ... ... ... ... \n", " 670 278256.0 4.600000 1.027496 0.0 \n", " 671 280515.0 9.000000 1.024612 0.0 \n", " 672 282082.0 6.666667 1.021387 0.0 \n", " 673 284598.0 7.000000 1.019413 0.0 \n", " 674 287094.0 1.941176 1.017611 0.0 \n", " \n", " code_init \n", " 0 AP \n", " 1 AP \n", " 2 AP \n", " 3 AP \n", " 4 AP \n", " .. ... \n", " 670 AP \n", " 671 AP \n", " 672 AP \n", " 673 AP \n", " 674 AP \n", " \n", " [675 rows x 38 columns]]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.Asyn worker closed peacefully.\n", "\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n", "Asyn worker closed peacefully.\n" ] } ], "source": [ "df_list\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from src.code_list_all_pkl import code_list\n", "code_init = set([c[:-4] for c in code_list])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "77" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(code_init)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'ap': 'AP',\n", " 'fg': 'FG',\n", " 'rm': 'RM',\n", " 'al': 'al',\n", " 'rs': 'RS',\n", " 'pg': 'pg',\n", " 'jm': 'jm',\n", " 'wh': 'WH',\n", " 'er': 'ER',\n", " 'cs': 'cs',\n", " 'fb': 'fb',\n", " 'pk': 'PK',\n", " 'pp': 'pp',\n", " 'p': 'p',\n", " 'ag': 'ag',\n", " 'pm': 'PM',\n", " 'ih': 'IH',\n", " 'wt': 'WT',\n", " 'ni': 'ni',\n", " 'j': 'j',\n", " 'ru': 'ru',\n", " 'b': 'b',\n", " 'ta': 'TA',\n", " 'rr': 'rr',\n", " 'sa': 'SA',\n", " 'jr': 'JR',\n", " 'y': 'y',\n", " 'jd': 'jd',\n", " 'lr': 'LR',\n", " 'sr': 'SR',\n", " 'm': 'm',\n", " 'sf': 'SF',\n", " 'eb': 'eb',\n", " 'i': 'i',\n", " 't': 'T',\n", " 'ur': 'UR',\n", " 'bu': 'bu',\n", " 'zn': 'zn',\n", " 'pf': 'PF',\n", " 'l': 'l',\n", " 'ts': 'TS',\n", " 'ws': 'WS',\n", " 'zc': 'ZC',\n", " 'tc': 'TC',\n", " 'eg': 'eg',\n", " 'me': 'ME',\n", " 'a': 'a',\n", " 'cy': 'CY',\n", " 'sn': 'sn',\n", " 'pb': 'pb',\n", " 'ic': 'IC',\n", " 'ro': 'RO',\n", " 'wr': 'wr',\n", " 'ri': 'RI',\n", " 'oi': 'OI',\n", " 'fu': 'fu',\n", " 'nr': 'nr',\n", " 'cu': 'cu',\n", " 'if': 'IF',\n", " 'rb': 'rb',\n", " 'bc': 'bc',\n", " 'cf': 'CF',\n", " 'sp': 'sp',\n", " 'c': 'c',\n", " 'lh': 'lh',\n", " 'tf': 'TF',\n", " 'lu': 'lu',\n", " 'ma': 'MA',\n", " 'im': 'IM',\n", " 'hc': 'hc',\n", " 'sm': 'SM',\n", " 'bb': 'bb',\n", " 'cj': 'CJ',\n", " 'au': 'au',\n", " 'ss': 'ss',\n", " 'v': 'v',\n", " 'sc': 'sc'}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "code_init_case_mapping = {}\n", "for c in code_init:\n", " code_init_case_mapping[c.lower()] = c\n", "code_init_case_mapping" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "77\n" ] } ], "source": [ "from src.code_list_all_pkl import code_init_case_mapping as cp\n", "print(len(cp))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.9 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" } } }, "nbformat": 4, "nbformat_minor": 2 }