@ex-master/core
Advanced tools
Comparing version 0.3.4 to 0.3.5
@@ -57,2 +57,3 @@ /// <reference types="node" /> | ||
export interface SpotClientOptions { | ||
isPrivateness?: boolean; | ||
dashboard?: Dashboard; | ||
@@ -65,2 +66,3 @@ } | ||
readonly dashboard: Dashboard; | ||
private isPrivateness; | ||
protected subscription: Subscription; | ||
@@ -72,3 +74,3 @@ private _destroyed; | ||
get balances(): Balance[]; | ||
constructor({ dashboard }?: SpotClientOptions); | ||
constructor({ dashboard, isPrivateness, }?: SpotClientOptions); | ||
abstract getMarkets(): Promise<SpotMarketData[]>; | ||
@@ -75,0 +77,0 @@ abstract getMarketQuotations(): Promise<MarketQuotation[]>; |
@@ -10,6 +10,7 @@ "use strict"; | ||
class SpotClient extends events_1.EventEmitter { | ||
constructor({ dashboard = dashboard_1.defaultDashboard } = {}) { | ||
constructor({ dashboard = dashboard_1.defaultDashboard, isPrivateness, } = {}) { | ||
super(); | ||
this.balanceUpdate$ = new rxjs_1.Subject(); | ||
this.orderUpdate$ = new rxjs_1.Subject(); | ||
this.isPrivateness = false; | ||
this.subscription = new rxjs_1.Subscription(); | ||
@@ -19,2 +20,3 @@ this._destroyed = false; | ||
this.dashboard = dashboard; | ||
this.isPrivateness = !!isPrivateness; | ||
this.ready = new Promise(nextTick => process.nextTick(nextTick)).then(() => this.initialize()); | ||
@@ -91,13 +93,15 @@ } | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
let balances = yield this.getBalances(); | ||
this.balanceMap.clear(); | ||
for (let balance of balances) { | ||
this.balanceMap.set(balance.currency, balance); | ||
if (this.isPrivateness) { | ||
let balances = yield this.getBalances(); | ||
this.balanceMap.clear(); | ||
for (let balance of balances) { | ||
this.balanceMap.set(balance.currency, balance); | ||
} | ||
this.subscription.add(this.balanceUpdate$.subscribe(({ currency, available, frozen }) => { | ||
let balance = this.getBalance(currency); | ||
balance.available = available || balance.available; | ||
balance.frozen = frozen || balance.frozen; | ||
return balance; | ||
})); | ||
} | ||
this.subscription.add(this.balanceUpdate$.subscribe(({ currency, available, frozen }) => { | ||
let balance = this.getBalance(currency); | ||
balance.available = available || balance.available; | ||
balance.frozen = frozen || balance.frozen; | ||
return balance; | ||
})); | ||
return new Promise(resolve => process.nextTick(resolve)).then(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
@@ -104,0 +108,0 @@ yield this.updateMarkets(); |
{ | ||
"name": "@ex-master/core", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"main": "bld/library/index.js", | ||
@@ -25,3 +25,3 @@ "types": "bld/library/index.d.ts", | ||
}, | ||
"gitHead": "ba7970b4124a958f0f03571f8e34589076fe5218" | ||
"gitHead": "ad2ebcc962f990af73526e6f8a2766b4d1ab2501" | ||
} |
@@ -83,2 +83,3 @@ import {EventEmitter} from 'events'; | ||
export interface SpotClientOptions { | ||
isPrivateness?: boolean; | ||
dashboard?: Dashboard; | ||
@@ -93,2 +94,3 @@ } | ||
private isPrivateness = false; | ||
protected subscription = new Subscription(); | ||
@@ -109,6 +111,10 @@ | ||
constructor({dashboard = defaultDashboard}: SpotClientOptions = {}) { | ||
constructor({ | ||
dashboard = defaultDashboard, | ||
isPrivateness, | ||
}: SpotClientOptions = {}) { | ||
super(); | ||
this.dashboard = dashboard; | ||
this.isPrivateness = !!isPrivateness; | ||
@@ -247,20 +253,22 @@ this.ready = new Promise(nextTick => process.nextTick(nextTick)).then(() => | ||
private async initialize(): Promise<void> { | ||
let balances = await this.getBalances(); | ||
if (this.isPrivateness) { | ||
let balances = await this.getBalances(); | ||
this.balanceMap.clear(); | ||
this.balanceMap.clear(); | ||
for (let balance of balances) { | ||
this.balanceMap.set(balance.currency, balance); | ||
} | ||
for (let balance of balances) { | ||
this.balanceMap.set(balance.currency, balance); | ||
} | ||
this.subscription.add( | ||
this.balanceUpdate$.subscribe(({currency, available, frozen}) => { | ||
let balance = this.getBalance(currency); | ||
this.subscription.add( | ||
this.balanceUpdate$.subscribe(({currency, available, frozen}) => { | ||
let balance = this.getBalance(currency); | ||
balance.available = available || balance.available; | ||
balance.frozen = frozen || balance.frozen; | ||
balance.available = available || balance.available; | ||
balance.frozen = frozen || balance.frozen; | ||
return balance; | ||
}), | ||
); | ||
return balance; | ||
}), | ||
); | ||
} | ||
@@ -267,0 +275,0 @@ return new Promise(resolve => process.nextTick(resolve)).then(async () => { |
Sorry, the diff of this file is not supported yet
35316
868