Exemple #1
0
def test_get_ticker_information():

    sess = KrakenSession()

    with pytest.raises(MissingRequiredParameterException):
        sess.get_ticker_information(None)

    single_pair = 'XXDGXXBT'
    single_list = [single_pair]
    single_list_as_string = ','.join(single_list)
    asset_pairs_single = sess.get_ticker_information(
        pair=single_list_as_string)
    assert lists_match(asset_pairs_single.keys(), single_list)

    ticker_data_pair = asset_pairs_single[single_pair]
    assert lists_match(ticker_data_pair.keys(),
                       ['a', 'b', 'c', 'v', 'p', 't', 'l', 'h', 'o'])

    for key in ticker_data_pair.keys():
        # 'o' represents opening value, which is not a list
        if key != 'o':
            assert dict_value_length_check(key, ticker_data_pair,
                                           TICKER_RESULTS_EXPECTED_LENGTH)

    multi_list = ['XETHZUSD', 'USDTEUR', 'KAVAEUR']
    multi_list_as_string = ','.join(multi_list)
    asset_pairs_multi = sess.get_ticker_information(pair=multi_list_as_string)
    assert lists_match(asset_pairs_multi.keys(), multi_list)

    bad_list = ['PAXGXBT', 'XLTCZEUR', 'GNOXBT', 'BADPAIR']
    with pytest.raises(InvalidRequestParameterOptionsException):
        bad_list_as_string = ','.join(bad_list)
        sess.get_ticker_information(pair=bad_list_as_string)
Exemple #2
0
def test_get_open_orders_base():

    sess = KrakenSession()
    sess.load_keys_from_file('kraken.key')

    open_orders = sess.get_open_orders()
    assert lists_match(open_orders.keys(), ['open'])
Exemple #3
0
def test_get_trade_balance_base():

    sess = KrakenSession()
    sess.load_keys_from_file('kraken.key')

    trade_balance = sess.get_trade_balance()
    assert lists_match(trade_balance.keys(), TRADE_BALANCE_RESULT_KEYS)
Exemple #4
0
def test_get_asset_info_aclass():

    sess = KrakenSession()
    asset_info_aclass_param = sess.get_asset_info(aclass='currency')
    for asset in asset_info_aclass_param.values():
        assert lists_match(asset.keys(), EXPECTED_ASSET_INFO_KEYS)
    with pytest.raises(InvalidRequestParameterOptionsException):
        sess.get_asset_info(aclass='unknown')
Exemple #5
0
def test_get_trade_balance_asset():

    sess = KrakenSession()
    sess.load_keys_from_file('kraken.key')

    trade_balance = sess.get_trade_balance(asset='ZCAD')
    assert lists_match(trade_balance.keys(), TRADE_BALANCE_RESULT_KEYS)

    with pytest.raises(InvalidRequestParameterOptionsException):
        sess.get_trade_balance(asset='FNYMN')
Exemple #6
0
def tes_kraken_session_get_trade_balance_aclass():

    sess = KrakenSession()
    sess.load_keys_from_file('kraken.key')

    trade_balance = sess.get_trade_balance(aclass='currency')
    assert lists_match(trade_balance.keys(), TRADE_BALANCE_RESULT_KEYS)

    with pytest.raises(InvalidRequestParameterOptionsException):
        sess.get_trade_balance(aclass="otherstuff")
Exemple #7
0
def test_get_tradable_asset_pairs_pair():

    sess = KrakenSession()
    single_list = ['XXDGXXBT']
    single_list_as_string = ','.join(single_list)
    asset_pairs_single = sess.get_tradable_asset_pairs(
        pair=single_list_as_string)
    assert lists_match(asset_pairs_single.keys(), single_list)

    multi_list = ['XETHZUSD', 'USDTEUR', 'KAVAEUR']
    multi_list_as_string = ','.join(multi_list)
    asset_pairs_multi = sess.get_tradable_asset_pairs(
        pair=multi_list_as_string)
    assert lists_match(asset_pairs_multi.keys(), multi_list)

    bad_list = ['PAXGXBT', 'XLTCZEUR', 'GNOXBT', 'BADPAIR']
    with pytest.raises(InvalidRequestParameterOptionsException):
        bad_list_as_string = ','.join(bad_list)
        sess.get_tradable_asset_pairs(pair=bad_list_as_string)
Exemple #8
0
def test_get_order_book_base():

    asset_pair = "XXRPZCAD"

    sess = KrakenSession()
    order_book = sess.get_order_book(asset_pair)
    assert lists_match(order_book.keys(), [asset_pair])

    asset_pair_order_book = order_book[asset_pair]
    assert lists_match(asset_pair_order_book.keys(), ['asks', 'bids'])

    for ask in asset_pair_order_book['asks']:
        assert len(ask) == ORDER_BOOK_ASKS_LENGTH

    for bids in asset_pair_order_book['bids']:
        assert len(bids) == ORDER_BOOKS_BIDS_LENGTH

    with pytest.raises(MissingRequiredParameterException):
        sess.get_order_book(None)

    with pytest.raises(InvalidRequestParameterOptionsException):
        sess.get_order_book("BadPAiR")
Exemple #9
0
def test_get_ohlc_data_base():

    sess = KrakenSession()

    with pytest.raises(MissingRequiredParameterException):
        sess.get_ohlc_data(None)

    asset_pair = 'SCXBT'
    ohlc_data = sess.get_ohlc_data(asset_pair)
    assert lists_match(ohlc_data.keys(), [asset_pair, 'last'])

    ohlc_pair_data = ohlc_data[asset_pair]
    for time_data in ohlc_pair_data:
        assert len(time_data) == OHLC_DATA_LENGTH

    with pytest.raises(InvalidRequestParameterOptionsException):
        sess.get_ohlc_data("BADPAIR")
Exemple #10
0
def test_get_recent_trades_base():

    asset_pair = "OXTETH"

    sess = KrakenSession()
    recent_trades = sess.get_recent_trades(asset_pair)

    assert lists_match(recent_trades.keys(), [asset_pair, 'last'])

    recent_trades_pair = recent_trades[asset_pair]
    for trade in recent_trades_pair:
        assert len(trade) == RECENT_TRADES_LENGTH

    with pytest.raises(MissingRequiredParameterException):
        sess.get_recent_trades(None)

    with pytest.raises(InvalidRequestParameterOptionsException):
        sess.get_recent_trades("UNKCURR")
Exemple #11
0
def test_get_recent_spead_data_base():

    asset_pair = "ETH2.SETH"

    sess = KrakenSession()
    recent_spread_data = sess.get_recent_spread_data(asset_pair)

    assert lists_match(recent_spread_data.keys(), [asset_pair, 'last'])

    recent_pair_spread_data = recent_spread_data[asset_pair]

    for spread_data in recent_pair_spread_data:
        assert len(spread_data) == RECENT_SPREAD_DATA_LENGTH

    with pytest.raises(MissingRequiredParameterException):
        sess.get_recent_spread_data(None)

    with pytest.raises(InvalidRequestParameterOptionsException):
        sess.get_recent_spread_data("EXXDEE")
Exemple #12
0
def test_get_asset_info_base():

    sess = KrakenSession()
    asset_info = sess.get_asset_info()
    for asset in asset_info.values():
        assert lists_match(asset.keys(), EXPECTED_ASSET_INFO_KEYS)