示例#1
0
    def closeShort(self, msg, count=basecount):

        bs, ss = getDepth()
        ss = ss[::-1]
        print bs
        print ss
        price = 0.0

        counttmp = 0

        n = 0
        while True:
            n -= 1
            counttmp += ss[n][1]
            if counttmp >= count:
                price = ss[-n][0]
                break
            if n < -5:
                price = bs[-5][0]
                break
        strtime = str(timetool.getNowDate())
        oustr = 'closeShort_%.4f_%d,%s,%s\n' % (price, count, strtime, msg)
        print oustr
        f = open(self.savepth, 'a')
        f.write(oustr)
        f.close()
        self.isOpenShort = False  #closlong
示例#2
0
def closeShortTrade(msg, count=basecount):
    bs, ss = getDepth()
    print bs
    print ss
    price = 0.0

    counttmp = 0

    n = 0
    while True:
        n -= 1
        counttmp += ss[n][1]
        if counttmp >= count:
            price = ss[-n][0]
            break
        if n < -5:
            price = bs[-5][0]
            break
    strtime = str(timetool.getNowDate())
    oustr = 'closeShort_%.4f_%d,%s,%s\n' % (price, count, strtime, msg)
    print oustr
    f = open(savepth, 'a')
    f.write(oustr)
    f.close()
    tradetool.isOpenShort = False
    tradetool.openIndex = -1
    cmd = 'say 平空操作'
    os.system(cmd)
示例#3
0
def openShort(count=basecount):
    bs, ss = getDepth()
    price = 0.0
    counttmp = 0

    n = 0
    while True:
        n -= 1
        counttmp += bs[n][1]
        if counttmp >= count:
            price = bs[-n][0]
            break
        if n < -5:
            price = bs[-5][0]
            break
    strtime = str(timetool.getNowDate())
    oustr = 'openShort_%.4f_%d,%s\n' % (price, count, strtime)
    print oustr
    f = open(savepth, 'a')
    f.write(oustr)
    f.close()
    tradetool.isOpenShort = True
    tradetool.openIndex = 0
    cmd = 'say 开空操作'
    os.system(cmd)
示例#4
0
def getTreadeType():
    k1d = get1minKline()
    # isUP = isClose(k1d)
    if not k1d:
        return

    dif, dea, macd = get_MACD(k1d)
    outstr = ''
    tp = 0
    s = -2
    e = -1
    if dea[-1] <= 0:  #0轴以下
        if macd[s] >= 0 and macd[e] < 0:
            outstr = '零轴以下死叉'
            cmd = 'say %s' % (outstr)
            os.system(cmd)
            tradetool.isOpenShort = True
        elif macd[s] <= 0 and macd[e] > 0:
            outstr = '零轴以下金叉'
            cmd = 'say %s' % (outstr)
            os.system(cmd)
            tradetool.isOpenLong = True
        else:
            outstr = '零轴以下'
            print outstr
    elif dea[-1] >= 0:  #0轴以上
        if macd[s] >= 0 and macd[e] < 0:
            outstr = '零轴以上死叉'
            cmd = 'say %s' % (outstr)
            os.system(cmd)
            tradetool.isOpenShort = True
        elif macd[s] <= 0 and macd[e] > 0:
            outstr = '零轴以上金叉'
            cmd = 'say %s' % (outstr)
            os.system(cmd)
            tradetool.isOpenLong = True
        else:
            outstr = '零轴以上'
            print outstr

    #         openShort()

    outstr = outstr + '%.4f' % (dea[-1])
    print outstr
    print timetool.getNowDate(k1d[-1][0] / 1000)
def get1minKline():
    turl = 'https://www.okex.com/api/v1/future_kline.do?symbol=ltc_usd&type=1min&contract_type=quarter&size=300'
    try:
        data = urltool.getUrl(turl)
        ddic = json.loads(data)
        print len(ddic)
        return ddic
    except Exception as e:
        print '获取数据错误,%s' % (str(timetool.getNowDate()))
        return None
