@ex-master/core
Advanced tools
Comparing version 0.2.26 to 0.2.27
@@ -26,4 +26,6 @@ /// <reference types="node" /> | ||
export declare abstract class Client extends EventEmitter { | ||
private _destroyed; | ||
abstract balance$: Observable<Map<string, AccountBalance>>; | ||
abstract orderUpdate$: Observable<Order>; | ||
get destroyed(): boolean; | ||
/** Provide depth information, with replay set to CLIENT_DEPTH_REPLAY. */ | ||
@@ -49,2 +51,3 @@ /** Provide trade information, with replay set to CLIENT_TRADE_REPLAY. */ | ||
cancelOrders(orders: OrderQuery[]): Promise<void>; | ||
destroy(): void; | ||
} |
@@ -17,3 +17,7 @@ "use strict"; | ||
super(); | ||
this._destroyed = false; | ||
} | ||
get destroyed() { | ||
return this._destroyed; | ||
} | ||
testFatalError(_error) { } | ||
@@ -49,4 +53,7 @@ /** | ||
} | ||
destroy() { | ||
this._destroyed = true; | ||
} | ||
} | ||
exports.Client = Client; | ||
//# sourceMappingURL=client.js.map |
@@ -14,3 +14,3 @@ import { Subject } from 'rxjs'; | ||
constructor(options: BalanceAccumulatorOptions); | ||
readonly activeOrders: Order[]; | ||
get activeOrders(): Order[]; | ||
getActiveOrder(id: string): Order | undefined; | ||
@@ -17,0 +17,0 @@ onOrderCreate(order: Order): void; |
export * from './balance-accumulator'; | ||
export * from './websocket-connection'; |
@@ -5,3 +5,2 @@ "use strict"; | ||
tslib_1.__exportStar(require("./balance-accumulator"), exports); | ||
tslib_1.__exportStar(require("./websocket-connection"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -68,4 +68,5 @@ /// <reference types="node" /> | ||
private pendingUpdatesPriorityScale; | ||
private subscription; | ||
constructor(client: Client, dashboard: Dashboard, { pendingUpdatesPriorityScale }?: ExchangeOptions); | ||
readonly markets: Market[]; | ||
get markets(): Market[]; | ||
getMarketData({ stock, money }: Market): MarketData | undefined; | ||
@@ -76,2 +77,3 @@ initialize(): Promise<void>; | ||
getActiveOrders(group?: string): ActiveOrder[]; | ||
destroy(): void; | ||
updateOrders(group: string, descriptors: OrderDescriptor[]): Promise<void>; | ||
@@ -78,0 +80,0 @@ getMinOrderSize({ stock, money }: Market): Decimal; |
@@ -28,2 +28,3 @@ "use strict"; | ||
this.groupToLockObjectMap = new Map(); | ||
this.subscription = new rxjs_1.Subscription(); | ||
this.pendingUpdatesPriorityScale = pendingUpdatesPriorityScale; | ||
@@ -45,3 +46,3 @@ } | ||
yield this.cancelActiveOrders(); | ||
this.client.orderUpdate$.subscribe(order => { | ||
this.subscription.add(this.client.orderUpdate$.subscribe(order => { | ||
let { id, active, filledSize, filledValue, paidFee } = order; | ||
@@ -61,3 +62,3 @@ let activeOrderMap = this.activeOrderMap; | ||
if (active) { | ||
let newActiveOrder = Object.assign({}, activeOrder, { filledSize, | ||
let newActiveOrder = Object.assign(Object.assign({}, activeOrder), { filledSize, | ||
filledValue, | ||
@@ -75,6 +76,6 @@ paidFee }); | ||
} | ||
}); | ||
this.client.balance$.subscribe(map => { | ||
})); | ||
this.subscription.add(this.client.balance$.subscribe(map => { | ||
this.balanceMap = map; | ||
}); | ||
})); | ||
yield this.client.initialize(this); | ||
@@ -109,2 +110,11 @@ clearTimeout(timeoutTimer); | ||
} | ||
destroy() { | ||
this.subscription.unsubscribe(); | ||
this.pendingOrderTaskMap.clear(); | ||
this.activeOrderMap.clear(); | ||
this.balanceMap.clear(); | ||
this.groupToLockObjectMap.clear(); | ||
this._markets = []; | ||
this.client.destroy(); | ||
} | ||
updateOrders(group, descriptors) { | ||
@@ -188,3 +198,3 @@ return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (activeOrderMap.has(id)) { | ||
activeOrderMap.set(id, Object.assign({}, order, { canceling: Date.now() })); | ||
activeOrderMap.set(id, Object.assign(Object.assign({}, order), { canceling: Date.now() })); | ||
yield this.client.cancelOrder(order); | ||
@@ -215,3 +225,3 @@ } | ||
} | ||
activeOrderMap.set(order.id, Object.assign({}, order, { canceling: now })); | ||
activeOrderMap.set(order.id, Object.assign(Object.assign({}, order), { canceling: now })); | ||
pendingCancelOrders.push(order); | ||
@@ -309,3 +319,3 @@ } | ||
active, | ||
descriptor: Object.assign({}, descriptor, { priority, label }), | ||
descriptor: Object.assign(Object.assign({}, descriptor), { priority, label }), | ||
}; | ||
@@ -410,3 +420,3 @@ }) | ||
} | ||
return !!(yield this.order(group, label, Object.assign({}, descriptor, { size }), { limitMaker: descriptor.limitMaker, cid: descriptor.cid })); | ||
return !!(yield this.order(group, label, Object.assign(Object.assign({}, descriptor), { size }), { limitMaker: descriptor.limitMaker, cid: descriptor.cid })); | ||
}); | ||
@@ -413,0 +423,0 @@ } |
export * from './object'; | ||
export * from './async'; | ||
export * from './controller'; | ||
export * from './number'; |
@@ -6,4 +6,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./async"), exports); | ||
tslib_1.__exportStar(require("./controller"), exports); | ||
tslib_1.__exportStar(require("./number"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@ex-master/core", | ||
"version": "0.2.26", | ||
"version": "0.2.27", | ||
"main": "bld/library/index.js", | ||
@@ -15,2 +15,3 @@ "types": "bld/library/index.d.ts", | ||
"peerDependencies": { | ||
"@ex-master/utilities": "^0.1.0", | ||
"rxjs": "^6.0.0" | ||
@@ -20,3 +21,3 @@ }, | ||
"debug": "^3.1.0", | ||
"decimal.js": "^10.0.0", | ||
"decimal.js": "^10.1.1", | ||
"extendable-error": "^0.1.5", | ||
@@ -31,3 +32,3 @@ "http-proxy-agent": "^2.1.0", | ||
}, | ||
"gitHead": "80af01bee4a450c817cb2d51ee008136e795d1c9" | ||
"gitHead": "9a6b529276a4f25beedc8f77b34ebfa57ed0a6ee" | ||
} |
@@ -42,5 +42,11 @@ import {EventEmitter} from 'events'; | ||
export abstract class Client extends EventEmitter { | ||
private _destroyed = false; | ||
abstract balance$: Observable<Map<string, AccountBalance>>; | ||
abstract orderUpdate$: Observable<Order>; | ||
get destroyed(): boolean { | ||
return this._destroyed; | ||
} | ||
/** Provide depth information, with replay set to CLIENT_DEPTH_REPLAY. */ | ||
@@ -119,2 +125,6 @@ // abstract readonly depth$: Observable<DepthData>; | ||
} | ||
destroy(): void { | ||
this._destroyed = true; | ||
} | ||
} |
export * from './balance-accumulator'; | ||
export * from './websocket-connection'; |
@@ -10,2 +10,3 @@ import {EventEmitter} from 'events'; | ||
Observable, | ||
Subscription, | ||
} from 'rxjs'; | ||
@@ -129,2 +130,4 @@ import {debounce, distinctUntilChanged, map, shareReplay} from 'rxjs/operators'; | ||
private subscription = new Subscription(); | ||
constructor( | ||
@@ -156,47 +159,51 @@ readonly client: Client, | ||
this.client.orderUpdate$.subscribe(order => { | ||
let {id, active, filledSize, filledValue, paidFee} = order; | ||
this.subscription.add( | ||
this.client.orderUpdate$.subscribe(order => { | ||
let {id, active, filledSize, filledValue, paidFee} = order; | ||
let activeOrderMap = this.activeOrderMap; | ||
let activeOrder = activeOrderMap.get(id); | ||
let activeOrderMap = this.activeOrderMap; | ||
let activeOrder = activeOrderMap.get(id); | ||
if (!activeOrder) { | ||
let {type, market, size, price} = order; | ||
let pendingOrderTask = this.pendingOrderTaskMap.get( | ||
generatePendingOrderTaskKey(type, market, size, price), | ||
); | ||
if (!activeOrder) { | ||
let {type, market, size, price} = order; | ||
let pendingOrderTask = this.pendingOrderTaskMap.get( | ||
generatePendingOrderTaskKey(type, market, size, price), | ||
); | ||
if (pendingOrderTask && Date.now() < pendingOrderTask.expiredAt) { | ||
pendingOrderTask.done(order); | ||
if (pendingOrderTask && Date.now() < pendingOrderTask.expiredAt) { | ||
pendingOrderTask.done(order); | ||
return; | ||
} | ||
this.dashboard.info( | ||
`order ${id} has not been tracked by this exchange.`, | ||
); | ||
return; | ||
} | ||
this.dashboard.info( | ||
`order ${id} has not been tracked by this exchange.`, | ||
); | ||
return; | ||
} | ||
if (active) { | ||
let newActiveOrder = { | ||
...activeOrder, | ||
filledSize, | ||
filledValue, | ||
paidFee, | ||
}; | ||
if (active) { | ||
let newActiveOrder = { | ||
...activeOrder, | ||
filledSize, | ||
filledValue, | ||
paidFee, | ||
}; | ||
if (!isEqual(activeOrder, newActiveOrder)) { | ||
this.dashboard.info(`order ${id} updated`); | ||
activeOrderMap.set(id, newActiveOrder); | ||
if (!isEqual(activeOrder, newActiveOrder)) { | ||
this.dashboard.info(`order ${id} updated`); | ||
activeOrderMap.set(id, newActiveOrder); | ||
} | ||
} else { | ||
activeOrderMap.delete(id); | ||
this.dashboard.info(`order ${id} became inactive`); | ||
activeOrder.becomeInactiveResolver(order); | ||
} | ||
} else { | ||
activeOrderMap.delete(id); | ||
this.dashboard.info(`order ${id} became inactive`); | ||
activeOrder.becomeInactiveResolver(order); | ||
} | ||
}); | ||
}), | ||
); | ||
this.client.balance$.subscribe(map => { | ||
this.balanceMap = map; | ||
}); | ||
this.subscription.add( | ||
this.client.balance$.subscribe(map => { | ||
this.balanceMap = map; | ||
}), | ||
); | ||
@@ -247,2 +254,13 @@ await this.client.initialize(this); | ||
destroy(): void { | ||
this.subscription.unsubscribe(); | ||
this.pendingOrderTaskMap.clear(); | ||
this.activeOrderMap.clear(); | ||
this.balanceMap.clear(); | ||
this.groupToLockObjectMap.clear(); | ||
this._markets = []; | ||
this.client.destroy(); | ||
} | ||
async updateOrders( | ||
@@ -249,0 +267,0 @@ group: string, |
export * from './object'; | ||
export * from './async'; | ||
export * from './controller'; | ||
export * from './number'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 4 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
1
0
108879
12
65
2220
Updateddecimal.js@^10.1.1