示例#1
0
def test_bid_ask_latest():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/tickers/eth_usd/latest", json=read_json("bidask_latest.json"))
        for exchange, series in AmberRequest(key="a").bid_ask.latest(pair="eth_usd", exchange="bitfinex"):
            assert exchange == "bitfinex"

            x = read_pd("bidask_latest.csv", squeeze=True, index_col=0, header=None)
            x["timestamp"] = pd.Timestamp(x["timestamp"])

            for key in {"bid", "ask", "mid", "last"}:
                x[key] = float(x[key])

            pt.assert_series_equal(series, x, check_names=False)
示例#2
0
def test_ohlcv_latest():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/ohlcv/eth_usd/latest", json=read_json("ohlcv_latest.json"))
        for exchange, series in AmberRequest(key="a").ohlcv.latest(pair="eth_usd", exchange="bitfinex"):
            assert exchange == "bitfinex"

            x = read_pd("ohlcv_latest.csv", squeeze=True, index_col=0, header=None)
            x["timestamp"] = pd.Timestamp(x["timestamp"])

            for key in {"open", "high", "low", "close", "volume"}:
                x[key] = float(x[key])

            pt.assert_series_equal(series, x, check_names=False)
示例#3
0
def test_prices_history():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/prices/eth_usd/historical", json=read_json("prices_history.json"))
        x = AmberRequest(key="a").prices.history(pair="eth_usd", start_date=pd.Timestamp("2020-02-12"), end_date=pd.Timestamp("2020-02-13"), time_interval=TimeInterval.DAYS)
        pt.assert_frame_equal(x, read_pd("prices_history.csv", index_col=0, parse_dates=True))
示例#4
0
def test_ohlcv_history():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/ohlcv/eth_usd/historical?timeInterval=days&startDate=1577836800000", json=read_json("ohlcv_history1.json"))
        m.get("https://web3api.io/api/v2/market/ohlcv/eth_usd/historical?timeInterval=days&startDate=1579564800000", json=read_json("ohlcv_history2.json"))
        m.get("https://web3api.io/api/v2/market/ohlcv/eth_usd/historical?timeInterval=days&startDate=1581292800000", json=read_json("ohlcv_history3.json"))

        for exchange, data in AmberRequest(key="a").ohlcv.history(pair="eth_usd", exchange="bitfinex", start_date=pd.Timestamp("2020-01-01"), end_date=pd.Timestamp("2020-02-20"), time_interval=TimeInterval.DAYS):
            assert exchange == "bitfinex"
            pt.assert_frame_equal(data, read_pd("ohlcv_history.csv", index_col=0, parse_dates=True))
示例#5
0
def test_bidask_history():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/tickers/eth_usd/historical", json=read_json("bidask_history.json"))
        for exchange, data in AmberRequest(key="a").bid_ask.history(pair="eth_usd", exchange="bitfinex", start_date=pd.Timestamp("2020-02-12 23:50:00"), end_date=pd.Timestamp("2020-02-13")):
            assert exchange == "bitfinex"
            pt.assert_frame_equal(data, read_pd("bidask_history.csv", index_col=0, parse_dates=True))
示例#6
0
def test_prices_latest():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/prices/eth_usd/latest", json=read_json("prices_latest.json"))
        for pair, series in AmberRequest(key="a").prices.latest(pair="eth_usd"):
            assert pair == "eth_usd"
            pt.assert_series_equal(series, read_pd("prices_latest.csv", squeeze=True, index_col=0, parse_dates=True, header=None), check_names=False)
示例#7
0
def test_pairs():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/pairs", json=read_json("pairs.json"))
        xxx = [f.exchange for f in AmberRequest(key="a").features.pairs(pair="eth_usd")]
        assert xxx == ["bitfinex"]
示例#8
0
def test_price_pairs():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/prices/pairs", json=read_json("price_pairs.json"))
        xxx = set([f for f in AmberRequest(key="a").features.price_pairs()])
        assert xxx == {"18c_btc", "18c_eth", "1st_btc"}
示例#9
0
def test_ohlcv_pairs():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/ohlcv/information", json=read_json("ohlcv_pairs.json"))
        xxx = set([f.exchange for f in AmberRequest(key="a").features.ohlcv_pairs()])
        assert xxx == {"binance"}
示例#10
0
def test_ticker_pairs():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/tickers/information", json=read_json("ticker_pairs.json"))
        xxx = [f.exchange for f in AmberRequest(key="a").features.ticker_pairs()]
        assert xxx == ["bitfinex"]
示例#11
0
def test_trades():
    with requests_mock.Mocker() as m:
        m.get("https://web3api.io/api/v2/market/trades/information?exchange=binance", json=read_json("trades.json"))
        xxx = [(f.pair, f.exchange) for f in AmberRequest(key="a").features.trades(exchange="binance")]
        assert xxx == [("adx_bnb","binance")]