Ejemplo n.º 1
0
async def test_set_tentacle_value():
    matrix = Matrix()
    Matrices.instance().add_matrix(matrix)
    set_tentacle_value(matrix.matrix_id,
                       tentacle_type="TA",
                       tentacle_value=0,
                       tentacle_path=["test-path"])
    assert matrix.get_node_at_path(["test-path"]).node_value == 0

    set_tentacle_value(matrix.matrix_id,
                       tentacle_type="TA",
                       tentacle_value="value",
                       tentacle_path=get_tentacle_path(
                           tentacle_type="TA",
                           tentacle_name="Test-TA",
                           exchange_name="binance"))
    assert matrix.get_node_at_path(
        get_tentacle_path(tentacle_type="TA",
                          tentacle_name="Test-TA",
                          exchange_name="binance")).node_value == "value"
    Matrices.instance().del_matrix(matrix.matrix_id)
Ejemplo n.º 2
0
async def test_get_available_time_frames():
    matrix = Matrix()
    Matrices.instance().add_matrix(matrix)

    evaluator_1_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="RSI",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1m")
    evaluator_2_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="ADX",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1m")
    evaluator_3_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="ADX",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1h")
    evaluator_4_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="RSI",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1h")

    # simulate AbstractEvaluator.initialize()
    set_tentacle_value(matrix.matrix_id, evaluator_1_path, "TA", 1)
    set_tentacle_value(matrix.matrix_id, evaluator_2_path, "TA", -0.5)
    set_tentacle_value(matrix.matrix_id, evaluator_3_path, "TA", 0)
    set_tentacle_value(matrix.matrix_id, evaluator_4_path, "TA", -1)

    assert get_available_time_frames(matrix.matrix_id,
                                     exchange_name="kraken",
                                     tentacle_type="TA",
                                     cryptocurrency="BTC",
                                     symbol="BTC/USD") == ["1m", "1h"]

    # invalid path
    assert get_available_time_frames(matrix.matrix_id,
                                     exchange_name="kraken",
                                     tentacle_type="TA_invalid",
                                     cryptocurrency="BTC",
                                     symbol="BTC/USD") == []
Ejemplo n.º 3
0
async def test_get_available_symbols():
    matrix = Matrix()
    Matrices.instance().add_matrix(matrix)

    evaluator_1_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="RSI",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1m")
    evaluator_2_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="RSI",
                                                     cryptocurrency="BTC",
                                                     symbol="BTCX/USDC",
                                                     time_frame="1m")
    evaluator_3_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="RSI",
                                                     cryptocurrency="BTC",
                                                     symbol="BTCX/USDC",
                                                     time_frame="1h")
    evaluator_4_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="RSI",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1h")

    # simulate AbstractEvaluator.initialize()
    set_tentacle_value(matrix.matrix_id, evaluator_1_path, "TA", 1)
    set_tentacle_value(matrix.matrix_id, evaluator_2_path, "TA", -0.5)
    set_tentacle_value(matrix.matrix_id, evaluator_3_path, "TA", 0)
    set_tentacle_value(matrix.matrix_id, evaluator_4_path, "TA", -1)

    assert get_available_symbols(matrix.matrix_id,
                                 exchange_name="kraken",
                                 cryptocurrency="BTC") == [
                                     "BTC/USD", "BTCX/USDC"
                                 ]

    # invalid path
    assert get_available_symbols(matrix.matrix_id,
                                 exchange_name="invalid_exchange",
                                 cryptocurrency="BTC") == []
    assert get_available_symbols(matrix.matrix_id,
                                 exchange_name="kraken",
                                 cryptocurrency="BTCX") == []
    assert get_available_symbols(matrix.matrix_id,
                                 exchange_name="invalid_exchange",
                                 cryptocurrency="BTCX") == []

    # now valid using real-time evaluation
    evaluator_5_path = get_matrix_default_value_path(tentacle_type="REAL_TIME",
                                                     exchange_name="kraken",
                                                     tentacle_name="RSI",
                                                     cryptocurrency="BTCX",
                                                     symbol="BTCX/USD",
                                                     time_frame="1h")
    set_tentacle_value(matrix.matrix_id, evaluator_5_path, "REAL_TIME", -1)
    assert get_available_symbols(matrix.matrix_id,
                                 exchange_name="kraken",
                                 cryptocurrency="BTCX") == ["BTCX/USD"]
