add
This commit is contained in:
70
ccxt/pro/test/Exchange/test_un_watch_positions.py
Normal file
70
ccxt/pro/test/Exchange/test_un_watch_positions.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def create_order_after_delay(exchange):
|
||||
await exchange.sleep(3000)
|
||||
await exchange.create_order('BTC/USDT:USDT', 'market', 'buy', 0.001)
|
||||
|
||||
|
||||
async def test_un_watch_positions(exchange, skipped_properties, symbol):
|
||||
method = 'unWatchPositions'
|
||||
exchange.set_sandbox_mode(True)
|
||||
# First, we need to subscribe to positions to test the unsubscribe functionality
|
||||
positions_subscription = None
|
||||
try:
|
||||
# First call uses snapshot
|
||||
positions_subscription = await exchange.watch_positions()
|
||||
# trigger a position update
|
||||
exchange.spawn(create_order_after_delay, exchange)
|
||||
# Second call uses subscription
|
||||
positions_subscription = await exchange.watch_positions()
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
# If we can't subscribe, we can't test unsubscribe, so skip this test
|
||||
return False
|
||||
# Verify that we have a subscription
|
||||
assert isinstance(positions_subscription, list), exchange.id + ' ' + method + ' requires a valid positions subscription to test unsubscribe'
|
||||
# Assert unWatchPositions for one symbol is not supported
|
||||
error_response = None
|
||||
try:
|
||||
error_response = await exchange.un_watch_positions([symbol])
|
||||
except Exception as e:
|
||||
error_response = e
|
||||
assert error_response is not None, exchange.id + ' ' + method + ' must throw an error when unwatching a specific symbol, returned ' + exchange.json(error_response)
|
||||
# Test unwatching all positions (without specific symbols)
|
||||
response_all = None
|
||||
try:
|
||||
response_all = await exchange.un_watch_positions()
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
raise e
|
||||
# Verify the response for unwatching all positions
|
||||
assert response_all is not None, exchange.id + ' ' + method + ' must return a response when unwatching all positions, returned ' + exchange.json(response_all)
|
||||
# Test that we can resubscribe after unwatching (to ensure cleanup was proper)
|
||||
resubscribe_response = None
|
||||
try:
|
||||
resubscribe_response = await exchange.watch_positions()
|
||||
exchange.spawn(create_order_after_delay, exchange)
|
||||
resubscribe_response = await exchange.watch_positions()
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
raise Error(exchange.id + ' ' + method + ' failed to resubscribe after unwatch, indicating potential cleanup issues')
|
||||
# Verify resubscription works
|
||||
assert isinstance(resubscribe_response, list), exchange.id + ' ' + method + ' must allow resubscription after unwatch, returned ' + exchange.json(resubscribe_response)
|
||||
return True
|
||||
36
ccxt/pro/test/Exchange/test_watch_balance.py
Normal file
36
ccxt/pro/test/Exchange/test_watch_balance.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_balance # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_balance(exchange, skipped_properties, code):
|
||||
method = 'watchBalance'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_balance()
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success is False:
|
||||
continue
|
||||
test_balance(exchange, skipped_properties, method, response)
|
||||
now = exchange.milliseconds()
|
||||
62
ccxt/pro/test/Exchange/test_watch_bids_asks.py
Normal file
62
ccxt/pro/test/Exchange/test_watch_bids_asks.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import asyncio
|
||||
from ccxt.base.errors import ArgumentsRequired # noqa E402
|
||||
from ccxt.test.exchange.base import test_ticker # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_bids_asks(exchange, skipped_properties, symbol):
|
||||
without_symbol = test_watch_bids_asks_helper(exchange, skipped_properties, None)
|
||||
with_symbol = test_watch_bids_asks_helper(exchange, skipped_properties, [symbol])
|
||||
await asyncio.gather(*[with_symbol, without_symbol])
|
||||
|
||||
|
||||
async def test_watch_bids_asks_helper(exchange, skipped_properties, arg_symbols, arg_params={}):
|
||||
method = 'watchBidsAsks'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
success = True
|
||||
should_return = False
|
||||
response = None
|
||||
try:
|
||||
response = await exchange.watch_bids_asks(arg_symbols, arg_params)
|
||||
except Exception as e:
|
||||
# for some exchanges, multi symbol methods might require symbols array to be present, so
|
||||
# so, if method throws "arguments-required" exception, we don't fail test, but just skip silently,
|
||||
# because tests will make a second call of this method with symbols array
|
||||
if (isinstance(e, ArgumentsRequired)) and (arg_symbols is None or len(arg_symbols) == 0):
|
||||
# todo: provide random symbols to try
|
||||
# return false;
|
||||
should_return = True
|
||||
elif not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if should_return:
|
||||
return False
|
||||
if success:
|
||||
assert isinstance(response, dict), exchange.id + ' ' + method + ' ' + exchange.json(arg_symbols) + ' must return an object. ' + exchange.json(response)
|
||||
values = list(response.values())
|
||||
checked_symbol = None
|
||||
if arg_symbols is not None and len(arg_symbols) == 1:
|
||||
checked_symbol = arg_symbols[0]
|
||||
test_shared_methods.assert_non_emtpy_array(exchange, skipped_properties, method, values, checked_symbol)
|
||||
for i in range(0, len(values)):
|
||||
ticker = values[i]
|
||||
test_ticker(exchange, skipped_properties, method, ticker, checked_symbol)
|
||||
now = exchange.milliseconds()
|
||||
return True
|
||||
47
ccxt/pro/test/Exchange/test_watch_liquidations.py
Normal file
47
ccxt/pro/test/Exchange/test_watch_liquidations.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.errors import NetworkError # noqa E402
|
||||
from ccxt.test.exchange.base import test_liquidation # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_liquidations(exchange, skipped_properties, symbol):
|
||||
# log (symbol.green, 'watching trades...')
|
||||
method = 'watchLiquidations'
|
||||
# we have to skip some exchanges here due to the frequency of trading
|
||||
skipped_exchanges = []
|
||||
if exchange.in_array(exchange.id, skipped_exchanges):
|
||||
print(exchange.id, method + '() test skipped')
|
||||
return False
|
||||
if not exchange.has[method]:
|
||||
print(exchange.id, 'does not support', method + '() method')
|
||||
return False
|
||||
response = None
|
||||
now = int(time.time() * 1000)
|
||||
ends = now + 10000
|
||||
while now < ends:
|
||||
try:
|
||||
response = await exchange[method](symbol)
|
||||
now = int(time.time() * 1000)
|
||||
is_array = isinstance(response, list)
|
||||
assert is_array, 'response must be an array'
|
||||
print(exchange.iso8601(now), exchange.id, symbol, method, len(list(response.values())), 'liquidations')
|
||||
# log.noLocate (asTable (response))
|
||||
for i in range(0, len(response)):
|
||||
test_liquidation(exchange, skipped_properties, method, response[i], symbol)
|
||||
except Exception as e:
|
||||
if not (isinstance(e, NetworkError)):
|
||||
raise e
|
||||
now = int(time.time() * 1000)
|
||||
return response
|
||||
@@ -0,0 +1,45 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.errors import NetworkError # noqa E402
|
||||
from ccxt.test.exchange.base import test_liquidation # noqa E402
|
||||
|
||||
async def test_watch_liquidations_for_symbols(exchange, skipped_properties, symbol):
|
||||
method = 'watchLiquidationsForSymbols'
|
||||
# we have to skip some exchanges here due to the frequency of trading
|
||||
skipped_exchanges = []
|
||||
if exchange.in_array(exchange.id, skipped_exchanges):
|
||||
print(exchange.id, method + '() test skipped')
|
||||
return False
|
||||
if not exchange.has[method]:
|
||||
print(exchange.id, method + '() is not supported')
|
||||
return False
|
||||
response = None
|
||||
now = int(time.time() * 1000)
|
||||
ends = now + 10000
|
||||
while now < ends:
|
||||
try:
|
||||
response = await exchange[method]([symbol])
|
||||
now = int(time.time() * 1000)
|
||||
is_array = isinstance(response, list)
|
||||
assert is_array, 'response must be an array'
|
||||
print(exchange.iso8601(now), exchange.id, symbol, method, len(list(response.values())), 'liquidations')
|
||||
# log.noLocate (asTable (response))
|
||||
for i in range(0, len(response)):
|
||||
test_liquidation(exchange, skipped_properties, method, response[i], symbol)
|
||||
except Exception as e:
|
||||
if not (isinstance(e, NetworkError)):
|
||||
raise e
|
||||
now = int(time.time() * 1000)
|
||||
return response
|
||||
39
ccxt/pro/test/Exchange/test_watch_my_trades.py
Normal file
39
ccxt/pro/test/Exchange/test_watch_my_trades.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_trade # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_my_trades(exchange, skipped_properties, symbol):
|
||||
method = 'watchMyTrades'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
success = True
|
||||
response = None
|
||||
try:
|
||||
response = await exchange.watch_my_trades(symbol)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
test_shared_methods.assert_non_emtpy_array(exchange, skipped_properties, method, response, symbol)
|
||||
now = exchange.milliseconds()
|
||||
for i in range(0, len(response)):
|
||||
test_trade(exchange, skipped_properties, method, response[i], symbol, now)
|
||||
test_shared_methods.assert_timestamp_order(exchange, method, symbol, response)
|
||||
return True
|
||||
47
ccxt/pro/test/Exchange/test_watch_ohlcv.py
Normal file
47
ccxt/pro/test/Exchange/test_watch_ohlcv.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_ohlcv # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_ohlcv(exchange, skipped_properties, symbol):
|
||||
method = 'watchOHLCV'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
timeframe_keys = list(exchange.timeframes.keys())
|
||||
assert len(timeframe_keys), exchange.id + ' ' + method + ' - no timeframes found'
|
||||
# prefer 1m timeframe if available, otherwise return the first one
|
||||
chosen_timeframe_key = '1m'
|
||||
if not exchange.in_array(chosen_timeframe_key, timeframe_keys):
|
||||
chosen_timeframe_key = timeframe_keys[0]
|
||||
limit = 10
|
||||
duration = exchange.parse_timeframe(chosen_timeframe_key)
|
||||
since = exchange.milliseconds() - duration * limit * 1000 - 1000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_ohlcv(symbol, chosen_timeframe_key, since, limit)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
test_shared_methods.assert_non_emtpy_array(exchange, skipped_properties, method, response, symbol)
|
||||
now = exchange.milliseconds()
|
||||
for i in range(0, len(response)):
|
||||
test_ohlcv(exchange, skipped_properties, method, response[i], symbol, now)
|
||||
return True
|
||||
54
ccxt/pro/test/Exchange/test_watch_ohlcv_for_symbols.py
Normal file
54
ccxt/pro/test/Exchange/test_watch_ohlcv_for_symbols.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_ohlcv # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_ohlcv_for_symbols(exchange, skipped_properties, symbol):
|
||||
method = 'watchOHLCVForSymbols'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
timeframe_keys = list(exchange.timeframes.keys())
|
||||
assert len(timeframe_keys), exchange.id + ' ' + method + ' - no timeframes found'
|
||||
# prefer 1m timeframe if available, otherwise return the first one
|
||||
chosen_timeframe_key = '1m'
|
||||
if not exchange.in_array(chosen_timeframe_key, timeframe_keys):
|
||||
chosen_timeframe_key = timeframe_keys[0]
|
||||
limit = 10
|
||||
duration = exchange.parse_timeframe(chosen_timeframe_key)
|
||||
since = exchange.milliseconds() - duration * limit * 1000 - 1000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_ohlcv_for_symbols([[symbol, chosen_timeframe_key]], since, limit)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
assertion_message = exchange.id + ' ' + method + ' ' + symbol + ' ' + chosen_timeframe_key + ' | ' + exchange.json(response)
|
||||
assert isinstance(response, dict), 'Response must be a dictionary. ' + assertion_message
|
||||
assert symbol in response, 'Response should contain the symbol as key. ' + assertion_message
|
||||
symbol_obj = response[symbol]
|
||||
assert isinstance(symbol_obj, dict), 'Response.Symbol should be a dictionary. ' + assertion_message
|
||||
assert chosen_timeframe_key in symbol_obj, 'Response.symbol should contain the timeframe key. ' + assertion_message
|
||||
ohlcvs = symbol_obj[chosen_timeframe_key]
|
||||
assert isinstance(ohlcvs, list), 'Response.symbol.timeframe should be an array. ' + assertion_message
|
||||
now = exchange.milliseconds()
|
||||
for i in range(0, len(ohlcvs)):
|
||||
test_ohlcv(exchange, skipped_properties, method, ohlcvs[i], symbol, now)
|
||||
return True
|
||||
38
ccxt/pro/test/Exchange/test_watch_order_book.py
Normal file
38
ccxt/pro/test/Exchange/test_watch_order_book.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_order_book # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_order_book(exchange, skipped_properties, symbol):
|
||||
method = 'watchOrderBook'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_order_book(symbol)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
# [ response, skippedProperties ] = fixPhpObjectArray (exchange, response, skippedProperties);
|
||||
assert isinstance(response, dict), exchange.id + ' ' + method + ' ' + symbol + ' must return an object. ' + exchange.json(response)
|
||||
now = exchange.milliseconds()
|
||||
test_order_book(exchange, skipped_properties, method, response, symbol)
|
||||
return True
|
||||
41
ccxt/pro/test/Exchange/test_watch_order_book_for_symbols.py
Normal file
41
ccxt/pro/test/Exchange/test_watch_order_book_for_symbols.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.base.errors import InvalidNonce # noqa E402
|
||||
from ccxt.test.exchange.base import test_order_book # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_order_book_for_symbols(exchange, skipped_properties, symbols):
|
||||
method = 'watchOrderBookForSymbols'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_order_book_for_symbols(symbols)
|
||||
except Exception as e:
|
||||
# temporary fix for InvalidNonce for c#
|
||||
if not test_shared_methods.is_temporary_failure(e) and not (isinstance(e, InvalidNonce)):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
# [ response, skippedProperties ] = fixPhpObjectArray (exchange, response, skippedProperties);
|
||||
assert isinstance(response, dict), exchange.id + ' ' + method + ' ' + exchange.json(symbols) + ' must return an object. ' + exchange.json(response)
|
||||
now = exchange.milliseconds()
|
||||
test_shared_methods.assert_in_array(exchange, skipped_properties, method, response, 'symbol', symbols)
|
||||
test_order_book(exchange, skipped_properties, method, response, None)
|
||||
return True
|
||||
39
ccxt/pro/test/Exchange/test_watch_orders.py
Normal file
39
ccxt/pro/test/Exchange/test_watch_orders.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_order # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_orders(exchange, skipped_properties, symbol):
|
||||
method = 'watchOrders'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_orders(symbol)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
test_shared_methods.assert_non_emtpy_array(exchange, skipped_properties, method, response, symbol)
|
||||
now = exchange.milliseconds()
|
||||
for i in range(0, len(response)):
|
||||
test_order(exchange, skipped_properties, method, response[i], symbol, now)
|
||||
test_shared_methods.assert_timestamp_order(exchange, method, symbol, response)
|
||||
return True
|
||||
37
ccxt/pro/test/Exchange/test_watch_position.py
Normal file
37
ccxt/pro/test/Exchange/test_watch_position.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_position # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_position(exchange, skipped_properties, symbol):
|
||||
method = 'watchPosition'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_position(symbol)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
assert isinstance(response, dict), exchange.id + ' ' + method + ' ' + symbol + ' must return an object. ' + exchange.json(response)
|
||||
now = exchange.milliseconds()
|
||||
test_position(exchange, skipped_properties, method, response, None, now)
|
||||
return True
|
||||
60
ccxt/pro/test/Exchange/test_watch_positions.py
Normal file
60
ccxt/pro/test/Exchange/test_watch_positions.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_position # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_positions(exchange, skipped_properties, symbol):
|
||||
method = 'watchPositions'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_positions([symbol])
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
test_shared_methods.assert_non_emtpy_array(exchange, skipped_properties, method, response, symbol)
|
||||
now = exchange.milliseconds()
|
||||
for i in range(0, len(response)):
|
||||
test_position(exchange, skipped_properties, method, response[i], None, now)
|
||||
test_shared_methods.assert_timestamp_order(exchange, method, symbol, response)
|
||||
#
|
||||
# Test with specific symbol
|
||||
#
|
||||
positions_for_symbols = None
|
||||
success2 = True
|
||||
try:
|
||||
positions_for_symbols = await exchange.watch_positions([symbol])
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success2 = False
|
||||
if success2:
|
||||
assert isinstance(positions_for_symbols, list), exchange.id + ' ' + method + ' must return an array, returned ' + exchange.json(positions_for_symbols)
|
||||
# max theoretical 4 positions: two for one-way-mode and two for two-way mode
|
||||
assert len(positions_for_symbols) <= 4, exchange.id + ' ' + method + ' positions length for particular symbol should be less than 4, returned ' + exchange.json(positions_for_symbols)
|
||||
now = exchange.milliseconds()
|
||||
for i in range(0, len(positions_for_symbols)):
|
||||
test_position(exchange, skipped_properties, method, positions_for_symbols[i], symbol, now)
|
||||
test_shared_methods.assert_timestamp_order(exchange, method, symbol, positions_for_symbols)
|
||||
return True
|
||||
37
ccxt/pro/test/Exchange/test_watch_ticker.py
Normal file
37
ccxt/pro/test/Exchange/test_watch_ticker.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_ticker # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_ticker(exchange, skipped_properties, symbol):
|
||||
method = 'watchTicker'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_ticker(symbol)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
assert isinstance(response, dict), exchange.id + ' ' + method + ' ' + symbol + ' must return an object. ' + exchange.json(response)
|
||||
now = exchange.milliseconds()
|
||||
test_ticker(exchange, skipped_properties, method, response, symbol)
|
||||
return True
|
||||
64
ccxt/pro/test/Exchange/test_watch_tickers.py
Normal file
64
ccxt/pro/test/Exchange/test_watch_tickers.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import asyncio
|
||||
from ccxt.base.errors import ArgumentsRequired # noqa E402
|
||||
from ccxt.test.exchange.base import test_ticker # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_tickers(exchange, skipped_properties, symbol):
|
||||
without_symbol = test_watch_tickers_helper(exchange, skipped_properties, None)
|
||||
with_symbol = test_watch_tickers_helper(exchange, skipped_properties, [symbol])
|
||||
await asyncio.gather(*[with_symbol, without_symbol])
|
||||
|
||||
|
||||
async def test_watch_tickers_helper(exchange, skipped_properties, arg_symbols, arg_params={}):
|
||||
method = 'watchTickers'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
should_return = False
|
||||
try:
|
||||
response = await exchange.watch_tickers(arg_symbols, arg_params)
|
||||
except Exception as e:
|
||||
# for some exchanges, specifically watchTickers method not subscribe
|
||||
# to "all tickers" itself, and it requires symbols to be set
|
||||
# so, in such case, if it's arguments-required exception, we don't
|
||||
# mark tests as failed, but just skip them
|
||||
if (isinstance(e, ArgumentsRequired)) and (arg_symbols is None or len(arg_symbols) == 0):
|
||||
# todo: provide random symbols to try
|
||||
# return;
|
||||
# return false;
|
||||
should_return = True
|
||||
elif not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if should_return:
|
||||
return False
|
||||
if success:
|
||||
assert isinstance(response, dict), exchange.id + ' ' + method + ' ' + exchange.json(arg_symbols) + ' must return an object. ' + exchange.json(response)
|
||||
values = list(response.values())
|
||||
checked_symbol = None
|
||||
if arg_symbols is not None and len(arg_symbols) == 1:
|
||||
checked_symbol = arg_symbols[0]
|
||||
test_shared_methods.assert_non_emtpy_array(exchange, skipped_properties, method, values, checked_symbol)
|
||||
for i in range(0, len(values)):
|
||||
ticker = values[i]
|
||||
test_ticker(exchange, skipped_properties, method, ticker, checked_symbol)
|
||||
now = exchange.milliseconds()
|
||||
return True
|
||||
39
ccxt/pro/test/Exchange/test_watch_trades.py
Normal file
39
ccxt/pro/test/Exchange/test_watch_trades.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_trade # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_trades(exchange, skipped_properties, symbol):
|
||||
method = 'watchTrades'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_trades(symbol)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
# continue;
|
||||
success = False
|
||||
if success:
|
||||
test_shared_methods.assert_non_emtpy_array(exchange, skipped_properties, method, response)
|
||||
now = exchange.milliseconds()
|
||||
for i in range(0, len(response)):
|
||||
test_trade(exchange, skipped_properties, method, response[i], symbol, now)
|
||||
if not ('timestampSort' in skipped_properties):
|
||||
test_shared_methods.assert_timestamp_order(exchange, method, symbol, response)
|
||||
42
ccxt/pro/test/Exchange/test_watch_trades_for_symbols.py
Normal file
42
ccxt/pro/test/Exchange/test_watch_trades_for_symbols.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
|
||||
sys.path.append(root)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
||||
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from ccxt.test.exchange.base import test_trade # noqa E402
|
||||
from ccxt.test.exchange.base import test_shared_methods # noqa E402
|
||||
|
||||
async def test_watch_trades_for_symbols(exchange, skipped_properties, symbols):
|
||||
method = 'watchTradesForSymbols'
|
||||
now = exchange.milliseconds()
|
||||
ends = now + 15000
|
||||
while now < ends:
|
||||
response = None
|
||||
success = True
|
||||
try:
|
||||
response = await exchange.watch_trades_for_symbols(symbols)
|
||||
except Exception as e:
|
||||
if not test_shared_methods.is_temporary_failure(e):
|
||||
raise e
|
||||
now = exchange.milliseconds()
|
||||
if success:
|
||||
assert isinstance(response, list), exchange.id + ' ' + method + ' ' + exchange.json(symbols) + ' must return an array. ' + exchange.json(response)
|
||||
now = exchange.milliseconds()
|
||||
symbol = None
|
||||
for i in range(0, len(response)):
|
||||
trade = response[i]
|
||||
symbol = trade['symbol']
|
||||
test_trade(exchange, skipped_properties, method, trade, symbol, now)
|
||||
test_shared_methods.assert_in_array(exchange, skipped_properties, method, trade, 'symbol', symbols)
|
||||
if not ('timestamp' in skipped_properties):
|
||||
test_shared_methods.assert_timestamp_order(exchange, method, symbol, response)
|
||||
return True
|
||||
Reference in New Issue
Block a user