Exemplo n.º 1
0
def notify10min():
    # --------------------------------------------------------------------------------------------------------------------------------------------
    items = dao.select(
        "select f_code, f_name, f_price, f_pre_close, f_createtime from t_future_tick where"
        " f_createtime > date_add(now(), interval - 10 minute) order by f_createtime desc",
        ())
    code_items_rel = {}
    for item in items:
        code = item['f_code']
        if code not in code_items_rel.keys():
            code_items_rel.setdefault(code, [item])
        else:
            code_items_rel[code].append(item)

    for code in code_items_rel.keys():
        items = code_items_rel[code]
        if items.__len__() < 2:
            continue
        lastest = items[0]
        pre_close = float(lastest['f_pre_close'])
        price = float(lastest['f_price'])
        rate = round((price - pre_close) / pre_close * 100, 2)
        speed = getRateBetweenMaxAndMin_Speed(items)

        if speed < -0.7:
            # Ôٴη¢ËÍ֪ͨµÄCDʱ¼ä
            if code in coolDown_10min.keys():
                now = util.getYMDHMS()
                coolDown_10min_starttime = coolDown_10min[code]
                durSec = util.timeDur_ReturnSec(coolDown_10min_starttime, now)
                if durSec < 60 * 30:
                    return
                else:
                    coolDown_10min.pop(code)
            # ·¢ËÍ֪ͨ
            log.log("Send Notification: " + code + " speed: " + str(speed))
            url = 'http://' + SmtpClient_Host + ':' + str(
                SmtpClient_Port
            ) + '/smtpclient/sendFuture/(Rate: ' + str(rate) + ' Speed: ' + str(
                speed
            ) + ')This is ' + code + '/This is ' + code + '/[email protected]'

            #util.Async_req(url).start()
            dao.update(
                "insert into t_future_unusual_action(f_code, f_name, f_speed, f_rate, f_createtime)"
                " values(%s,%s,%s,%s,%s)",
                (code, code_name_rel[code], speed, rate, util.getYMDHMS()))
            coolDown_10min.setdefault(code, util.getYMDHMS())
Exemplo n.º 2
0
def notifyCloseKon(security, currentTimeString=None):
    if currentTimeString is None:
        currentTimeString = util.getYMDHMS()
    a = '<a href="http://107.182.31.161:5288/">查看行情</a>'
    sendEmail(subject='[' + str(currentTimeString) + '] Kon平_' +
              util.futureName(security),
              content='' + a)
Exemplo n.º 3
0
def notifyUnLockDuo(security):
    security = util.futureName(security)
    currentTimeString = util.getYMDHMS()
    a = '<a href="http://107.182.31.161:5288/">查看行情</a>'
    sendEmail(subject='[' + str(currentTimeString) + '] 解锁多(重新开多仓)_' +
              security,
              content='' + a)
Exemplo n.º 4
0
def log(content):
    string = "[Time: " + util.getYMDHMS() + "]: " + str(content)
    print(string)
    file = open("log.out", "a")
    file.write(string + "\n")
    file.close()
    return string
Exemplo n.º 5
0
def notifyVolumeUnusual(security, volumeArrowCount=0):
    currentTimeString = util.getYMDHMS()
    content = '<div style="padding: 10px">' \
            '<a href="http://107.182.31.161:5288/candle_sticks?security='+security+'" style="font-weight: bold;">查看走势</a>' \
        '</div>'
    sendEmail(subject='[' + str(currentTimeString) + '] 成交量大增:' +
              str(volumeArrowCount) + '_' + util.futureName(security),
              content='' + content)
Exemplo n.º 6
0
def notifyTrade(security, nowRate="?"):
    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) + '] 触发交易动作_' +
              util.futureName(security),
              content='rate: ' + nowRate + ' duo: ' + duo + ' kon: ' + kon +
              ' max: ' + max)
Exemplo n.º 7
0
def pushPosition(position):
    o = {
        'available': True,
        'position': position,
        'createtime': util.getYMDHMS()
    }
    position_flow = util.getProperty('position_flow')
    if position_flow is None:
        util.setProperty('position_flow', [o])
    else:
        position_flow.append(o)
        util.removeProperty('position_flow')
        util.setProperty('position_flow', position_flow)
Exemplo n.º 8
0
def listen():
    while True:
        if util.isOpenTime_wide() is False:
            time.sleep(10)
            continue
        url = getUrl(code_name_rel.keys())
        ctn = requests.get(url).text
        strs = ctn.split("\n")
        values = []
        count = 0
        for line in strs:
            if line == '': continue
            try:
                code = line[line.index("str_") + 4:line.index('=') - 1].upper()
            except:
                continue
            if util.isOpenTime_Kind(code) is False:
                continue
            if '"' not in line: continue
            line = line[line.index('"') + 1:line.rindex('"')]
            if line.__len__() == 0: continue
            cols = line.split(",")
            name = cols[0]
            pre_close = float(cols[5])
            price = float(cols[8])
            position = float(cols[13])
            settlement_price = float(cols[9])
            date = cols[17]
            log.log("Ãû³Æ£º" + name + " ×òÊÕ£º" + str(pre_close) + " ÏÖ¼Û£º" +
                    str(price) + " ÊÕÅ̼ۣº" +
                    str(round((price - pre_close) / pre_close * 100, 2)))
            values.append((code, name, date, price, pre_close, position,
                           settlement_price, util.getHMS(), util.getYMDHMS()))
            count = count + 1
        dao.updatemany(
            "insert into"
            " t_future_tick(f_code, f_name, f_date, f_price, f_pre_close,"
            " f_position, f_settlement_price, f_time, f_createtime)"
            " values(%s,%s,%s,%s,%s,%s,%s,%s,%s)", values)

        notify5min()
        notify10min()
        notify15min()
        print("loop next need sleep")
        time.sleep(25)
Exemplo n.º 9
0
def notifyError(content):
    currentTimeString = util.getYMDHMS()
    sendEmail(subject='[' + str(currentTimeString) + '] 错误:' + content,
              content=str(content))