Esempio n. 1
0
def test_index_markets_from(monkeypatch):
    monkeypatch.setattr(index, 'get_exchange', get_mock_exchange)

    expected = [Market('BTC', 'ETH'), Market('USDT', 'BTC')]
    actual = index_markets_from('EXCHANGE2')

    assert actual == expected
Esempio n. 2
0
def test_common_markets(monkeypatch):
    monkeypatch.setattr(utility, 'get_exchange', get_mock_exchange)

    expected = [Market('BTC', 'ETH'), Market('BTC', 'LTC')]
    actual = common_markets(['EXCHANGE1', 'EXCHANGE4'])

    assert actual == expected
Esempio n. 3
0
def test_index_markets(monkeypatch):
    monkeypatch.setattr(index, 'all_markets', all_mock_markets)

    expected = [
        Market('BTC', 'ETH'),
        Market('BTC', 'LTC'),
        Market('USDT', 'BTC')
    ]
    actual = index_markets()

    assert actual == expected
Esempio n. 4
0
def test_ccxt_exchange_get_book(monkeypatch):
    monkeypatch.setattr(ccxt, "bittrex", ExchangeMockAPI)

    exchange = CCXTExchange("BITTREX", "bittrex")
    book = exchange.get_book(Market('BTC', 'ETH'))

    assert isinstance(book, Book)
Esempio n. 5
0
def test_ccxt_exchange_get_ticker(monkeypatch):
    monkeypatch.setattr(ccxt, "southxchange", ExchangeMockAPI)

    exchange = CCXTExchange("SOUTHEXCHANGE", "southxchange")
    ticker = exchange.get_ticker(Market('BTC', 'ETH'))

    assert isinstance(ticker, Ticker)
Esempio n. 6
0
def test_ccxt_exchange_has_not_such_market(monkeypatch):
    monkeypatch.setattr(ccxt, "kraken", ExchangeMockAPI)

    exchange = CCXTExchange("KRAKEN", "kraken")
    exists = exchange.has_market(Market('BTC', 'LTC'))

    assert exists is False
Esempio n. 7
0
def test_ccxt_exchange_has_market(monkeypatch):
    monkeypatch.setattr(ccxt, "bitfinex", ExchangeMockAPI)

    exchange = CCXTExchange("BITFINEX", "bitfinex")
    exists = exchange.has_market(Market('BTC', 'ETH'))

    assert exists is True
Esempio n. 8
0
def get_book(exchange: str, quote: str, base: str) -> Book:
    market = Market(quote.upper(), base.upper())
    return fetch_book(exchange.upper(), market)
Esempio n. 9
0
def get_ticker(exchange: str, quote: str, base: str) -> Ticker:
    market = Market(quote.upper(), base.upper())
    return fetch_ticker(exchange.upper(), market)
Esempio n. 10
0
import ccxt
from typing import List

from dotcoin.core.types import Market, Context, Ticker, Order, Book
from dotcoin.core.abstract import Exchange

SYMBOL_SAMPLE = 'ETH/BTC'

MARKET_SAMPLE = Market("BTC", "ETH")

CONTEXT_SAMPLE = Context(MARKET_SAMPLE, "BINANCE")

SOURCE_TICKER_SAMPLE = {
    'symbol': 'ETH/BTC', 'timestamp': 1584330712574, 'datetime': '2020-03-16T03:51:52.574Z',
    'high': 0.023629,
    'low': 0.022214, 'bid': 0.023176, 'bidVolume': 0.086, 'ask': 0.023184, 'askVolume': 4.0,
    'vwap': 0.02317318,
    'open': 0.023344, 'close': 0.023182, 'last': 0.023182, 'previousClose': 0.02334,
    'change': -0.000162,
    'percentage': -0.694, 'average': None, 'baseVolume': 336552.631,
    'quoteVolume': 7798.99618515,
    'info': {
        'symbol': 'ETHBTC', 'priceChange': '-0.00016200', 'priceChangePercent': '-0.694',
        'weightedAvgPrice': '0.02317318', 'prevClosePrice': '0.02334000',
        'lastPrice': '0.02318200',
        'lastQty': '1.16200000', 'bidPrice': '0.02317600', 'bidQty': '0.08600000',
        'askPrice': '0.02318400',
        'askQty': '4.00000000', 'openPrice': '0.02334400', 'highPrice': '0.02362900',
        'lowPrice': '0.02221400',
        'volume': '336552.63100000', 'quoteVolume': '7798.99618515',
        'openTime': 1584244312574,
Esempio n. 11
0
from dotcoin.core.types import Market, Context, Ticker, Order, Book, Table

MARKET = Market("BTC", "ETH")

CONTEXT = Context(MARKET, "BINANCE")

TICKER = Ticker(
    CONTEXT, **{
        'bid': 0.023176,
        'ask': 0.023184,
        'last': 0.023182,
        'volume': 336552.631,
        'var': -0.694
    })

TICKER_TABLE = Table(
    ["Last ETH/BTC", "Volume ETH", "Var.", "Bid ETH/BTC", "Ask BTC/ETH"],
    [["0.023182", "336552.631", "-0.69%", "0.023176", "0.023184"]])

TICKER_PRINT = """\
┌──────────────┬────────────┬────────┬─────────────┬─────────────┐
│ Last ETH/BTC │ Volume ETH │ Var.   │ Bid ETH/BTC │ Ask BTC/ETH │
╞══════════════╪════════════╪════════╪═════════════╪═════════════╡
│ 0.023182     │ 336552.631 │ -0.69% │ 0.023176    │ 0.023184    │
└──────────────┴────────────┴────────┴─────────────┴─────────────┘"""

BOOK = Book(CONTEXT,
            bids=[
                Order(price=0.02309, base=10.729, quote=0.24773260999999996),
                Order(price=0.023089, base=17.176, quote=0.3965766639999999),
                Order(price=0.023088, base=0.121, quote=0.002793648),
Esempio n. 12
0
def symbol_to_market(symbol: str) -> Market:
    base, quote = symbol.split("/")
    return Market(quote, base)
Esempio n. 13
0
from typing import List

from dotcoin.core.types import Market, Book, Ticker
from dotcoin.core.abstract import Exchange

MARKETS = {
    'EXCHANGE1': [Market('BTC', 'ETH'),
                  Market('BTC', 'LTC')],
    'EXCHANGE2': [Market('BTC', 'ETH'),
                  Market('USDT', 'BTC')],
    'EXCHANGE3': [
        Market('USDT', 'BTC'),
    ],
    'EXCHANGE4':
    [Market('USDT', 'BTC'),
     Market('BTC', 'ETH'),
     Market('BTC', 'LTC')]
}


class MockExchange(Exchange):
    def __init__(self, exchange):
        self.name = exchange

    def markets(self) -> List[Market]:
        return MARKETS[self.name]

    def has_market(self, market: Market) -> bool:
        return market in MARKETS[self.name]

    def get_ticker(self, market: Market) -> Ticker:
Esempio n. 14
0
def common_exchanges(quote: str, base: str) -> List[str]:
    market = Market(quote.upper(), base.upper())
    matches = match_exchanges(market, all_exchanges())
    names = exchanges_to_names(matches)
    return sorted(names)