Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(base) - safeIntegerOmitZero #22244

Merged
merged 6 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions ts/src/base/Exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,17 @@ export default class Exchange {
return res === 0;
}

safeIntegerOmitZero (obj: object, key: IndexType, defaultValue: Int = undefined): Int {
const timestampString = this.omitZero (this.safeString (obj, key));
let timestamp = undefined;
if (timestampString !== undefined) {
timestamp = this.parseToInt (timestampString);
carlosmiei marked this conversation as resolved.
Show resolved Hide resolved
} else if (defaultValue !== undefined) {
timestamp = defaultValue;
}
return timestamp;
}

afterConstruct () {
this.createNetworksByIdObject ();
}
Expand Down
6 changes: 1 addition & 5 deletions ts/src/bitget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2630,11 +2630,7 @@ export default class bitget extends Exchange {
//
const marketId = this.safeString (ticker, 'symbol');
const close = this.safeString (ticker, 'lastPr');
const timestampString = this.omitZero (this.safeString (ticker, 'ts')); // exchange sometimes provided 0
let timestamp = undefined;
if (timestampString !== undefined) {
timestamp = this.parseToInt (timestampString);
}
const timestamp = this.safeIntegerOmitZero (ticker, 'ts'); // exchange bitget provided 0
const change = this.safeString (ticker, 'change24h');
const open24 = this.safeString (ticker, 'open24');
const open = this.safeString (ticker, 'open');
Expand Down
2 changes: 1 addition & 1 deletion ts/src/latoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ export default class latoken extends Exchange {
//
const marketId = this.safeString (ticker, 'symbol');
const last = this.safeString (ticker, 'lastPrice');
const timestamp = this.safeInteger (ticker, 'updateTimestamp');
const timestamp = this.safeIntegerOmitZero (ticker, 'updateTimestamp'); // sometimes latoken provided '0' ts from /ticker endpoint
return this.safeTicker ({
'symbol': this.safeSymbol (marketId, market),
'timestamp': timestamp,
Expand Down