예제 #1
0
def crawlSecurityData_AtFront(daysCount):
    securities = fd.get_all_securities()
    min_date = dao.select("select min(date) min_date from security_data",
                          ())[0]['min_date']
    if min_date is not None:
        endDate = fd.preOpenDate(min_date, 1)
    else:
        endDate = fd.getLastestOpenDate()
    startDate = fd.preOpenDate(endDate, daysCount)
    if startDate > endDate: return
    for code in securities:
        count = 0
        df = ts.get_k_data(code, startDate, endDate)
        arr_values = []
        while count < df.index.__len__():
            open = str(df['open'].values[count])
            close = str(df['close'].values[count])
            high = str(df['high'].values[count])
            low = str(df['low'].values[count])
            volume = str(df['volume'].values[count])
            date = str(df['date'].values[count])
            arr_values.append((code, date, open, close, high, low, volume))
            count = count + 1
            print("Date: " + date + " Code: " + code)

        #dao.update("delete from security_data where code=%s", (code,))
        dao.updatemany(
            "insert into security_data(code, date, open, close, high, low, volume) values(%s,%s,%s,%s,%s,%s,%s)",
            arr_values)
예제 #2
0
def notifyTrade(security):
    currentTimeString = util.getYMDHMS()
    duo = str(int(dao.readDuoPosition(security=security)))
    kon = str(int(dao.readKongPosition(security=security)))
    max = str(int(dao.readMaxPosition(security=security)))
    a = '<p>duo: <strong>' + duo + '</strong></p><p>kon: <strong>' + kon + '</strong></p><p>max: <strong>' + max + '</strong></p>'
    sendEmail(subject='[' + str(currentTimeString) + '] 触发交易动作_' + security,
              content='' + a)
예제 #3
0
def get_zhangtingconcept_countMap(dayCount):
    nowDate = fd.getLastestOpenDate()
    #(1)获取所有concept的集合(大于1)
    startDate = fd.preOpenDate(nowDate, dayCount)
    rows = dao.select("select concept from zhangting_concept where date>=%s group by concept", (startDate))
    concepts = []
    for row in rows:
        concept = row['concept']
        concepts.append(concept)

    #(2)迭代concept,获取count,在特定的date
    # date = nowDate
    # while date > startDate:
    #     rows = dao.select("select concept, count(0) count from zhangting_concept where date=%s group by concept", (date))
    #     for row in rows:
    #         concept = row['concept']
    #         count = row['count']
    date = startDate
    ret = {}
    concept_count_rel = {}


    for concept in concepts:
        countsArr = []
        _date = date
        while _date <= nowDate:
            row = dao.select("select count(0) count from zhangting_concept where date=%s and concept=%s", (_date, concept))
            count = str(row[0]['count'])
            countsArr.append(count)
            _date = fd.nextOpenDate(_date, 1)
        concept_count_rel.setdefault(concept, countsArr)
    ret.setdefault('concept_count_rel', concept_count_rel)
    ret.setdefault('concepts', concepts)
    #(3)返回图标接受的数据model

    # endDate = fd.getLastestOpenDate()
    # startDate = fd.preOpenDate(endDate, dayCount)
    # nowDate = startDate
    # ret = {}
    # while nowDate <= endDate:
    #     try:
    #         arr = dao.select("select count(0) count, concept from zhangting_concept where date = %s GROUP BY concept", (nowDate))
    #     except Exception as e:
    #         return "get_zhangtingconcept_countMap mysql error"
    #     map = {}
    #     for it in arr:
    #         count = it['count']
    #         concept = it['concept']
    #         map.setdefault(concept, count)
    #     ret[nowDate] = map
    #     nowDate = fd.nextOpenDate(nowDate, 1)
    dates = []
    _date = date
    while _date <= nowDate:
        dates.append(_date)
        _date = fd.nextOpenDate(_date, 1)
    ret.setdefault('dates', dates)
    return ret
