Add test for ticker/ohlcv
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
"""Tests for fetch_ticker and fetch_ohlcv."""
|
||||
|
||||
import responses
|
||||
import pytest
|
||||
|
||||
import mt5bridge_ccxt
|
||||
|
||||
|
||||
class TestFetchTicker:
|
||||
@responses.activate
|
||||
def test_returns_ccxt_ticker(self, exchange_config, mock_ticker):
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://mock-mt5bridge:8080/symbols/XAUUSDc/tick",
|
||||
json=mock_ticker, status=200,
|
||||
)
|
||||
ex = mt5bridge_ccxt.mt5bridge(exchange_config)
|
||||
ticker = ex.fetch_ticker("XAU/USD")
|
||||
|
||||
assert ticker["symbol"] == "XAU/USD"
|
||||
assert ticker["bid"] == 4180.50
|
||||
assert ticker["ask"] == 4181.00
|
||||
assert ticker["last"] == 4180.75
|
||||
assert ticker["baseVolume"] == 100
|
||||
assert "info" in ticker
|
||||
assert "timestamp" in ticker
|
||||
|
||||
@responses.activate
|
||||
def test_resolves_symbol_via_map(self, exchange_config, mock_ticker):
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://mock-mt5bridge:8080/symbols/EURUSDc/tick",
|
||||
json=mock_ticker, status=200,
|
||||
)
|
||||
ex = mt5bridge_ccxt.mt5bridge(exchange_config)
|
||||
ticker = ex.fetch_ticker("EUR/USD")
|
||||
assert ticker["symbol"] == "EUR/USD"
|
||||
|
||||
|
||||
class TestFetchOHLCV:
|
||||
@responses.activate
|
||||
def test_from_pos_returns_bars(self, exchange_config, mock_bars):
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://mock-mt5bridge:8080/rates/from-pos",
|
||||
json=mock_bars, status=200,
|
||||
)
|
||||
ex = mt5bridge_ccxt.mt5bridge(exchange_config)
|
||||
bars = ex.fetch_ohlcv("XAU/USD", "1h", limit=2)
|
||||
|
||||
assert len(bars) == 2
|
||||
ts, o, h, l, c, v = bars[0]
|
||||
assert isinstance(ts, int)
|
||||
assert o == 4180.0
|
||||
assert h == 4185.0
|
||||
assert l == 4178.0
|
||||
assert c == 4182.0
|
||||
assert v == 100.0
|
||||
|
||||
@responses.activate
|
||||
def test_from_date_with_params(self, exchange_config, mock_bars):
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://mock-mt5bridge:8080/rates/from-date",
|
||||
json=mock_bars, status=200,
|
||||
)
|
||||
ex = mt5bridge_ccxt.mt5bridge(exchange_config)
|
||||
bars = ex.fetch_ohlcv("XAU/USD", "1h", params={
|
||||
"date_from": "2026-07-01", "date_to": "2026-07-03"
|
||||
})
|
||||
assert len(bars) == 2
|
||||
|
||||
@responses.activate
|
||||
def test_from_date_with_since(self, exchange_config, mock_bars):
|
||||
responses.add(
|
||||
responses.GET,
|
||||
"http://mock-mt5bridge:8080/rates/from-date",
|
||||
json=mock_bars, status=200,
|
||||
)
|
||||
ex = mt5bridge_ccxt.mt5bridge(exchange_config)
|
||||
since = 1720000000000 # some millisecond timestamp
|
||||
bars = ex.fetch_ohlcv("XAU/USD", "1h", since=since, limit=100)
|
||||
assert len(bars) == 2
|
||||
|
||||
def test_invalid_timeframe_raises(self, exchange_config):
|
||||
ex = mt5bridge_ccxt.mt5bridge(exchange_config)
|
||||
from ccxt.base.errors import BadRequest
|
||||
with pytest.raises(BadRequest):
|
||||
ex.fetch_ohlcv("XAU/USD", "2h") # 2h not supported
|
||||
Reference in New Issue
Block a user