예제 #1
0
def tactics2(operationType):
    try:
        print(misc.getTimeStr())
        ma5Value, closeValue, fatherMa5Slope = getMa5AndCloseAndFatherMa5Slope(
        )
        operation, orderId = isBuyOrSellByMa5ValueAndCloseValue(
            operationType, ma5Value, closeValue, fatherMa5Slope)
        misc.setConfigKeyValue('config.ini', symbolValue, 'type', operation)
        if orderId:
            time.sleep(30)
            if operation == 'sell':
                tempOrder = getOrderInfo(orderId)
                fieldCashAmount = float(tempOrder['field-cash-amount'])
                fieldFees = float(tempOrder['field-fees'])
                usdt = getFloatStr(str(fieldCashAmount - fieldFees))
                misc.setConfigKeyValue('config.ini', symbolValue, 'usdt', usdt)
            orderInfo = getMatchResults()[0]
            print(orderInfo)
            content = '<html>'
            content += '<p>symbol(交易对)=%s</p>' % orderInfo['symbol']
            content += '<p>filled-amount(订单数量)=%s</p>' % orderInfo[
                'filled-amount']
            content += '<p>filled-fees(已成交手续费)=%s</p>' % orderInfo[
                'filled-fees']
            content += '<p>price(成交价格)=%s</p>' % orderInfo['price']
            content += '<p>type(订单类型(buy-market:市价买, sell-market:市价卖))=%s</p>' % orderInfo[
                'type']
            content += '<p>%s</p>' % str(orderInfo)
            content += '</html>'
            misc.sendEmail(mailHost, mailUser, mailPass, receivers, '交易报告',
                           content)
    except Exception as e:
        print(e)
예제 #2
0
def tactics1(operationType):
    print(misc.getTimeStr())
    periodStr = '30min'
    kLine = getKLine(periodStr, '15')
    smallMa = getMa(kLine, 3)
    bigMa = getMa(kLine, 14)
    checkCross(operationType, kLine[0], smallMa, bigMa)
    operation, orderId = checkSignal()
    if orderId:
        misc.setConfigKeyValue('config.ini', symbolValue, 'type', operation)
        global buySignal
        buySignal = 0
        global sellSignal
        sellSignal = 0
        time.sleep(10)
        if operation == 'sell':
            tempOrder = getOrderInfo(orderId)
            fieldCashAmount = float(tempOrder['field-cash-amount'])
            fieldFees = float(tempOrder['field-fees'])
            usdt = getFloatStr(str(fieldCashAmount - fieldFees))
            misc.setConfigKeyValue('config.ini', symbolValue, 'usdt', usdt)
        orderInfo = getMatchResults()[0]
        print(orderInfo)
        content = '<html>'
        content += '<p>symbol(交易对)=%s</p>' % orderInfo['symbol']
        content += '<p>type(订单类型)=%s</p>' % orderInfo['type']
        content += '<p>price(成交价格)=%s</p>' % orderInfo['price']
        content += '<p>filled-amount(订单数量)=%s</p>' % orderInfo['filled-amount']
        content += '<p>filled-fees(已成交手续费)=%s</p>' % orderInfo['filled-fees']
        content += '<p>%s</p>' % str(orderInfo)
        content += '</html>'
        misc.sendEmail(mailHost, mailUser, mailPass, receivers, '交易报告',
                       content)
예제 #3
0
def tactics1(operationType):
    #try:
    print(misc.getTimeStr())
    #获取均线斜率
    period='60min'
    ma4LastSlope = getLastMASlope(period,4)[0]
    ma11LastSlope = getLastMASlope(period,11)[0]
    ma2LastSlope = getLastMASlope(period,2)[0]
    ma3LastSlope = getLastMASlope(period,3)[0]
    ma5LastSlope = getLastMASlope(period,5)[0]
    lastClose = getLastClose(period)
    price=getLastBuyOrderPrice()
    print('ma2=',ma2LastSlope,'\tma3=',ma3LastSlope,'\tma4=',ma4LastSlope,'\tlastClose=',lastClose,'\tprice=',price)
    checkOperation(operationType,ma4LastSlope,ma11LastSlope,ma2LastSlope,ma3LastSlope,ma5LastSlope,lastClose,price)
    operation,orderId=checkSignal()
    if orderId:
        misc.setConfigKeyValue('config.ini',symbolValue,'type',operation)
        global buySignal
        buySignal=0
        global sellSignal
        sellSignal=0
        time.sleep(10)
        if operation == 'sell':
            tempOrder=getOrderInfo(orderId)
            fieldCashAmount=float(tempOrder['field-cash-amount'])
            fieldFees=float(tempOrder['field-fees'])
            usdt=getFloatStr(str(fieldCashAmount-fieldFees))
            misc.setConfigKeyValue('config.ini',symbolValue,'usdt',usdt)
        orderInfo=getMatchResults()[0]
        print(orderInfo)
        content='<html>'
        content+='<p>symbol(交易对)=%s</p>' % orderInfo['symbol']
        content+='<p>filled-amount(订单数量)=%s</p>' % orderInfo['filled-amount']
        content+='<p>filled-fees(已成交手续费)=%s</p>' % orderInfo['filled-fees']
        content+='<p>price(成交价格)=%s</p>' % orderInfo['price']
        content+='<p>type(订单类型(buy-market:市价买, sell-market:市价卖))=%s</p>' % orderInfo['type']
        content+='<p>%s</p>' % str(orderInfo)
        content+='</html>'
        misc.sendEmail(mailHost, mailUser, mailPass, receivers, '交易报告', content)