예제 #4
0
def init():
    #(1) 更新t_position,没有就插入
    dao.updateAllPosition(max, jqdata_security)
    #(2) 更新CTA_setting.json
    with open('CTA_setting.json', 'w') as json_file:
        json_file.write(
            json.dumps([{
                "name":
                strategy,
                "className":
                strategy,
                "vtSymbol":
                util.get_CTA_setting_dominant_future(
                    jqSecurity=jqdata_security)
            }]))
        print "################# My t_position and CTA_setting.json REFRESH! ######################"
예제 #5
0
def prepare():
    #securities
    securities = [
        item['code'] for item in dao.select(
            "select distinct code from t_security_concept", ())
    ]
    me.setdefault('securities', securities)
    #code_items_rel
    code_items_rel = {}
    starttime = util.preOpenDate(util.getLastestOpenDate(), Prepare_TimeLen)
    total = dao.select(
        'select count(0) count from t_security_daily where date>=%s order by date desc',
        (starttime))[0]['count']
    fromindex = 0
    pagesize = 100
    count = 0
    while True:
        print("Range: " + str(fromindex) + "->" + str(fromindex + pagesize))
        tem_codes = me['securities'][fromindex:(fromindex + pagesize)]
        items = dao.select(
            'select code, date, pre_close, high, low, close, open from t_security_daily where code in %s and date>=%s order by date desc',
            (tem_codes, starttime))
        for item in items:
            code = item['code']
            date = item['date']
            if code not in code_items_rel.keys():
                code_items_rel.setdefault(code, [item])
            else:
                code_items_rel[code].append(item)
            count = count + 1
            log.log('Code: ' + code + " Date: " + date)
        if tem_codes.__len__() != pagesize or count >= total:
            break
        fromindex = fromindex + pagesize
    me.setdefault('code_items_rel', code_items_rel)

    #code_lastestClose_rel
    code_lastestItem_rel = {}
    items = dao.select(
        'select code, date, pre_close, high, low, close, open from t_security_daily where date in (select max(date) max from t_security_daily) order by date desc',
        ())
    for item in items:
        code = item['code']
        code_lastestItem_rel.setdefault(code, item)
    me.setdefault('code_lastestItem_rel', code_lastestItem_rel)
예제 #6
0
    def __init__(self, security, ctaEngine):
        self.security = security
        self.ctaEngine = ctaEngine
        self.lockActionToken = False  # 瞬间动作标记
        self.unlockActionToken = False  # 瞬间动作标记
        self.maxPosition = dao.readMaxPosition(security=security)
        print "RickControl初始化:已从DB读取maxPosition:" + str(self.maxPosition)
        self.realOpenKonPrice = dao.readRealOpenKonPrice(
            security=self.security)
        print "RickControl初始化:已从DB读取realOpenKonPrice:" + str(
            self.realOpenKonPrice)
        self.realOpenDuoPrice = dao.readRealOpenDuoPrice(
            security=self.security)
        print "RickControl初始化:已从DB读取realOpenDuoPrice:" + str(
            self.realOpenDuoPrice)
        self.locking = dao.readLocking(security=self.security)
        print "RickControl初始化:已从DB读取locking:" + str(self.locking)

        print('RickControl初始化:完成')
예제 #7
0
def init():
    #(1) 更新t_position,没有就插入
    dao.updateAllPosition(duo=duo, kon=kon, max=max, security=jqdata_security)
    #(2) 更新CTA_setting.json
    vtSymbol = util.get_CTA_setting_dominant_future(jqSecurity=jqdata_security)
    #(3)riskcontrol重设
    controlRisk = ControlRisk(security=jqdata_security, ctaEngine=None)
    controlRisk.releaseAll()
    controlRisk.setOpenKonPrice(price=init_realOpenKonPrice)
    controlRisk.setOpenDuoPrice(price=init_realOpenDuoPrice)
    if init_realOpenDuoPrice is not None or init_realOpenKonPrice is not None:
        controlRisk.activeLocking()
    with open('CTA_setting.json', 'w') as json_file:
        json_file.write(
            json.dumps([{
                "name": strategy,
                "className": strategy,
                "vtSymbol": vtSymbol
            }]))
        print "################# My t_position and CTA_setting.json REFRESH! ######################"
