Пример #1
0
     candles.append(eval(line))
 tiedot = candles[0]
 print(tiedot)
 candles.pop(0)
 paras = 0
 parassma = []
 parashold = 0
 for x in range(SMA_PERIODS[0], MAX_PERIODS[0] + 1):
     for y in range(max(SMA_PERIODS[1], x), MAX_PERIODS[1]):
         #print('SMA1: ' + str(x) + ' SMA2: ' + str(y))
         last_action = 'SELL'
         saldo = 0
         kauppoja = 0
         kynttilat = []
         kynttilat = candles.copy()
         sma1 = sma.SMA(x)
         sma2 = sma.SMA(y)
         for i in range(x):
             sma1.add(kynttilat[i][SMA_POINTS[0]])
         for j in range(y):
             sma2.add(kynttilat[j][SMA_POINTS[1]])
         for k in range(y):
             kynttilat.pop(0)
         for kynttila in kynttilat:
             #print('added: ' + str(kynttila[SMA_POINTS[0]]))
             sma1.add(kynttila[SMA_POINTS[0]])
             sma2.add(kynttila[SMA_POINTS[1]])
             sma1_value = sma1.v()
             sma2_value = sma2.v()
             if last_action == 'SELL' and sma1_value > sma2_value * multipsma2:
                 saldo = saldo - kynttila['close']
Пример #2
0
            parsed_klines = []
            for k in resp:
                k_candle = {
                    'open': float(k[1]),
                    'high': float(k[2]),
                    'low': float(k[3]),
                    'close': float(k[4]),
                    'vol': float(k[5])
                }
                parsed_klines.append(k_candle)
        except Exception as e:
            logging(2, tieto['symbol'], 'Getting candle failed', str(e), 1)
            continue

    #get sma values
        sma1 = sma.SMA(tieto['SMA_PERIODS'][0])
        sma2 = sma.SMA(tieto['SMA_PERIODS'][1])
        for kline in parsed_klines:
            #add close values to sma objects
            sma1.add(kline[tieto['SMA_POINTS'][0]])
            sma2.add(kline[tieto['SMA_POINTS'][1]])
        sma1_value = sma1.v()
        sma2_value = sma2.v()
        logging(0, tieto['symbol'],
                'SMA1: ' + str(sma1_value) + ', SMA2: ' + str(sma2_value), '',
                1)

        #triggers buy and changes last_action
        if (tieto['last_action'] == 'SELL' and sma1_value >
            (sma2_value * tieto['sma2multip'])) or (
                tieto['last_action'] == 'BUY' and sma2_value >
Пример #3
0
    resp = requests.get(BASE_URL + '/api/v3/klines', params=payload)
    klines = json.loads(resp.content)

    #parse to get only needed values
    parsed_klines = []
    for k in klines:
        k_candle = {
            'open': float(k[1]),
            'high': float(k[2]),
            'low': float(k[3]),
            'close': float(k[4]),
            'vol': float(k[5])
        }
        parsed_klines.append(k_candle)

    sma1 = sma.SMA(SMA_PERIODS[0])
    sma2 = sma.SMA(SMA_PERIODS[1])
    for kline in parsed_klines:
        #add close values to sma objects
        sma1.add(kline[SMA_POINTS[0]])
        sma2.add(kline[SMA_POINTS[1]])
    sma1_value = sma1.v()
    sma2_value = sma2.v()
    print(symbol + ', SMA1: ' + str(sma1_value) + ', SMA2: ' + str(sma2_value))
    #triggers buy and changes last_action
    if (last_action == 'SELL'
            and sma1_value > sma2_value) or (last_action == 'BUY'
                                             and sma2_value > sma1_value):
        if last_action == 'SELL': suunta = 'BUY'
        elif last_action == 'BUY': suunta = 'SELL'
        logging('Trade:' + str(symbol) + ',' + str(suunta) + ',' +