예제 #4
0
def main(symbol_value):
    print(misc.getTimeStr())
    print(symbol_value)
    operationType = misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'type')
    buy_signal = int(misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'buy_signal'))
    sell_signal = int(misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'sell_signal'))
    buy_signal_max = int(misc.getConfigKeyValueByKeyName('config.ini', 'config', 'buy_signal_max'))
    sell_signal_max = int(misc.getConfigKeyValueByKeyName('config.ini', 'config', 'sell_signal_max'))
    condition = operationType == 'sell'
    order_id = None
    if condition:#买入判断
        condition1, condition2, condition3 = get_buy_condition(symbol_value)
        if condition1 and condition2 and condition3:
            print('买入信号+1')
            buy_signal = buy_signal + 1
            print('buy_signal = %s' % buy_signal)
            misc.setConfigKeyValue('config.ini', symbol_value, 'buy_signal', buy_signal)
        else:
            misc.setConfigKeyValue('config.ini', symbol_value, 'buy_signal', 0)
    else:#卖出判断
        condition = get_sell_condition(symbol_value)
        if condition:
            print('卖出信号+1')
            sell_signal = sell_signal + 1
            print('sell_signal = %s' % sell_signal)
            misc.setConfigKeyValue('config.ini', symbol_value, 'sell_signal', sell_signal)
        else:
            misc.setConfigKeyValue('config.ini', symbol_value, 'sell_signal', 0)

    if buy_signal >= buy_signal_max:
        #买入操作
        amount = misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'money_value')
        #amount = api.get_balance(account_id, money_name)
        order_id = api.do_place(account_id, amount, symbol_value, 'buy-market')
        misc.setConfigKeyValue('config.ini', symbol_value, 'buy_signal', 0)
        
    if sell_signal >= sell_signal_max:
        #卖出操作
        coin_name = misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'coin_name')
        amount = api.get_balance(account_id, coin_name)
        if coin_name == 'knc' or coin_name == 'qsp':
            amount = misc.get_float_str(amount,0)
        order_id = api.do_place(account_id, amount, symbol_value, 'sell-market')
        misc.setConfigKeyValue('config.ini', symbol_value, 'sell_signal', 0)
        
    if order_id:
        time.sleep(2)
        order_detail = api.get_order_detail(order_id)[0]
        if order_detail['type'] == 'buy-market':
            misc.setConfigKeyValue('config.ini', symbol_value, 'type', 'buy')
            misc.setConfigKeyValue('config.ini', symbol_value, 'price_buy', order_detail['price'])
            misc.setConfigKeyValue('config.ini', symbol_value, 'price_max', order_detail['price'])
            coin_value = misc.get_float_str(str(float(order_detail['filled-amount']) - float(order_detail['filled-fees'])))
            misc.setConfigKeyValue('config.ini', symbol_value, 'coin_value', coin_value)
        if order_detail['type'] == 'sell-market':
            order_info = api.get_order_info(order_id)
            misc.setConfigKeyValue('config.ini', symbol_value, 'type', 'sell')
            misc.setConfigKeyValue('config.ini', symbol_value, 'price_sell', order_detail['price'])
            money_value = misc.get_float_str(str(float(order_info['field-cash-amount']) - float(order_info['field-fees'])),6)
            misc.setConfigKeyValue('config.ini', symbol_value, 'money_value', money_value)
        '''
예제 #5
0
파일: ma_main.py 프로젝트: sz547073165/huo
def main():
    print(misc.getTimeStr())

    condition1, condition2, condition3, condition4, condition5, condition6, condition7, condition8 = get_condition(
    )
    order_id = None

    global buy_signal
    global sell_signal
    if condition1 and condition2 and (
        (condition3 and condition4) or
        (not condition4 and condition5 and condition7)) and condition6:
        print('买入信号+1')
        buy_signal = buy_signal + 1
    else:
        buy_signal = 0

    if not condition1 and not condition2 and not condition6:  #(condition4 or (not condition4 and not condition5)):
        print('卖出信号+1')
        sell_signal = sell_signal + 1
    else:
        sell_signal = 0

    if buy_signal >= buy_signal_max:
        #买入操作
        #amount = misc.getConfigKeyValueByKeyName('config.ini', symbol_value, 'usdt')
        amount = api.get_balance(account_id, money_name)
        order_id = api.do_place(account_id, amount, symbol_value, 'buy-market')
        buy_signal = 0

    if sell_signal >= sell_signal_max:
        #卖出操作
        amount = api.get_balance(account_id, coin_name)
        order_id = api.do_place(account_id, amount, symbol_value,
                                'sell-market')
        sell_signal = 0

    if order_id:
        time.sleep(10)
        order_detail = api.get_order_detail(order_id)[0]
        if order_detail['type'] == 'buy-market':
            misc.setConfigKeyValue('config.ini', symbol_value, 'type', 'buy')
            misc.setConfigKeyValue('config.ini', symbol_value, 'price_buy',
                                   order_detail['price'])
        if order_detail['type'] == 'sell-market':
            misc.setConfigKeyValue('config.ini', symbol_value, 'type', 'sell')
            misc.setConfigKeyValue('config.ini', symbol_value, 'price_sell',
                                   order_detail['price'])
        content = '<html>'
        if order_detail['type'] == 'sell-market':
            price_buy = float(
                misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                                'price_buy'))
            price_sell = float(
                misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                                'price_sell'))
            content += '<p>盈亏=%.4f%%</p>' % (
                (price_sell / price_buy - 1 - 0.005) * 100)
        content += '<p>created-at(交易时间)=%s</p>' % misc.getTimeStrWithUnixTimestamp(
            int(order_detail['created-at'] / 1000))
        content += '<p>symbol(交易对)=%s</p>' % order_detail['symbol']
        content += '<p>price(成交价格)=%s</p>' % order_detail['price']
        #content+='<p>filled-amount(订单数量)=%s</p>' % order_detail['filled-amount']
        #content+='<p>filled-fees(已成交手续费)=%s</p>' % order_detail['filled-fees']
        content += '<p>type(订单类型(buy-market:市价买, sell-market:市价卖))=%s</p>' % order_detail[
            'type']
        content += '<p>%s</p>' % str(order_detail)
        content += '<p>1-最后一次操作为卖出 = %s</p>' % condition1
        content += '<p>2-市价高于均线 = %s</p>' % condition2
        content += '<p>3-斜率之和大于0 = %s</p>' % condition3
        content += '<p>4-波动幅度足够大 = %s</p>' % condition4
        content += '<p>5-后半段斜率之和大于前半段三斜率之和 = %s</p>' % condition5
        content += '<p>7-后半段斜率之和大于0 = %s</p>' % condition7
        content += '<p>6-是否阳线 = %s</p>' % condition6
        content += '<p>condition1 and condition2 and ((condition3 and condition4) or (not condition4 and condition5 and condition7)) and condition6</p>'
        content += '<p>not condition1 and not condition2 and not condition6</p>'
        content += '</html>'
        misc.sendEmail(mail_host, mail_user, mail_pass, receivers,
                       '%s_%s_交易报告' % (symbol_value, order_detail['type']),
                       content)
예제 #6
0
def main(symbol_value):
    print(misc.getTimeStr())
    print(symbol_value)
    operationType = misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                                    'type')
    buy_signal = int(
        misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                        'buy_signal'))
    sell_signal = int(
        misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                        'sell_signal'))
    buy_signal_max = int(
        misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                        'buy_signal_max'))
    sell_signal_max = int(
        misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                        'sell_signal_max'))
    condition = operationType == 'sell'
    order_id = None
    if condition:  #买入判断
        k_line_1_id, ma_line, slope_list, condition1, condition2, condition3 = get_buy_condition(
            symbol_value)
        if condition1 and condition2 and condition3:
            print('买入信号+1')
            buy_signal = buy_signal + 1
            misc.setConfigKeyValue('config.ini', symbol_value, 'buy_signal',
                                   buy_signal)
        else:
            buy_signal = 0
            misc.setConfigKeyValue('config.ini', symbol_value, 'buy_signal',
                                   buy_signal)
    else:  #卖出判断
        condition = get_sell_condition(symbol_value)
        if condition:
            print('卖出信号+1')
            sell_signal = sell_signal + 1
            misc.setConfigKeyValue('config.ini', symbol_value, 'sell_signal',
                                   sell_signal)
        else:
            sell_signal = 0
            misc.setConfigKeyValue('config.ini', symbol_value, 'sell_signal',
                                   sell_signal)

    if buy_signal >= buy_signal_max:
        #买入操作
        amount = misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                                 'money_value')
        #amount = api.get_balance(account_id, money_name)
        order_id = api.do_place(account_id, amount, symbol_value, 'buy-market')
        buy_signal = 0
        misc.setConfigKeyValue('config.ini', symbol_value, 'buy_signal',
                               buy_signal)

    if sell_signal >= sell_signal_max:
        #卖出操作
        coin_name = misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                                    'coin_name')
        amount = api.get_balance(account_id, coin_name)
        order_id = api.do_place(account_id, amount, symbol_value,
                                'sell-market')
        sell_signal = 0
        misc.setConfigKeyValue('config.ini', symbol_value, 'sell_signal',
                               sell_signal)

    if order_id:
        time.sleep(2)
        order_detail = api.get_order_detail(order_id)[0]
        if order_detail['type'] == 'buy-market':
            misc.setConfigKeyValue('config.ini', symbol_value, 'type', 'buy')
            misc.setConfigKeyValue('config.ini', symbol_value, 'price_buy',
                                   order_detail['price'])
            misc.setConfigKeyValue(
                'config.ini', symbol_value, 'b_value',
                float(order_detail['price']) - ma_line[0] + ma_line[1])
            misc.setConfigKeyValue('config.ini', symbol_value, 'k_value',
                                   ma_line[0] - ma_line[1])
            misc.setConfigKeyValue('config.ini', symbol_value, 'k_line_time',
                                   k_line_1_id)
            coin_value = misc.get_float_str(
                str(
                    float(order_detail['filled-amount']) -
                    float(order_detail['filled-fees'])))
            misc.setConfigKeyValue('config.ini', symbol_value, 'coin_value',
                                   coin_value)
        if order_detail['type'] == 'sell-market':
            misc.setConfigKeyValue('config.ini', symbol_value, 'type', 'sell')
            misc.setConfigKeyValue('config.ini', symbol_value, 'price_sell',
                                   order_detail['price'])
            money_value = misc.get_float_str(
                str(
                    float(order_detail['filled-amount']) -
                    float(order_detail['filled-fees'])))
            misc.setConfigKeyValue('config.ini', symbol_value, 'money_value',
                                   money_value)
        content = '<html>'
        if order_detail['type'] == 'sell-market':
            price_buy = float(
                misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                                'price_buy'))
            price_sell = float(
                misc.getConfigKeyValueByKeyName('config.ini', symbol_value,
                                                'price_sell'))
            content += '<p>盈亏=%.4f%%</p>' % (
                (price_sell / price_buy - 1 - 0.005) * 100)
        content += '<p>created-at(交易时间)=%s</p>' % misc.getTimeStrWithUnixTimestamp(
            int(order_detail['created-at'] / 1000))
        content += '<p>symbol(交易对)=%s</p>' % order_detail['symbol']
        content += '<p>price(成交价格)=%s</p>' % order_detail['price']
        #content+='<p>filled-amount(订单数量)=%s</p>' % order_detail['filled-amount']
        #content+='<p>filled-fees(已成交手续费)=%s</p>' % order_detail['filled-fees']
        content += '<p>type(订单类型)=%s</p>' % order_detail['type']
        content += '<p>%s</p>' % str(order_detail)
        content += '</html>'
        misc.sendEmail(
            mail_host, mail_user, mail_pass, receivers,
            '%s_%s_transaction_report' % (symbol_value, order_detail['type']),
            content)
예제 #7
0
def runTestCases(caseList):
  t0 = time.time()
  
  logPath = env.getValue('logPath')
  if logPath is None:
    logPath = '.'

  logName = env.getValue('logName')
  if logName:
    logName = os.path.join(logPath, logName)
  else:
    logName = os.path.join(logPath, '%s_%s' % (misc.testSuiteName, misc.getTimeStr()))

  if not misc.makeDirs(logName):
    return

  misc.removeFile(logName + '.txt')
  log.open(logName + '.txt', log = 'suite', enableConsole = False)

  nodeList = env.getNodeList(10000, respectLimit = True) # Get as many as we can
  nodesAvail = len(nodeList)

  nodes.setStatus(nodeList, '%s: preparing' % misc.testSuiteName)

  result = {True: 0, False: 0}

  # Extract all required info from cases and build all images
  extList = expandCaseList(caseList, nodesAvail)
  cache.init()
  
  t1 = time.time()
#  buildImagesForTestSuite(extList)
  buildTime = time.time() - t1
  cache.sync()

  # Remove cases without all required images built
  workList = []
  fullSet = []
  for caseName, connParameters, variables in extList:
    workList += [(caseName, connParameters, variables)]
    fullSet = misc.clists([fullSet, [par for conn, par in connParameters.iteritems()]])

  nodesNeeded = len(fullSet)

  if nodesAvail < nodesNeeded:
    log.write('Info: for maximum performance %d nodes required (%d nodes available)' %
      (nodesNeeded, nodesAvail), log = 'suite')
  else:
    log.write('Info: %d nodes will be used' % nodesNeeded, log = 'suite')
    nodesAvail = nodesNeeded
  
  # Group all scripts to optimize upload strategy
  groups = groupCases(workList, nodesAvail)
  log.write('Info: %d uploads will be performed' % len(groups), log = 'suite')
  
  
  # Upload and execute scripts
  nodeList = nodeList[:nodesAvail]
  allNodes = []
  log.write('Test will use next nodes:', log = 'suite')
  for node in nodeList:
    log.write('  %s' % node, log = 'suite')
    allNodes += [misc.__nodeFactory.create(node)]

  #for node in allNodes:
  #  node.getConnection().setTesterMode(misc.runOn['tester'])

  testCaseExecTimes = []
  uploadTimes = []
  nodes.restart(allNodes, leaveOff = True)
  groupNo = 1

  for group in groups:
    log.write('Running group %d of %d' % (groupNo, len(groups)), log = 'suite')
    t2 = time.time()
    usedNodes = uploadNodesFromGroup(allNodes, workList, group)
    uploadTimes.append(time.time() - t2)
    time.sleep(1)
    for index in group:
      t3 = time.time()
      ret = runCaseFromGroup(workList[index], usedNodes, logName)
      testCaseExecTimes.append(time.time() - t3)
      result[ret] += 1
    groupNo += 1

  if len(uploadTimes):
    meanUploadTime = sum(uploadTimes) / len(uploadTimes)
  else:
    meanUploadTime = 0

  if len(testCaseExecTimes):
    meanTestcaseExecTime = sum(testCaseExecTimes) / len(testCaseExecTimes)
  else:
    meanTestcaseExecTime = 0

  totalTime = time.time() - t0
  
  log.write('Test finished: %d passed, %d failed' % (result[True], result[False]), log = 'suite')
  log.write('Execution time statistics', log = 'suite')
  log.write('Build images time: %d sec' % buildTime, log = 'suite')
  log.write('Total upload time: %d sec' % sum(uploadTimes), log = 'suite')
  log.write('Mean group upload time: %d sec' % meanUploadTime, log = 'suite')
  log.write('Testcases execution time: %d sec' % sum(testCaseExecTimes), log = 'suite')
  log.write('Mean testcase execution time: %d sec' % meanTestcaseExecTime, log = 'suite')
  log.write('Total execution time: %d sec' % totalTime, log = 'suite')

  # Remove all temporary files, save cache
  cache.cleanup()
예제 #8
0
    if not kLine:
        continue
    print(kLine)
    kLineLast = kLine[-1]
    kLineEarly = kLine[-2]

    timestampLast = kLineLast[0] / 1000
    high = kLineLast[2]
    low = kLineLast[3]
    priceLast = kLineLast[4]
    priceEarly = kLineEarly[4]
    change = (float(priceLast) / float(priceEarly)) - 1

    subject = 'BTC_USDT'
    content = '<html>'
    content += '<p>%s</p>' % misc.getTimeStr()

    if high > highValue:
        highValue = high
        misc.setConfigKeyValue('config.ini', 'global', 'high', high)
        content += '<p style="font-weight: bold; color: red;">最高价:%s</p>' % high
        subject += '“最高价”'
        isSend = True
    if low < lowValue:
        lowValue = low
        misc.setConfigKeyValue('config.ini', 'global', 'low', low)
        content += '<p style="font-weight: bold; color: green;">最低价:%s</p>' % low
        subject += '“最低价”'
        isSend = True
    if abs(change) > thresholdValue:
        if not change == changeValue: