@ -1,12 +1,13 @@
from code_list_all_pkl import code_list as code_list_pickel_from_file , all_fm_init_curr
from code_list_all_pkl import code_list as code_list_pickel_from_file , all_fm_init_curr , tsl_ind_codeinit_mapping
from TSLfm import TSLfm
from TSLfm import TSLfm
from DDBfm import DDBfm
from DDBfm import DDBfm
import pandas as pd
import pandas as pd
import numpy as np
from loguru import logger
from loguru import logger
from os . path import dirname , abspath , join
from os . path import dirname , abspath , join
import sys
import sys
running_which_env = ' pr d'
running_which_env = ' dev '
def run_add_1day_code_init_minKline ( date , code_list ) :
def run_add_1day_code_init_minKline ( date , code_list ) :
@ -32,6 +33,12 @@ def run_add_1day_code_init_minKline(date, code_list):
f ' Getting a df of { df . shape } : { " + " . join ( code_list ) } on { date } ' )
f ' Getting a df of { df . shape } : { " + " . join ( code_list ) } on { date } ' )
ddb . append_hft_table ( ddb . ddf_hft_mink_tbname , df )
ddb . append_hft_table ( ddb . ddf_hft_mink_tbname , df )
def map_code_tsl_to_9999indcode ( code_tsl ) :
if code_tsl in tsl_ind_codeinit_mapping :
return tsl_ind_codeinit_mapping [ code_tsl ] + ' 9999 '
else :
logger . error ( f ' TSL code didnt find mapping for { code_tsl } ' )
return np . nan
def check_if_date_codelist_exists ( typ , date , code_list ) :
def check_if_date_codelist_exists ( typ , date , code_list ) :
code_list_filtered = [ ]
code_list_filtered = [ ]
@ -47,7 +54,7 @@ def check_if_date_codelist_exists(typ, date, code_list):
if typ == ' tick ' :
if typ == ' tick ' :
tbName = ddb1 . ddf_hft_tick_tbname
tbName = ddb1 . ddf_hft_tick_tbname
elif typ == ' mink ' :
elif typ in [ ' mink ' , ' indl ' ] :
tbName = ddb1 . ddf_hft_mink_tbname
tbName = ddb1 . ddf_hft_mink_tbname
code_list_filtered = ddb1 . get_missing_code_date_in_tb (
code_list_filtered = ddb1 . get_missing_code_date_in_tb (
@ -64,15 +71,26 @@ def check_if_date_codelist_exists(typ, date, code_list):
def run_pool_add_by_datelist_codeinit ( typ , date_list , code_list , if_check = 1 ) :
def run_pool_add_by_datelist_codeinit ( typ , date_list , code_list , if_check = 1 ) :
df_list = [ ]
df_list = [ ]
if typ == ' indl ' :
code_list_filtered = [ ] # real code in ddb
code_list_tsl_code = [ ]
for c in code_list :
code_list_filtered . append ( map_code_tsl_to_9999indcode ( c ) )
code_list_tsl_code . append ( c )
else :
code_list_filtered = code_list
for date in date_list :
for date in date_list :
if if_check :
if if_check :
code_list_filtered = check_if_date_codelist_exists (
code_list_filtered = check_if_date_codelist_exists (
typ , date , code_list )
typ , date , code_list _filtered )
else :
code_list_filtered = code_list
with TSLfm ( ) as tsl :
with TSLfm ( ) as tsl :
if typ == ' tick ' :
if typ == ' tick ' :
df = tsl . process_result_data_type (
df = tsl . process_result_data_type (
@ -80,6 +98,15 @@ def run_pool_add_by_datelist_codeinit(typ, date_list, code_list, if_check=1):
elif typ == ' mink ' :
elif typ == ' mink ' :
df = tsl . process_result_data_type (
df = tsl . process_result_data_type (
tsl . get_mkt_min_k ( date , date , code_list_filtered ) )
tsl . get_mkt_min_k ( date , date , code_list_filtered ) )
elif typ == ' indl ' :
df = tsl . process_result_data_type (
tsl . get_mkt_min_k ( date , date , code_list_tsl_code ) )
if typ == ' indl ' and not df . empty :
# df.rename(columns={'code':'code_tsl'},inplace=True)
df [ ' code ' ] = df [ ' code ' ] . apply ( map_code_tsl_to_9999indcode )
df [ ' code_init ' ] = df [ ' code ' ] . apply ( lambda x : x [ : - 4 ] )
# df.drop('code_tsl',axis=1,inplace=True)
if not df . empty :
if not df . empty :
df_list . append ( df )
df_list . append ( df )
if not df_list :
if not df_list :
@ -91,7 +118,7 @@ def run_pool_add_by_datelist_codeinit(typ, date_list, code_list, if_check=1):
f ' Getting a df of { df_all . shape } : { code_list [ 0 ] [ : - 4 ] } on { " + " . join ( date_list ) } ' )
f ' Getting a df of { df_all . shape } : { code_list [ 0 ] [ : - 4 ] } on { " + " . join ( date_list ) } ' )
if typ == ' tick ' :
if typ == ' tick ' :
ddb2 . append_pool_hft_table ( ddb2 . ddf_hft_tick_tbname , df_all )
ddb2 . append_pool_hft_table ( ddb2 . ddf_hft_tick_tbname , df_all )
elif typ == ' mink ' :
elif typ in [ ' mink ' , ' indl ' ] :
ddb2 . append_pool_hft_table ( ddb2 . ddf_hft_mink_tbname , df_all )
ddb2 . append_pool_hft_table ( ddb2 . ddf_hft_mink_tbname , df_all )
ddb2 . close_sess ( )
ddb2 . close_sess ( )
del ddb2
del ddb2
@ -149,6 +176,8 @@ def run():
def run_pool_dates_by_code_init_n_group ( typ = ' mink ' , code_gp_amt = 10 , date_gp_amt = 10 , start_date = ' 20220101 ' , end_date = ' 20221031 ' , if_check = 1 , code_dict_by = ' init ' ) :
def run_pool_dates_by_code_init_n_group ( typ = ' mink ' , code_gp_amt = 10 , date_gp_amt = 10 , start_date = ' 20220101 ' , end_date = ' 20221031 ' , if_check = 1 , code_dict_by = ' init ' ) :
logger . info ( " Running run_pool_dates_by_group " )
logger . info ( " Running run_pool_dates_by_group " )
if typ in [ ' mink ' , ' tick ' ] :
code_list_pickel = code_list_pickel_from_file
code_list_pickel = code_list_pickel_from_file
code_list_pickel = sorted ( list ( set ( code_list_pickel ) ) )
code_list_pickel = sorted ( list ( set ( code_list_pickel ) ) )
all_code_dict_by_init = { }
all_code_dict_by_init = { }
@ -163,7 +192,6 @@ def run_pool_dates_by_code_init_n_group(typ='mink', code_gp_amt=10, date_gp_amt=
all_code_dict_by_init [ init ] = [ c ]
all_code_dict_by_init [ init ] = [ c ]
else :
else :
logger . warning ( " There ' s unrecognized code init!!!! " )
logger . warning ( " There ' s unrecognized code init!!!! " )
if code_dict_by == ' init ' :
if code_dict_by == ' init ' :
all_code_dict = all_code_dict_by_init
all_code_dict = all_code_dict_by_init
if code_dict_by == ' group ' :
if code_dict_by == ' group ' :
@ -176,6 +204,19 @@ def run_pool_dates_by_code_init_n_group(typ='mink', code_gp_amt=10, date_gp_amt=
all_code_dict_by_group_no [ group_no ] + = all_code_dict_by_init [ code_init ]
all_code_dict_by_group_no [ group_no ] + = all_code_dict_by_init [ code_init ]
all_code_dict = all_code_dict_by_group_no
all_code_dict = all_code_dict_by_group_no
elif typ in [ ' indl ' ] :
tsl_ind_code_list = [ ]
real_code_init_list = [ ]
all_code_dict = { }
for c in sorted ( tsl_ind_codeinit_mapping ) :
if tsl_ind_codeinit_mapping [ c ] in all_fm_init_curr :
tsl_ind_code_list . append ( c )
real_code_init_list . append ( tsl_ind_codeinit_mapping [ c ] )
all_code_dict [ tsl_ind_codeinit_mapping [ c ] ] = [ c ]
else :
logger . warning ( f " There ' s unrecognized code init: { tsl_ind_codeinit_mapping [ c ] } !!!! " )
allDates = pd . date_range ( start_date , end_date , freq = ' D ' )
allDates = pd . date_range ( start_date , end_date , freq = ' D ' )
dates_dict_by_day = { }
dates_dict_by_day = { }
@ -199,16 +240,9 @@ def run_pool_dates_by_code_init_n_group(typ='mink', code_gp_amt=10, date_gp_amt=
code_list = all_code_dict [ code_init ]
code_list = all_code_dict [ code_init ]
logger . info ( date_list )
logger . info ( date_list )
logger . info ( code_list )
logger . info ( code_list )
if typ == ' mink ' :
# logger.info('Running mink')
run_pool_add_by_datelist_codeinit (
run_pool_add_by_datelist_codeinit (
' mink ' , date_list , code_list , if_check )
typ , date_list , code_list , if_check )
# run_pool_add_byday_code_init_minKline(date_list,code_list)
elif typ == ' tick ' :
logger . info ( ' Running tick ' )
run_pool_add_by_datelist_codeinit (
' tick ' , date_list , code_list , if_check )
if __name__ == ' __main__ ' :
if __name__ == ' __main__ ' :
@ -231,12 +265,12 @@ if __name__ == '__main__':
split_code_into_howmany_groups_no = int ( split_code_into_howmany_groups_no )
split_code_into_howmany_groups_no = int ( split_code_into_howmany_groups_no )
split_date_into_howmany_groups = int ( split_date_into_howmany_groups )
split_date_into_howmany_groups = int ( split_date_into_howmany_groups )
else :
else :
typ = ' tick '
typ = ' indl '
st_d = ' 202 112 01'
st_d = ' 202 2 1101'
en_d = ' 202 1123 1'
en_d = ' 202 2110 1'
if_check = True
if_check = True
split_code_into_howmany_groups_no = 20
split_code_into_howmany_groups_no = 1 # how many in 1 gp
split_date_into_howmany_groups = 5
split_date_into_howmany_groups = 1
logger . add ( ROOT_DIR + " /logs/ { time:YYYYMMDD-HHmmss} " + f " _ { running_which_env } _ { typ } _ { st_d } _ { en_d } _ { if_check } _ { split_code_into_howmany_groups_no } _ { split_date_into_howmany_groups } .log " ,
logger . add ( ROOT_DIR + " /logs/ { time:YYYYMMDD-HHmmss} " + f " _ { running_which_env } _ { typ } _ { st_d } _ { en_d } _ { if_check } _ { split_code_into_howmany_groups_no } _ { split_date_into_howmany_groups } .log " ,