示例#6
0
def test():
    koutdatas = readout5Data()
    dlen = len(koutdatas)
    klinedats = read5MimKline()[-dlen:]
    
    print len(klinedats),len(koutdatas)

    maxy = [None,None]
    miny = [None,None]
    maxx = [None,None]
    minx = [None,None]

    max_xy = [None,None]
    min_xy = [None,None]
    max_xy_ = [None,None]
    min_xy_ = [None,None]

    ym = 0
    ys = 1000
    xm = 0
    xs = 1000
    lm = 0
    ls = 10000
    for n in range(len(koutdatas)):
        d = koutdatas[n]
        k = klinedats[n]
        if d[0] > xm:
            xm = d[0]
            maxx[0] = d
            maxx[1] = k
        if d[0] < xs:
            xs = d[0]
            minx[0] = d
            minx[1] = k
        if d[1] > ym:
            ym = d[1]
            maxy[0] = d
            maxy[1] = k
        if d[1] < ys:
            ys = d[1]
            miny[0] = d
            miny[1] = k
        lth = getLeath(d[0], d[1])
        if lth > lm:
            lm = lth
            max_xy[0] = d
            max_xy[1] = k
        if lth < ls:
            min_xy[0] = d
            min_xy[1] = k

    print 'minx:',minx,timetool.getNowDate(int(minx[1][0])/1000)
    print 'maxx:',maxx,timetool.getNowDate(int(maxx[1][0])/1000)
    print 'miny:',miny,timetool.getNowDate(int(miny[1][0])/1000)
    print 'maxy:',maxy,timetool.getNowDate(int(maxy[1][0])/1000)
    print 'min_xy:',min_xy,timetool.getNowDate(int(min_xy[1][0])/1000)
    print 'max_xy:',max_xy,timetool.getNowDate(int(max_xy[1][0])/1000)
def closeLong(msg, count=basecount):

    bs, ss = getDepth()
    price = 0.0
    counttmp = 0

    n = 0
    while True:
        n -= 1
        counttmp += bs[n][1]
        if counttmp >= count:
            price = bs[-n][0]
            break
        if n < -5:
            price = bs[-5][0]
            break
    strtime = str(timetool.getNowDate())
    oustr = 'closeLong_%.4f_%d,%s,%s\n' % (price, count, strtime, msg)
    print oustr
    f = open(savepth, 'a')
    f.write(oustr)
    f.close()
    tradetool.isOpenLong = False  #closlong
示例#8
0
    def openLong(self, count=basecount):

        bs, ss = getDepth()
        ss = ss[::-1]
        price = 0.0
        counttmp = 0

        n = 0
        while True:
            n -= 1
            counttmp += ss[n][1]
            if counttmp >= count:
                price = ss[-n][0]
                break
            if n < -5:
                price = bs[-5][0]
                break
        strtime = str(timetool.getNowDate())
        oustr = 'openLong_%.4f_%d,%s\n' % (price, count, strtime)
        print oustr
        f = open(self.savepth, 'a')
        f.write(oustr)
        f.close()
        self.isOpenLong = True  #openlong
示例#9
0
def conventDataForMTCL():
    koutdatas = readout5Data()
    dlen = len(koutdatas)
    klinedats = read5MimKline()[-dlen:]
    
    print len(klinedats),len(koutdatas)

    ndatas = []

    for n in range(len(koutdatas)):
        d = koutdatas[n]
        k = klinedats[n]
        ttime = timetool.getNowDate(int(k[0])/1000)
        #数据状态分配方法,(x + 2000) * 10000 + (y + 2000)
        # ds = int(((d[0]/10) + 200) * 1000 + ((d[1]/10) + 200)) #数据量太少,获得相同状态过少
        # ds = int(((d[0]/20) + 100) * 1000 + ((d[1]/20) + 100)) #数据量太少
        ds = int(((d[0]/50) + 50) * 500 + ((d[1]/50) + 50))
        tmpd = [ds,d,k,str(ttime)]
        ndatas.append(tmpd)

    jsonpth = 'data/nnout/allout.json'
    txtpth = 'data/nnout/allout.txt'
    saveListWithJson(ndatas, jsonpth)
    saveListWithLineTxt(ndatas, txtpth)
示例#10
0
def test():
    # openLong()
    print timetool.getNowDate()