def test_cancel_all_orders(api: GatecoinAPI): """Test cancelling all open orders""" response = api.cancel_all_orders() assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.response_status.message == 'OK' ), 'API response not successful'
def test_cancel_order(api: GatecoinAPI): """Test cancelling the order created in the previous test""" if order_id is not None: response = api.cancel_order(order_id) assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.response_status.message == 'OK' ), 'API response not successful'
def test_get_recent_transactions(api: GatecoinAPI): """Test fetching recent transactions from REST API""" response = GatecoinAPI().get_recent_transactions('BTCUSD') assert (response is not None), 'Response did not deserialize properly' assert (response.response_status.message == 'OK' ), 'API response not successful' assert (len(response.transactions) > 0), 'Empty transactions list' for transaction in response.transactions: _test_transaction(transaction)
def api() -> GatecoinAPI: """Fixture to return API class with credentials set for testing""" assert (os.environ.get('GC_TESTS_PRIVATE_KEY') is not None ), 'GC_TESTS_PRIVATE_KEY not set in environment for trading API\ tests' assert (os.environ.get('GC_TESTS_PUBLIC_KEY') is not None), 'GC_TESTS_PUBLIC_KEY not set in environment for\ trading API tests' return GatecoinAPI(os.environ.get('GC_TESTS_PRIVATE_KEY'), os.environ.get('GC_TESTS_PUBLIC_KEY'))
def test_create_order(api: GatecoinAPI): """Test create a dummy order for BTC using USD""" response = api.create_order('BTCUSD', BID, 0.1, 0.1) assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.response_status.message == 'OK' ), 'API response not successful' assert (response.cl_order_id is not None), 'Cl Order Id was not included in response' global order_id order_id = response.cl_order_id
def test_get_balance(api: GatecoinAPI): """Test USD currency balance from REST API""" response = api.get_balance('USD') assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.response_status.message == 'OK' ), 'API response not successful' assert (response.balance is not None), 'Balance was not included in response' _test_balance(response.balance)
def test_get_balances(api: GatecoinAPI): """Test fetching currency balances from REST API""" response = api.get_balances() assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.response_status.message == 'OK' ), 'API response not successful' assert (response.balances is not None), 'Balances list did not deserialize properly' assert (len(response.balances) > 0), 'Empty balances list' for balance in response.balances: _test_balance(balance)
def test_get_open_orders(api: GatecoinAPI): """Test fetching all open orders from REST API""" global order_id response = api.get_open_orders() assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.response_status.message == 'OK' ), 'API response not successful' assert (response.orders is not None), 'Orders were not included in response' for order in response.orders: _test_open_order(order) order_id = response.orders[0].cl_order_id
def test_get_order_book(api: GatecoinAPI): """Test fetching order book from REST API""" response = GatecoinAPI().get_order_book('BTCUSD') assert (response is not None), 'Response did not deserialize properly' # Disabled for now, v1 does not return response_status for this method # assert (response.response_status.message == 'OK'), 'API response not successful' assert (response.asks is not None), 'Asks list does not exist' assert (response.bids is not None), 'Bids list does not exist' assert (len(response.asks) > 0), 'Empty asks list' assert (len(response.bids) > 0), 'Empty bids list' for limit in response.asks: _test_limit(limit) for limit in response.bids: _test_limit(limit)
def test_get_open_order(api: GatecoinAPI): """Test fetching specific open order from REST API""" global order_id # Make sure to test only if a valid order id is available if order_id is not None: response = api.get_open_order(order_id) assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.response_status.message == 'OK' ), 'API response not successful' assert (response.order is not None), 'Order was not included in response' _test_open_order(response.order)
def test_get_market_depth(api: GatecoinAPI): """Test fetching market depth info from REST API""" response = GatecoinAPI().get_market_depth('BTCUSD') assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.asks is not None), 'Asks list does not exist' assert (response.bids is not None), 'Bids list does not exist' assert (response.response_status.message == 'OK' ), 'API response not successful' assert (len(response.asks) > 0), 'Empty asks list' assert (len(response.bids) > 0), 'Empty bids list' for limit in response.asks: _test_limit(limit) for limit in response.bids: _test_limit(limit)
def test_get_currency_pairs(api: GatecoinAPI): """Test currency pairs fetching from REST API""" response = GatecoinAPI().get_currency_pairs() assert (response is not None), 'Response did not deserialize properly' assert (response.response_status is not None), 'Response status does not exist' assert (response.currency_pairs is not None), 'Currency pairs list does not exist' assert (response.response_status is not None), 'Response status did not deserialize successfully' assert ( response.currency_pairs is not None), 'Currency pairs list did not deserialize successfully' assert (response.response_status.message == 'OK' ), 'API response not successful' assert (len(response.currency_pairs) > 0), 'Empty currency pairs list' for currency_pair in response.currency_pairs: _test_currency_pair(currency_pair)
def api() -> GatecoinAPI: """Fixture to return API class with credentials set for testing""" return GatecoinAPI()