예제 #8
0
def getZhangTingCodeConceptAnd2DB(date=fd.getLastestOpenDate()):
    soups = hg.getSoupsFromWencai(date + "日涨跌幅>=9.89;" + date +"涨停原因;按"+date+"日首次涨停时间排序")
    for soup in soups:
        eles_codes = soup.select('#resultWrap .static_con_outer .tbody_table tr td.item div.em')
        index = 0
        codes = []
        while index < eles_codes.__len__():
            o_str = eles_codes[index].text.strip()
            if (o_str.isdigit()):
                codes.append(o_str)
            index = index + 1
        eles_reason = soup.select('#resultWrap .scroll_tbody_con .tbody_table tr td[colnum="5"] div.em')
        reasons = []
        for elem in eles_reason:
            o_str = elem.text.strip()
            reasons.append(o_str)
        count = 0
        for code in codes:
            r = reasons[count]
            dao.update("delete from zhangting_concept where date=%s and code=%s", (date, code))
            dao.update("insert into zhangting_concept(code, date, concept) values(%s,%s,%s)", (code, date, r))
            count = count + 1
예제 #9
0
def crawlSecurityData_AtRear(dayCount):
    securities = fd.get_all_securities()
    max_date = dao.select("select max(date) max_date from security_data",
                          ())[0]['max_date']
    endDate = fd.getLastestOpenDate()
    if max_date is not None:
        startDate = fd.nextOpenDate(max_date, 1)
    else:
        startDate = fd.preOpenDate(endDate, dayCount)
    isFromHist = False
    if startDate > endDate: return
    for code in securities:
        count = 0
        df = ts.get_k_data(code, startDate, endDate)
        if df.index.__len__() == 0:
            isFromHist = True
            df = ts.get_hist_data(code, startDate, endDate)
        arr_values = []
        while count < df.index.__len__():
            open = str(df['open'].values[count])
            close = str(df['close'].values[count])
            high = str(df['high'].values[count])
            low = str(df['low'].values[count])
            volume = str(df['volume'].values[count])
            if isFromHist is True:
                date = df.index[count]
            else:
                date = str(df['date'].values[count])
            arr_values.append((code, date, open, close, high, low, volume))
            count = count + 1
            print("Date: " + date + " Code: " + code)

        dao.update("delete from security_data where code=%s and date=%s",
                   (code, date))
        dao.updatemany(
            "insert into security_data(code, date, open, close, high, low, volume) values(%s,%s,%s,%s,%s,%s,%s)",
            arr_values)
예제 #10
0
 def releaseAll(self):
     print '清空风控设置'
     self.realOpenKonPrice = None
     self.realOpenDuoPrice = None
     self.locking = False
     # 持久化,下次策略重载时风控对象重新初始化从数据库读取
     dao.releaseRealOpenKonPrice(security=self.security)
     dao.releaseRealOpenDuoPrice(security=self.security)
     dao.releaseLocking(security=self.security)