Ejemplo n.º 4
0
async def test_get_evaluations_by_evaluator():
    matrix = Matrix()
    Matrices.instance().add_matrix(matrix)

    evaluator_1_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="RSI",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1m")
    evaluator_2_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="ADX",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1m")
    evaluator_3_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     exchange_name="kraken",
                                                     tentacle_name="ADX",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1h")

    # simulate AbstractEvaluator.initialize()
    set_tentacle_value(matrix.matrix_id, evaluator_1_path, "TA", 1)
    set_tentacle_value(matrix.matrix_id, evaluator_2_path, "TA", -0.5)
    set_tentacle_value(matrix.matrix_id, evaluator_3_path, "TA", 0)

    assert get_evaluations_by_evaluator(
        matrix.matrix_id,
        tentacle_type="TA",
        exchange_name="kraken",
        cryptocurrency="BTC",
        symbol="BTC/USD",
        time_frame="1m") == {
            "RSI": get_tentacle_node(matrix.matrix_id, evaluator_1_path),
            "ADX": get_tentacle_node(matrix.matrix_id, evaluator_2_path)
        }

    # set invalid value to not to add this value in result dict
    set_tentacle_value(matrix.matrix_id, evaluator_2_path, "TA",
                       START_PENDING_EVAL_NOTE)
    with pytest.raises(UnsetTentacleEvaluation):
        get_evaluations_by_evaluator(matrix.matrix_id,
                                     tentacle_type="TA",
                                     exchange_name="kraken",
                                     cryptocurrency="BTC",
                                     symbol="BTC/USD",
                                     time_frame="1m",
                                     allow_missing=False)
    assert get_evaluations_by_evaluator(matrix.matrix_id,
                                        tentacle_type="TA",
                                        exchange_name="kraken",
                                        cryptocurrency="BTC",
                                        symbol="BTC/USD",
                                        time_frame="1m",
                                        allow_missing=True) == {
                                            "RSI": get_tentacle_node(
                                                matrix.matrix_id,
                                                evaluator_1_path)
                                        }
    assert get_evaluations_by_evaluator(
        matrix.matrix_id,
        tentacle_type="TA",
        exchange_name="kraken",
        cryptocurrency="BTC",
        symbol="BTC/USD",
        time_frame="1m",
        allow_missing=True,
        allowed_values=[START_PENDING_EVAL_NOTE]) == {
            "RSI": get_tentacle_node(matrix.matrix_id, evaluator_1_path),
            "ADX": get_tentacle_node(matrix.matrix_id, evaluator_2_path)
        }

    # invalid path
    assert get_evaluations_by_evaluator(
        matrix.matrix_id,
        tentacle_type="TA_invalid",
        exchange_name="kraken",
        cryptocurrency="BTC",
        symbol="BTC/USD",
        time_frame="1m",
        allow_missing=True,
        allowed_values=[START_PENDING_EVAL_NOTE]) == {}
