Example #1
0
def get_stock_tick_data(stock_codes, date):
    """
    获取股票当天的tick数据
    :param stock_codes:  股票代码
    :param date: 日期
    :return:
    """
    ret = StrategyBase('13554406825', 'qq532357515')
    date = pd.to_datetime(date).strftime('%Y-%m-%d')
    for code in stock_codes:
        st = date + ' 09:30:00'
        et = date + ' 15:00:00'
        data = ret.get_ticks(code, st, et)
        data = [props(d) for d in data]
        data = pd.DataFrame(data)
        data = clean_data(data)
        yield data
Example #2
0
def update_stock_tick(date=None):
    """
    将csv数据读取到数据库中
    date: 日期
    :return: no return
    """

    conn = create_engine(
        'postgres+psycopg2://postgres:123456@localhost:5432/postgres',
        echo=True)

    ret = StrategyBase('13554406825', 'qq532357515')
    sh_stocks = ret.get_instruments(exchange='SHSE', sec_type=1, is_active=1)
    sz_stocks = ret.get_instruments(exchange='SZSE', sec_type=1, is_active=1)
    stocks = sh_stocks + sz_stocks
    stocks = [i.symbol for i in stocks]

    for data in get_stock_tick_data(stocks, date):
        insert_data(data, conn)
 def close_short_yesterday(self, bar, price, volume, comments=None):
     StrategyBase.close_short_yesterday(self, bar.exchange, bar.sec_id,
                                        price, volume)
     if comments is not None:
         print((bar.strendtime, '平空', volume, comments))
 def open_short(self, bar, price, volume, comments=None):
     StrategyBase.open_short(self, bar.exchange, bar.sec_id, price, volume)
     if comments is not None:
         print((bar.strendtime, '开空', volume, comments))
 def close_long(self, bar, price, volume, comments=None):
     StrategyBase.close_long(self, bar.exchange, bar.sec_id, price, volume)
     if comments is not None:
         print((bar.strendtime, '平多', volume, comments))
 def open_long(self, bar, price, volume, comments=None):
     # print('bar type', type(bar), 'price', price, 'volume', volume, 'comments', comments)
     StrategyBase.open_long(self, bar.exchange, bar.sec_id, price, volume)
     if comments is not None:
         print((bar.strendtime, '开多', volume, comments))