per-exchange throttling
This commit is contained in:
parent
d64861acec
commit
c8576b433d
@ -509,7 +509,7 @@ export type PayCoinInfo = Array<{ updatedCoin: CoinRecord, sig: CoinPaySig }>;
|
|||||||
|
|
||||||
|
|
||||||
export namespace Amounts {
|
export namespace Amounts {
|
||||||
export const fractionalBase = 1e6;
|
export const fractionalBase = 1e8;
|
||||||
|
|
||||||
export interface Result {
|
export interface Result {
|
||||||
amount: AmountJson;
|
amount: AmountJson;
|
||||||
|
@ -380,6 +380,7 @@ export class Wallet {
|
|||||||
public cryptoApi: CryptoApi;
|
public cryptoApi: CryptoApi;
|
||||||
|
|
||||||
private processPreCoinConcurrent = 0;
|
private processPreCoinConcurrent = 0;
|
||||||
|
private processPreCoinThrottle: {[url: string]: number} = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set of identifiers for running operations.
|
* Set of identifiers for running operations.
|
||||||
@ -728,7 +729,7 @@ export class Wallet {
|
|||||||
|
|
||||||
private async processPreCoin(preCoin: PreCoinRecord,
|
private async processPreCoin(preCoin: PreCoinRecord,
|
||||||
retryDelayMs = 200): Promise<void> {
|
retryDelayMs = 200): Promise<void> {
|
||||||
if (this.processPreCoinConcurrent >= 1) {
|
if (this.processPreCoinConcurrent >= 4 || this.processPreCoinThrottle[preCoin.exchangeBaseUrl]) {
|
||||||
console.log("delaying processPreCoin");
|
console.log("delaying processPreCoin");
|
||||||
setTimeout(() => this.processPreCoin(preCoin, retryDelayMs * 2),
|
setTimeout(() => this.processPreCoin(preCoin, retryDelayMs * 2),
|
||||||
retryDelayMs);
|
retryDelayMs);
|
||||||
@ -793,6 +794,8 @@ export class Wallet {
|
|||||||
let nextRetryDelayMs = Math.min(retryDelayMs * 2, 1000 * 60);
|
let nextRetryDelayMs = Math.min(retryDelayMs * 2, 1000 * 60);
|
||||||
setTimeout(() => this.processPreCoin(preCoin, nextRetryDelayMs),
|
setTimeout(() => this.processPreCoin(preCoin, nextRetryDelayMs),
|
||||||
retryDelayMs);
|
retryDelayMs);
|
||||||
|
this.processPreCoinThrottle[preCoin.exchangeBaseUrl] = (this.processPreCoinThrottle[preCoin.exchangeBaseUrl] || 0) + 1;
|
||||||
|
setTimeout(() => {this.processPreCoinThrottle[preCoin.exchangeBaseUrl]--; }, retryDelayMs);
|
||||||
} finally {
|
} finally {
|
||||||
this.processPreCoinConcurrent--;
|
this.processPreCoinConcurrent--;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user