def test_from_matrix_w_volume(self): values = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 0]] self.assertListEqual(OHLCVFactory.from_matrix(values), [ OHLCV(1, 2, 3, 4, 5), OHLCV(6, 7, 8, 9, 0), ])
def test_from_matrix2_wo_volume(self): values = [[1, 6], [2, 7], [3, 8], [4, 9]] self.assertListEqual(OHLCVFactory.from_matrix2(values), [ OHLCV(1, 2, 3, 4, None), OHLCV(6, 7, 8, 9, None), ])
def test_from_matrix2_w_time(self): now = datetime.now() values = [[1, 6], [2, 7], [3, 8], [4, 9], [5, 0], [now, now]] self.assertListEqual(OHLCVFactory.from_matrix2(values), [ OHLCV(1, 2, 3, 4, 5, now), OHLCV(6, 7, 8, 9, 0, now), ])
def test_from_matrix_w_time(self): now = datetime.now() values = [[1, 2, 3, 4, 5, now], [6, 7, 8, 9, 0, now]] self.assertListEqual(OHLCVFactory.from_matrix(values), [ OHLCV(1, 2, 3, 4, 5, now), OHLCV(6, 7, 8, 9, 0, now), ])
def test_from_dict_wo_volume(self): values = { 'open': [1, 6], 'high': [2, 7], 'low': [3, 8], 'close': [4, 9] } self.assertListEqual(OHLCVFactory.from_dict(values), [ OHLCV(1, 2, 3, 4, None), OHLCV(6, 7, 8, 9, None), ])
def test_from_dict_w_time(self): now = datetime.now() values = { 'open': [1, 6], 'high': [2, 7], 'low': [3, 8], 'close': [4, 9], 'volume': [5, 0], 'time': [now, now] } self.assertListEqual(OHLCVFactory.from_dict(values), [ OHLCV(1, 2, 3, 4, 5, now), OHLCV(6, 7, 8, 9, 0, now), ])
def assertIndicatorDelete(self, indicator: Indicator, iterations_no: int = 20): last_indicator_value = indicator[-1] last_input_value = indicator.input_values[-1] for i in range(1, iterations_no): if isinstance(last_input_value, OHLCV): new_val = OHLCV((i + 1)**2, (i + 3)**2, (i + 5)**2, (i + 7)**2, i**2) else: new_val = i indicator.add_input_value(new_val) for i in range(1, iterations_no): indicator.remove_input_value() # verify that adding and then removing X input values returns the original output value self.assertEqual(last_indicator_value, indicator[-1]) # delete the original last input value and add it back and check the original last output value is returned indicator.remove_input_value() indicator.add_input_value(last_input_value) self.assertEqual(last_indicator_value, indicator[-1])
def assertIndicatorUpdate(self, indicator: Indicator, iterations_no: int = 20): last_indicator_value = indicator[-1] last_input_value = indicator.input_values[-1] for i in range(1, iterations_no): if isinstance(last_input_value, OHLCV): new_val = OHLCV(i + 1, i + 2, i + 3, i + 4, i + 5) else: new_val = i indicator.update_input_value(new_val) indicator.update_input_value(last_input_value) self.assertEqual(last_indicator_value, indicator[-1])
async def run(): api_key = os.environ['BITPANDAAPIKEY'] client = CryptoXLib.create_bitpanda_client(api_key) candles = await client.get_candlesticks( Pair('BTC', 'EUR'), enums.TimeUnit.DAYS, "1", datetime.datetime.now() - datetime.timedelta(days=1500), datetime.datetime.now()) candles = candles['response'] close = [float(x['close']) for x in candles] ohlcv = [ OHLCV(float(x['open']), float(x['high']), float(x['low']), float(x['close']), float(x['volume'])) for x in candles ] print(f"Last OHLCV: {ohlcv[-1]}") print(f'AccuDist: {AccuDist(ohlcv)[-1]}') print(f'ADX: {ADX(14, 14, ohlcv)[-1]}') print(f'ALMA: {ALMA(9, 0.85, 6, close)[-1]}') print(f'AO: {AO(5, 34, ohlcv)[-1]}') print(f'Aroon: {Aroon(4, ohlcv)[-1]}') print(f'ATR: {ATR(14, ohlcv)[-1]}') print(f'BB: {BB(20, 2, close)[-1]}') print(f'BOP: {BOP(ohlcv)[-1]}') print(f'CCI: {CCI(20, ohlcv)[-1]}') print(f'ChaikinOsc: {ChaikinOsc(3, 10, ohlcv)[-1]}') print(f'ChandeKrollStop: {ChandeKrollStop(10, 2, 9, ohlcv)[-5:]}') print(f'CHOP: {CHOP(14, ohlcv)[-5:]}') print(f'CoppockCurve: {CoppockCurve(11, 14, 10, close)[-1]}') print(f'DEMA: {DEMA(20, close)[-1]}') print(f'DonchianChannels: {DonchianChannels(20, ohlcv)[-1]}') print(f'DPO: {DPO(20, close)[-1]}') print(f'EMA: {EMA(20, close)[-1]}') print(f'EMV: {EMV(14, 10000, ohlcv)[-1]}') print(f'ForceIndex: {ForceIndex(13, ohlcv)[-1]}') print(f'HMA: {HMA(9, close)[-1]}') print(f'Ichimoku: {Ichimoku(26, 9, 52, 52, 26, ohlcv)[-1]}') print(f'KAMA: {KAMA(14, 2, 30, close)[-1]}') print(f'KeltnerChannels: {KeltnerChannels(20, 26, 1, 1, ohlcv)[-1]}') print(f'KST: {KST(10, 10, 15, 10, 20, 10, 30, 15, 9, close)[-1]}') print(f'KVO: {KVO(34, 55, ohlcv)[-5:]}') print(f'MACD: {MACD(12, 26, 9, close)[-1]}') print(f'MassIndex: {MassIndex(9, 9, 10, ohlcv)[-1]}') print(f'McGinleyDynamic: {McGinleyDynamic(14, close)[-1]}') print(f'MeanDev: {MeanDev(10, close)[-1]}') print(f'OBV: {OBV(ohlcv)[-1]}') print(f'Pivots: {PivotsHL(15, 15, ohlcv)[-4:]}') print(f'ROC: {ROC(9, close)[-1]}') print(f'RSI: {RSI(14, close)[-1]}') print(f"SAR: {ParabolicSAR(0.02, 0.02, 0.2, ohlcv)[-20:]}") print(f'SFX: {SFX(12, 12, 3, ohlcv)[-1]}') print(f'SMA: {SMA(20, close)[-1]}') print(f'SMMA: {SMMA(7, close)[-1]}') print(f'SOBV: {SOBV(7, ohlcv)[-1]}') print(f'StdDev: {StdDev(7, close)[-1]}') print(f'Stoch: {Stoch(14, 3, ohlcv)[-1]}') print(f'StochRSI: {StochRSI(14, 14, 3, 3, close)[-1]}') print(f'TEMA: {TEMA(20, close)[-1]}') print(f'TRIX: {TRIX(18, close)[-1]}') print(f'TSI: {TSI(13, 25, close)[-1]}') print(f'UO: {UO(7, 14, 28, ohlcv)[-1]}') print(f'VTX: {VTX(14, ohlcv)[-1]}') print(f'VWMA: {VWMA(20, ohlcv)[-1]}') print(f'WMA: {WMA(9, close)[-1]}') await client.close()
def test_low_high_equal(self): ind = AccuDist(self.input_values) ind.add_input_value(OHLCV(1, 1, 1, 1, 1))