49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from arbitrade.detection.graph import CurrencyGraph
|
|
|
|
|
|
def test_currency_graph_from_kraken_pairs_builds_adjacency() -> None:
|
|
asset_pairs = {
|
|
"XXBTZUSD": {"wsname": "BTC/USD"},
|
|
"XETHXXBT": {"wsname": "ETH/BTC"},
|
|
"XETHZUSD": {"wsname": "ETH/USD"},
|
|
}
|
|
|
|
graph = CurrencyGraph.from_kraken_asset_pairs(asset_pairs)
|
|
|
|
assert "USD" in graph.adjacency
|
|
assert "BTC" in graph.adjacency["USD"]
|
|
assert "ETH" in graph.adjacency["USD"]
|
|
|
|
|
|
def test_triangular_cycles_detected_once() -> None:
|
|
asset_pairs = {
|
|
"XXBTZUSD": {"wsname": "BTC/USD"},
|
|
"XETHXXBT": {"wsname": "ETH/BTC"},
|
|
"XETHZUSD": {"wsname": "ETH/USD"},
|
|
}
|
|
|
|
graph = CurrencyGraph.from_kraken_asset_pairs(asset_pairs)
|
|
cycles = graph.triangular_cycles()
|
|
|
|
assert len(cycles) == 1
|
|
cycle = cycles[0]
|
|
assert cycle.currencies == ("BTC", "ETH", "USD")
|
|
assert set(cycle.pairs) == {"BTC/USD", "ETH/BTC", "ETH/USD"}
|
|
|
|
|
|
def test_cycles_indexed_by_pair() -> None:
|
|
asset_pairs = {
|
|
"XXBTZUSD": {"wsname": "BTC/USD"},
|
|
"XETHXXBT": {"wsname": "ETH/BTC"},
|
|
"XETHZUSD": {"wsname": "ETH/USD"},
|
|
}
|
|
|
|
graph = CurrencyGraph.from_kraken_asset_pairs(asset_pairs)
|
|
cycles = graph.triangular_cycles()
|
|
index = graph.index_cycles_by_pair(cycles)
|
|
|
|
assert "BTC/USD" in index
|
|
assert "ETH/BTC" in index
|
|
assert "ETH/USD" in index
|
|
assert len(index["BTC/USD"]) == 1
|