aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/order-watcher/CHANGELOG.json9
-rw-r--r--packages/order-watcher/src/index.ts1
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts10
-rw-r--r--packages/order-watcher/test/order_watcher_test.ts17
-rw-r--r--packages/types/src/index.ts4
5 files changed, 40 insertions, 1 deletions
diff --git a/packages/order-watcher/CHANGELOG.json b/packages/order-watcher/CHANGELOG.json
index ce56e492c..feebb9d69 100644
--- a/packages/order-watcher/CHANGELOG.json
+++ b/packages/order-watcher/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "version": "2.1.2",
+ "changes": [
+ {
+ "note": "Added getStats function and returns a Stats object",
+ "pr": 1118
+ }
+ ]
+ },
+ {
"version": "2.1.1",
"changes": [
{
diff --git a/packages/order-watcher/src/index.ts b/packages/order-watcher/src/index.ts
index d2f91eab1..8280c73a4 100644
--- a/packages/order-watcher/src/index.ts
+++ b/packages/order-watcher/src/index.ts
@@ -7,6 +7,7 @@ export {
OrderState,
ExchangeContractErrs,
OrderRelevantState,
+ Stats,
} from '@0xproject/types';
export { OnOrderStateChangeCallback, OrderWatcherConfig } from './types';
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index f9a63efe3..eb37bd617 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -30,7 +30,7 @@ import {
orderHashUtils,
OrderStateUtils,
} from '@0xproject/order-utils';
-import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder } from '@0xproject/types';
+import { AssetProxyId, ExchangeContractErrs, OrderState, SignedOrder, Stats } from '@0xproject/types';
import { errorUtils, intervalUtils } from '@0xproject/utils';
import { BlockParamLiteral, LogEntryEvent, LogWithDecodedArgs, Provider } from 'ethereum-types';
import * as _ from 'lodash';
@@ -213,6 +213,14 @@ export class OrderWatcher {
this._expirationWatcher.unsubscribe();
intervalUtils.clearAsyncExcludingInterval(this._cleanupJobIntervalIdIfExists);
}
+ /**
+ * Gets statistics of the OrderWatcher Instance.
+ */
+ public getStats(): Stats {
+ return {
+ orderCount: _.size(this._orderByOrderHash),
+ };
+ }
private async _cleanupAsync(): Promise<void> {
for (const orderHash of _.keys(this._orderByOrderHash)) {
this._cleanupOrderRelatedState(orderHash);
diff --git a/packages/order-watcher/test/order_watcher_test.ts b/packages/order-watcher/test/order_watcher_test.ts
index 60d9069e8..4545f84bf 100644
--- a/packages/order-watcher/test/order_watcher_test.ts
+++ b/packages/order-watcher/test/order_watcher_test.ts
@@ -140,6 +140,23 @@ describe('OrderWatcher', () => {
expect(() => orderWatcher.subscribe(_.noop.bind(_))).to.throw(OrderWatcherError.SubscriptionAlreadyPresent);
});
});
+ describe('#getStats', async () => {
+ it('orderCount should increment and decrement with order additions and removals', async () => {
+ signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerAssetData,
+ takerAssetData,
+ makerAddress,
+ takerAddress,
+ fillableAmount,
+ );
+ const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
+ expect(orderWatcher.getStats().orderCount).to.be.eq(0);
+ await orderWatcher.addOrderAsync(signedOrder);
+ expect(orderWatcher.getStats().orderCount).to.be.eq(1);
+ orderWatcher.removeOrder(orderHash);
+ expect(orderWatcher.getStats().orderCount).to.be.eq(0);
+ });
+ });
describe('tests with cleanup', async () => {
afterEach(async () => {
orderWatcher.unsubscribe();
diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts
index 6bc966ba1..d33048b61 100644
--- a/packages/types/src/index.ts
+++ b/packages/types/src/index.ts
@@ -620,3 +620,7 @@ export interface EIP712TypedData {
message: EIP712Object;
primaryType: string;
}
+
+export interface Stats {
+ orderCount: number;
+}