예제 #11
0
def caculateMarketAnd2DB():
    openDates = fd.getOpenDates()
    openDates.reverse()
    max_date = dao.select("select max(date) max_date from security_data",
                          ())[0]['max_date']
    min_date = dao.select("select min(date) min_date from security_data",
                          ())[0]['min_date']
    startDate = min_date
    endDate = max_date
    pdv = None
    for date in openDates:
        if date == '' or date > endDate or date < fd.nextOpenDate(
                startDate, 10):
            continue

        arr = dao.select(
            "select code, date, open, close, high, low, volume from "
            "security_data where date=%s", (date))

        ye_arr = dao.select(
            "select code, date, open, close, high, low, volume from "
            "security_data where date=(select max(date) from security_data where date<%s) ",
            (date))

        ty_arr = dao.select(
            "select code, date, open, close, high, low, volume from "
            "security_data where date=(select max(date) from security_data where date<%s) ",
            (fd.preOpenDate(date, 1)))

        pre_ty_arr = dao.select(
            "select code, date, open, close, high, low, volume from "
            "security_data where date=(select max(date) from security_data where date<%s) ",
            (fd.preOpenDate(date, 2)))

        code_item = {}
        code_ye_item = {}
        code_ty_item = {}
        code_pre_ty_item = {}
        for item in arr:
            code_item[item['code']] = item
        for ye_item in ye_arr:
            code_ye_item[ye_item['code']] = ye_item
        for ty_item in ty_arr:
            code_ty_item[ty_item['code']] = ty_item
        for pre_ty_item in pre_ty_arr:
            code_pre_ty_item[pre_ty_item['code']] = pre_ty_item
        yzzt_count = 0
        yzdt_count = 0
        dt = 0
        zrzt = 0

        zt_count = 0
        zt_high_count = 0
        _1bzt_count = 0
        _1bzt_high_count = 0
        _2bzt_count = 0
        _2bzt_high_count = 0
        _3bzt_count = 0
        _3bzt_high_count = 0
        _4bzt_count = 0
        _4bzt_high_count = 0
        _5bzt_count = 0
        _5bzt_high_count = 0
        _6bzt_count = 0
        _6bzt_high_count = 0
        sum_chg = 0
        ye_zt_count = 0

        for item in arr:
            code = item['code']
            # if code != '000760': continue
            try:
                ye_item = code_ye_item[code]
            except:
                _date = item['date']
                ye_items = dao.select(
                    "select code, date, open, close, high, low, volume from security_data "
                    "where code=%s and date=(select max(date) from security_data where date<%s and code=%s) ",
                    (code, _date, code))
                if ye_items is None or ye_items.__len__() == 0:
                    continue
                else:
                    ye_item = ye_items[0]
            try:
                ty_item = code_ty_item[code]
            except:
                _date = ye_item['date']
                ty_items = dao.select(
                    "select code, date, open, close, high, low, volume from security_data "
                    "where code=%s and date=(select max(date) from security_data where date<%s and code=%s) ",
                    (code, _date, code))
                if ty_items is None or ty_items.__len__() == 0: continue
                else: ty_item = ty_items[0]

            try:
                pre_ty_item = code_pre_ty_item[code]
            except:
                _date = ty_item['date']
                pre_ty_items = dao.select(
                    "select code, date, open, close, high, low, volume from security_data "
                    "where code=%s and date=(select max(date) from security_data where date<%s and code=%s) ",
                    (code, _date, code))
                if pre_ty_items is None or pre_ty_items.__len__() == 0:
                    continue
                else:
                    pre_ty_item = pre_ty_items[0]

            if (_is_yzzt(item, ye_item) == True): yzzt_count = yzzt_count + 1
            if (_is_yzdt(item, ye_item) == True): yzdt_count = yzdt_count + 1
            if (_is_dt(ye_item, ty_item) == True): dt = dt + 1
            if (_is_zrzt(ye_item, ty_item) == True): zrzt = zrzt + 1
            lb = _is_lb(code, date, item, ye_item, ty_item)
            if (lb == 6): _6bzt_count = _6bzt_count + 1
            elif (lb == 5): _5bzt_count = _5bzt_count + 1
            elif (lb == 4): _4bzt_count = _4bzt_count + 1
            elif (lb == 3): _3bzt_count = _3bzt_count + 1
            elif (lb == 2): _2bzt_count = _2bzt_count + 1
            elif (lb == 1): _1bzt_count = _1bzt_count + 1

            if is_zt(item, ye_item) == True: zt_count = zt_count + 1
            if is_high_zt(item, ye_item) == True:
                zt_high_count = zt_high_count + 1

            pre_lb = _is_ye_lb(code, date, ye_item, ty_item, pre_ty_item)

            if pre_lb == 0 and is_high_zt(item, ye_item):
                _1bzt_high_count = _1bzt_high_count + 1
            if pre_lb == 1 and is_high_zt(item, ye_item) == True:
                _2bzt_high_count = _2bzt_high_count + 1
            if pre_lb == 2 and is_high_zt(item, ye_item) == True:
                _3bzt_high_count = _3bzt_high_count + 1
            if pre_lb == 3 and is_high_zt(item, ye_item) == True:
                _4bzt_high_count = _4bzt_high_count + 1
            if pre_lb == 4 and is_high_zt(item, ye_item) == True:
                _5bzt_high_count = _5bzt_high_count + 1
            if pre_lb == 5 and is_high_zt(item, ye_item) == True:
                _6bzt_high_count = _6bzt_high_count + 1

            if is_ye_zt(ye_item, ty_item) == True:
                today_chg = get_chg(item, ye_item)
                sum_chg = sum_chg + today_chg
                ye_zt_count = ye_zt_count + 1

            print("Code: " + code + " Date: " + date)

        zt_success = None
        if zt_high_count > 0: zt_success = round((zt_count / zt_high_count), 2)
        _1bzt_success = -1
        if _1bzt_high_count > 0:
            _1bzt_success = round((_1bzt_count / _1bzt_high_count), 2)
        _2bzt_success = -1
        if _2bzt_high_count > 0:
            _2bzt_success = round((_2bzt_count / _2bzt_high_count), 2)
        _3bzt_success = -1
        if _3bzt_high_count > 0:
            _3bzt_success = round((_3bzt_count / _3bzt_high_count), 2)
        _4bzt_success = -1
        if _4bzt_high_count > 0:
            _4bzt_success = round((_4bzt_count / _4bzt_high_count), 2)
        _5bzt_success = -1
        if _5bzt_high_count > 0:
            _5bzt_success = round((_5bzt_count / _5bzt_high_count), 2)
        _6bzt_success = -1
        if _6bzt_high_count > 0:
            _6bzt_success = round((_6bzt_count / _6bzt_high_count), 2)

        today_avg_chg_when_yezt = round((sum_chg / ye_zt_count), 2)

        print('Date: ' + date + ' yzzt_count: ' + str(yzzt_count) +
              ' yzdt_count: ' + str(yzdt_count) + ' dt: ' + str(dt) +
              ' zrzt:' + str(zrzt))

        dao.update("delete from market_environment where date=%s", (date))

        if pdv is None:

            dao.update(
                "insert into market_environment(date, yzzt_count, yzdt_count, dt_count, zrzt_count, "
                "1bzt_count, 2bzt_count, 3bzt_count, 4bzt_count, 5bzt_count, 6bzt_count, "
                "1bzt_success, 2bzt_success, 3bzt_success, 4bzt_success, 5bzt_success, 6bzt_success, "
                "zt_success, today_avg_chg_when_yezt) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                (date, yzzt_count, yzdt_count, dt, zrzt, _1bzt_count,
                 _2bzt_count, _3bzt_count, _4bzt_count, _5bzt_count,
                 _6bzt_count, _1bzt_success, _2bzt_success, _3bzt_success,
                 _4bzt_success, _5bzt_success, _6bzt_success, zt_success,
                 today_avg_chg_when_yezt))
        else:

            dao.update(
                "insert into market_environment(date, yzzt_count, ye_yzzt_count, yzdt_count, ye_yzdt_count, dt_count, ye_dt_count, zrzt_count, ye_zrzt_count, "
                "1bzt_count, ye_1bzt_count, 2bzt_count, ye_2bzt_count, 3bzt_count, ye_3bzt_count, 4bzt_count, ye_4bzt_count, 5bzt_count, ye_5bzt_count, 6bzt_count, ye_6bzt_count, "
                "1bzt_success, ye_1bzt_success, 2bzt_success, ye_2bzt_success, 3bzt_success, ye_3bzt_success, 4bzt_success, ye_4bzt_success, 5bzt_success, ye_5bzt_success, 6bzt_success, ye_6bzt_success, "
                "zt_success, ye_zt_success, today_avg_chg_when_yezt, ye_today_avg_chg_when_yezt) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,"
                "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                (date, yzzt_count, pdv[1], yzdt_count, pdv[2], dt, pdv[3],
                 zrzt, pdv[4], _1bzt_count, pdv[5], _2bzt_count, pdv[6],
                 _3bzt_count, pdv[7], _4bzt_count, pdv[8], _5bzt_count, pdv[9],
                 _6bzt_count, pdv[10], _1bzt_success, pdv[11], _2bzt_success,
                 pdv[12], _3bzt_success, pdv[13], _4bzt_success, pdv[14],
                 _5bzt_success, pdv[15], _6bzt_success, pdv[16], zt_success,
                 pdv[17], today_avg_chg_when_yezt, pdv[18]))

        pdv = (date, yzzt_count, yzdt_count, dt, zrzt, _1bzt_count,
               _2bzt_count, _3bzt_count, _4bzt_count, _5bzt_count, _6bzt_count,
               _1bzt_success, _2bzt_success, _3bzt_success, _4bzt_success,
               _5bzt_success, _6bzt_success, zt_success,
               today_avg_chg_when_yezt)
