-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exchange.close()): have exchange.close() [ci deploy]
* fix ts * python fix * python fix on_error call * more elegante python solution * php fixes * fast client lint * error hieracrchy * lint * lint * eslint fixes * latest changes * remove logic of adding error * fix python lint [ci deploy] --------- Co-authored-by: carlosmiei <[email protected]>
- Loading branch information
1 parent
a7bbeef
commit 225bc94
Showing
15 changed files
with
304 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
namespace ccxt\pro; | ||
include_once (__DIR__.'/../../../../ccxt.php'); | ||
|
||
|
||
use ccxt\ExchangeClosedByUser; | ||
use React\Async; | ||
use React\Promise; | ||
|
||
|
||
|
||
function watch_ticker_loop ($exchange) { | ||
return Async\async(function () use ($exchange) { | ||
while (true) { | ||
$ticker = Async\await ($exchange->watch_ticker('BTC/USDT')); | ||
} | ||
}) (); | ||
}; | ||
|
||
|
||
function watch_order_book_for_symbols_loop($exchange) { | ||
return Async\async(function () use ($exchange) { | ||
while (true) { | ||
$trades = Async\await ( $exchange->watch_trades_for_symbols(['BTC/USDT', 'ETH/USDT', 'LTC/USDT'])); | ||
} | ||
}) (); | ||
}; | ||
|
||
|
||
function close_after ($exchange, $s) { | ||
return Async\async(function () use ($exchange, $s) { | ||
Async\delay ($s); | ||
$exchange->close(); | ||
}) (); | ||
}; | ||
|
||
|
||
$test_close = function () { | ||
$exchangeClass = '\\ccxt\\pro\\binance'; | ||
$exchange = new $exchangeClass(); | ||
$exchange->verbose = false; | ||
|
||
// -------------------------------------------- | ||
|
||
var_dump('Testing exchange.close(): No future awaiting, should close with no errors'); | ||
Async\await ($exchange->watch_ticker('BTC/USD')); | ||
var_dump('ticker received'); | ||
$exchange->close(); | ||
var_dump('PASSED - exchange closed with no errors'); | ||
|
||
// -------------------------------------------- | ||
|
||
var_dump('Testing exchange.close(): Awaiting future should throw ClosedByUser'); | ||
try { | ||
Async\await(Promise\all([ | ||
close_after($exchange, 5), | ||
watch_ticker_loop($exchange) | ||
])); | ||
} catch(\Throwable $e) { | ||
if ($e instanceof ExchangeClosedByUser) { | ||
var_dump('PASSED - future rejected with ClosedByUser'); | ||
} else { | ||
throw $e; | ||
} | ||
} | ||
|
||
// -------------------------------------------- | ||
|
||
var_dump('Test exchange.close(): Call watch_multiple unhandled futures are canceled'); | ||
try { | ||
Async\await(Promise\all([ | ||
close_after($exchange, 5), | ||
watch_order_book_for_symbols_loop($exchange) | ||
])); | ||
} catch(\Throwable $e) { | ||
if ($e instanceof ExchangeClosedByUser) { | ||
var_dump('PASSED - future rejected with ClosedByUser'); | ||
} else { | ||
throw $e; | ||
} | ||
} | ||
exit(0); | ||
}; | ||
|
||
|
||
\React\Async\coroutine($test_close); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
from asyncio import run, sleep, gather | ||
from ccxt.base.errors import ExchangeClosedByUser # noqa E402 | ||
import ccxt.pro | ||
|
||
async def watch_ticker_loop(exchange): | ||
while True: | ||
ticker = await exchange.watch_ticker('BTC/USDT') | ||
print('ticker received') | ||
|
||
|
||
async def watch_order_book_for_symbols_loop(exchange): | ||
while True: | ||
trades = await exchange.watch_trades_for_symbols(['BTC/USDT', 'ETH/USDT', 'LTC/USDT']) | ||
print('trades received') | ||
|
||
|
||
async def close_after(exchange, ms): | ||
await sleep(ms) | ||
await exchange.close() | ||
|
||
|
||
async def test_close(): | ||
exchange = ccxt.pro.binance() | ||
# exchange.verbose = True | ||
# -------------------------------------------- | ||
print('Testing exchange.close(): No future awaiting, should close with no errors') | ||
await exchange.watch_ticker('BTC/USD') | ||
print('ticker received') | ||
await exchange.close() | ||
print('PASSED - exchange closed with no errors') | ||
# -------------------------------------------- | ||
print('Testing exchange.close(): Open watch multiple, resolve, should close with no errors') | ||
await exchange.watch_trades_for_symbols(['BTC/USD', 'ETH/USD', 'LTC/USD']) | ||
print('ticker received') | ||
await exchange.close() | ||
print('PASSED - exchange closed with no errors') | ||
# -------------------------------------------- | ||
print('Testing exchange.close(): Awaiting future should throw ClosedByUser') | ||
try: | ||
await gather(close_after(exchange, 5), watch_ticker_loop(exchange)) | ||
except Exception as e: | ||
if isinstance(e, ExchangeClosedByUser): | ||
print('PASSED - future rejected with ClosedByUser') | ||
else: | ||
raise e | ||
# -------------------------------------------- | ||
print('Test exchange.close(): Call watch_multiple unhandled futures are canceled') | ||
try: | ||
await gather(close_after(exchange, 5), watch_order_book_for_symbols_loop(exchange)) | ||
except Exception as e: | ||
if isinstance(e, ExchangeClosedByUser): | ||
print('PASSED - future rejected with ClosedByUser') | ||
else: | ||
raise e | ||
exit(0) | ||
|
||
|
||
run(test_close()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ const errorHierarchy = { | |
'RequestTimeout': {}, | ||
}, | ||
}, | ||
'ExchangeClosedByUser': {}, | ||
}, | ||
}; | ||
|
||
|
Oops, something went wrong.