Ejemplo n.º 5
0
async def test_is_tentacles_values_valid():
    matrix = Matrix()
    Matrices.instance().add_matrix(matrix)

    evaluator_1_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     tentacle_name="Test-TA",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1m")
    evaluator_2_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     tentacle_name="Test-TA",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1h")

    # simulate AbstractEvaluator.initialize()
    set_tentacle_value(matrix.matrix_id, evaluator_1_path, "TA", None)
    set_tentacle_value(matrix.matrix_id, evaluator_2_path, "TA", None)

    assert not is_tentacles_values_valid(matrix.matrix_id,
                                         [evaluator_1_path, evaluator_2_path])

    set_tentacle_value(
        matrix.matrix_id,
        evaluator_1_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_MINUTE] * 2 * MINUTE_TO_SECONDS)
    set_tentacle_value(
        matrix.matrix_id,
        evaluator_2_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_HOUR] * 2 * MINUTE_TO_SECONDS)
    assert not is_tentacles_values_valid(matrix.matrix_id,
                                         [evaluator_1_path, evaluator_2_path])

    set_tentacle_value(
        matrix.matrix_id,
        evaluator_1_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_MINUTE] * MINUTE_TO_SECONDS)
    assert not is_tentacles_values_valid(matrix.matrix_id,
                                         [evaluator_1_path, evaluator_2_path])

    set_tentacle_value(
        matrix.matrix_id,
        evaluator_2_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_HOUR] * MINUTE_TO_SECONDS)
    assert is_tentacles_values_valid(matrix.matrix_id,
                                     [evaluator_1_path, evaluator_2_path])
    Matrices.instance().del_matrix(matrix.matrix_id)
Ejemplo n.º 6
0
async def test_is_tentacle_value_valid():
    matrix = Matrix()
    Matrices.instance().add_matrix(matrix)

    evaluator_1_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     tentacle_name="Test-TA",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1m")
    evaluator_2_path = get_matrix_default_value_path(tentacle_type="TA",
                                                     tentacle_name="Test-TA",
                                                     cryptocurrency="BTC",
                                                     symbol="BTC/USD",
                                                     time_frame="1h")

    # simulate AbstractEvaluator.initialize()
    set_tentacle_value(matrix.matrix_id, evaluator_1_path, "TA", None)
    set_tentacle_value(matrix.matrix_id, evaluator_2_path, "TA", None)

    get_tentacle_node(matrix.matrix_id,
                      evaluator_1_path).node_value_time = time.time()
    assert is_tentacle_value_valid(matrix.matrix_id, evaluator_1_path)
    assert not is_tentacle_value_valid(matrix.matrix_id, evaluator_2_path)

    set_tentacle_value(matrix.matrix_id,
                       evaluator_2_path,
                       "TA",
                       None,
                       timestamp=100)
    assert not is_tentacle_value_valid(matrix.matrix_id, evaluator_2_path)

    set_tentacle_value(
        matrix.matrix_id,
        evaluator_2_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_HOUR] * 2 * MINUTE_TO_SECONDS)
    assert not is_tentacle_value_valid(matrix.matrix_id, evaluator_2_path)

    set_tentacle_value(
        matrix.matrix_id,
        evaluator_2_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_HOUR] * MINUTE_TO_SECONDS)
    assert is_tentacle_value_valid(matrix.matrix_id, evaluator_2_path)

    # test delta
    set_tentacle_value(
        matrix.matrix_id,
        evaluator_2_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_HOUR] * MINUTE_TO_SECONDS - 10)
    assert not is_tentacle_value_valid(matrix.matrix_id, evaluator_2_path)

    # test delta
    set_tentacle_value(
        matrix.matrix_id,
        evaluator_2_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_HOUR] * MINUTE_TO_SECONDS - 9)
    assert is_tentacle_value_valid(matrix.matrix_id, evaluator_2_path)

    # test modified delta
    set_tentacle_value(
        matrix.matrix_id,
        evaluator_2_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_HOUR] * MINUTE_TO_SECONDS - 29)
    assert is_tentacle_value_valid(matrix.matrix_id,
                                   evaluator_2_path,
                                   delta=30)

    # test modified delta
    set_tentacle_value(
        matrix.matrix_id,
        evaluator_2_path,
        "TA",
        None,
        timestamp=time.time() -
        TimeFramesMinutes[TimeFrames.ONE_HOUR] * MINUTE_TO_SECONDS - 31)
    assert not is_tentacle_value_valid(
        matrix.matrix_id, evaluator_2_path, delta=30)

    Matrices.instance().del_matrix(matrix.matrix_id)