예제 #12
0
def getRecord(code, date):
    ret = dao.select("select code, date, ye_chg, continuous_rise_day_count, ye_qrr, ye_tr, open_chg, close_chg, res from security_feature_record where code = %s and date = %s", (code, date))
    return ret[0]
예제 #13
0
def appendRecord(code, date, ye_chg, continuous_rise_day_count, continuous_z_day_count, ye_qrr, ye_tr, open_chg, close_chg, res):
    if isinstance(code, str) == False:
        code = code['code'].values[0]
    delRecord(code, date)
    dao.update("insert into security_feature_record(code, date, ye_chg, continuous_rise_day_count, continuous_z_day_count, ye_qrr, ye_tr, open_chg, close_chg, res) value(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
               (code, date, ye_chg, continuous_rise_day_count, continuous_z_day_count, ye_qrr, ye_tr, open_chg, close_chg, res))
예제 #14
0
def getCodeAndDateArray():
    return dao.select("select code, date from security_feature_record order by date desc", ())
예제 #15
0
def updateColume(code, date, colName, colVal):
    dao.update("update security_feature_record set " + colName + " =%s where code=%s and date=%s", (colVal, code, date))
예제 #16
0
def start(startTime=None,
          jqSecurity=None,
          frequency=None,
          enableBuy=None,
          enableShort=None):
    security = jqSecurity  #'FG9999.XZCE' 'RB9999.XSGE' 'JM9999.XDCE'
    status = Status()
    frequency = frequency
    strategyBase = MutilEMaStrategyBase(security=security,
                                        status=status,
                                        ctaTemplate=None,
                                        frequency=frequency,
                                        jqDataAccount='13268108673',
                                        jqDataPassword='******',
                                        enableTrade=False,
                                        enableBuy=enableBuy,
                                        enableShort=enableShort)
    times = util.getTimeSerial(startTime, count=1000 * 800, periodSec=12)
    for t in times:
        if strategyBase.startJudgeAndRefreshStatus(t):
            strategyBase.trade(None)


