清理缓存的委托单 - purgeCachedOrders
对于长时间运行的交易所实例,及时清理不再需要的资源是非常重要的。
因为在活跃的交易当中,.orders
缓存会增长到非常大,ccxt库提供了
purgeCachedOrders
/purge_cached_orders
方法来清理缓存中较早的
非敞口委托单以释放占用的内存或其他目的,清理选择条件如下:
where (order['timestamp'] < before) && (order['status'] != 'open')
清理命令接受一个参数来声明具体的清理条件。示例代码如下:
JavaScript:
// keep last 24 hours of history in cache
before = exchange.milliseconds () - 24 * 60 * 60 * 1000
// purge all closed and canceled orders "older" or issued "before" that time
exchange.purgeCachedOrders (before)
Python:
# keep last hour of history in cache
before = exchange.milliseconds () - 1 * 60 * 60 * 1000
# purge all closed and canceled orders "older" or issued "before" that time
exchange.purge_cached_orders (before)
PHP:
// keep last 24 hours of history in cache
$before = $exchange->milliseconds () - 24 * 60 * 60 * 1000;
// purge all closed and canceled orders "older" or issued "before" that time
$exchange->purge_cached_orders ($before);