def buy(self, strategy_code, date):
        sql = """
        select a.ts_code, b.name from strategy_result a inner join future_basic_info_data b
        on a.ts_code=b.ts_code
        where a.bs_flag='B' and a.date=(select max(date) from strategy_result where strategy_code=:strategy_code and date <= :date) 
        and strategy_code=:strategy_code order by a.ts_code
        """
        args = {"date": date, "strategy_code": strategy_code}
        result = get_multi_data(self._session, sql, args)

        return result
Esempio n. 2
0
    def get_future_info_by_symbol(self, symbol_code_list):
        index_dict = dict(zip([i for i in symbol_code_list], count()))

        sql = """
        select ts_code, name from  future_basic_info_data 
        where symbol in ({0})
        """.format("'" + "','".join(symbol_code_list) + "'")
        args = {}
        result = get_multi_data(self._session, sql, args)

        result = sorted(result, key=lambda x: index_dict[x[0].split('.')[0]])

        return result
Esempio n. 3
0
    def get_future_interval_point_data_by_main_code(self, ts_code, end_date):
        sql = """select a.close, a.trade_date, b.mapping_ts_code as ts_code from 
        future_daily_point_data a inner join
        (select trade_date, mapping_ts_code from future_main_code_data where ts_code=(
        select ts_code from future_main_code_data where mapping_ts_code= :ts_code limit 1)) b 
        on a.ts_code=b.mapping_ts_code and a.trade_date=b.trade_date
        where a.trade_date >= :start_date and a.trade_date <= :end_date
        order by a.trade_date"""

        args = {
            "ts_code": ts_code,
            "start_date": end_date - datetime.timedelta(days=1800),
            "end_date": end_date
        }
        result = get_multi_data(self._session, sql, args)

        result = pd.DataFrame(result,
                              columns=['close', 'trade_date', 'ts_code'])

        return result
Esempio n. 4
0
    def get_future_interval_point_data(self, ts_code, start_date, end_date):
        sql = '''
        select ts_code, trade_date, `open`, high, low, close, settle, change1, change2, vol, amount from future_daily_point_data where 
        ts_code = :ts_code and trade_date >= :start_date and trade_date <= :end_date
        order by trade_date
        '''
        args = {
            "ts_code": ts_code,
            "start_date": start_date,
            "end_date": end_date
        }
        result = get_multi_data(self._session, sql, args)

        result = pd.DataFrame(result,
                              columns=[
                                  'ts_code', 'trade_date', 'open', 'high',
                                  'low', 'close', 'settle', 'change1',
                                  'change2', 'vol', 'amount'
                              ])

        return result