jqSecurity = 'TA8888.XZCE'
dao.updateAllPosition(3, jqSecurity)
start(jqSecurity=jqSecurity,
      startTime='2018-10-10 14:00:00',
      frequency='5m',
      enableBuy=True,
      enableShort=True)
예제 #17
0
    def controlOnTick(self, tick):

        if self.realOpenDuoPrice is not None and self.realOpenKonPrice is not None:
            smtp.notifyError('realOpenDuoPrice和realOpenKonPrice都不为空,将中止进程')
            exit()

        # 监听区域!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!##########################################
        # 持有多仓风控计算实时盈亏
        rate = None
        if self.realOpenKonPrice is not None:
            openPrice = self.realOpenKonPrice
            rate = round((openPrice - tick.lastPrice) / openPrice, 8) * 100
            print '[' + str(
                util.getYMDHMS()) + '] RiskControl realOpenKonPrice: ' + str(
                    self.realOpenDuoPrice) + ' rate: ' + str(rate)
            if rate < RiskControlRate:
                self.lockActionToken = True  # 发出放狗指令
            if self.locking is True and rate > -RiskControlRate:
                self.unlockActionToken = True  # 发出放狗指令

        # 持有空仓风控计算实时盈亏
        elif self.realOpenDuoPrice is not None:
            openPrice = self.realOpenDuoPrice
            rate = round((tick.lastPrice - openPrice) / openPrice, 8) * 100
            print '[' + str(
                util.getYMDHMS()) + '] RiskControl realOpenDuoPrice: ' + str(
                    self.realOpenDuoPrice) + ' rate: ' + str(rate)
            if rate < RiskControlRate:
                self.lockActionToken = True  # 发出放狗指令
            if self.locking is True and rate > -RiskControlRate:
                self.unlockActionToken = True  # 发出放狗指令

        #Return的话,说明还没有开仓,或者开仓时候没有设置这两个值
        if self.realOpenDuoPrice is None and self.realOpenKonPrice is None:
            return

        # 动作执行区域!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!##########################################
        # 锁动作执行
        if self.lockActionToken is True and self.locking is False:
            if self.realOpenKonPrice is not None:
                if self.ctaEngine is not None:
                    self.ctaEngine.cover(
                        tick.upperLimit * 0.995, int32(self.maxPosition)
                    )  # 平空!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    smtp.notifyLockKon(security=self.security)

            if self.realOpenDuoPrice is not None:
                if self.ctaEngine is not None:
                    self.ctaEngine.sell(
                        tick.lowerLimit * 1.005, int32(self.maxPosition)
                    )  # 平多!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    smtp.notifyLockDuo(security=self.security)

            self.locking = True
            # 持久化,下次策略重载时风控对象重新初始化从数据库读取
            dao.activeLocking(security=self.security)
            self.lockActionToken = False

        # 解锁动作执行
        if self.unlockActionToken is True and self.locking is True:
            if self.realOpenKonPrice is not None:
                if self.ctaEngine is not None:
                    smtp.notifyUnLockKon(security=self.security)

            if self.realOpenDuoPrice is not None:
                if self.ctaEngine is not None:
                    smtp.notifyUnLockDuo(security=self.security)

            self.locking = False
            # 持久化,下次策略重载时风控对象重新初始化从数据库读取
            dao.releaseLocking(security=self.security)
            self.unlockActionToken = False
예제 #18
0
 def setOpenKonPrice(self, price):
     print '设置realOpenKonPrice:' + str(price)
     self.realOpenKonPrice = price
     # 持久化,下次策略重载时风控对象重新初始化从数据库读取
     dao.setRealOpenKonPrice(security=self.security, price=price)
예제 #19
0
 def activeLocking(self):
     self.locking = True
     dao.activeLocking(security=self.security)
예제 #20
0
          jqSecurity=None,
          frequency=None,
          enableBuy=None,
          enableShort=None):
    security = jqSecurity  #'FG9999.XZCE' 'RB9999.XSGE' 'JM9999.XDCE'
    status = Status()
    frequency = frequency
    strategyBase = MutilEMaStrategyBase(security=security,
                                        status=status,
                                        ctaTemplate=None,
                                        frequency=frequency,
                                        jqDataAccount='13268108673',
                                        jqDataPassword='******',
                                        pricePosi_top=0,
                                        pricePosi_bottom=4,
                                        enableTrade=False,
                                        enableBuy=enableBuy,
                                        enableShort=enableShort)
    times = util.getTimeSerial(startTime, count=1000 * 800, periodSec=12)
    for t in times:
        if strategyBase.startJudgeAndRefreshStatus(t):
            strategyBase.trade(None)


jqSecurity = 'RB9999.XSGE'
dao.updateAllPosition(duo=0, kon=0, max=1, security=jqSecurity)
start(jqSecurity=jqSecurity,
      startTime='2018-12-12 13:45:00',
      frequency='5m',
      enableBuy=True,
      enableShort=True)
예제 #21
0
def delRecord(code, date):
    dao.update("delete from security_feature_record where code = %s and date = %s", (code, date))