chore(): lint for trailing commas, fix tests with new types

This commit is contained in:
Tiago Siebler
2023-03-22 17:02:12 +00:00
parent 831689e857
commit e9972ef829
20 changed files with 86 additions and 85 deletions

View File

@@ -82,7 +82,7 @@ export default class WsStore<WsKey extends string> {
if (this.hasExistingActiveConnection(key)) {
this.logger.warning(
'WsStore setConnection() overwriting existing open connection: ',
this.getWs(key)
this.getWs(key),
);
}
this.wsState[key] = {
@@ -98,7 +98,7 @@ export default class WsStore<WsKey extends string> {
const ws = this.getWs(key);
this.logger.warning(
'WsStore deleting state for connection still open: ',
ws
ws,
);
ws?.close();
}
@@ -119,7 +119,7 @@ export default class WsStore<WsKey extends string> {
if (this.isWsOpen(key)) {
this.logger.warning(
'WsStore setConnection() overwriting existing open connection: ',
this.getWs(key)
this.getWs(key),
);
}

View File

@@ -11,7 +11,7 @@ function _arrayBufferToBase64(buffer: ArrayBuffer) {
export async function signMessage(
message: string,
secret: string,
method: 'hex' | 'base64'
method: 'hex' | 'base64',
): Promise<string> {
const encoder = new TextEncoder();
const key = await window.crypto.subtle.importKey(
@@ -19,20 +19,20 @@ export async function signMessage(
encoder.encode(secret),
{ name: 'HMAC', hash: { name: 'SHA-256' } },
false,
['sign']
['sign'],
);
const signature = await window.crypto.subtle.sign(
'HMAC',
key,
encoder.encode(message)
encoder.encode(message),
);
switch (method) {
case 'hex': {
return Array.prototype.map
.call(new Uint8Array(signature), (x: any) =>
('00' + x.toString(16)).slice(-2)
('00' + x.toString(16)).slice(-2),
)
.join('');
}

View File

@@ -4,7 +4,7 @@ import { createHmac } from 'crypto';
export async function signMessage(
message: string,
secret: string,
method: 'hex' | 'base64'
method: 'hex' | 'base64',
): Promise<string> {
const hmac = createHmac('sha256', secret).update(message);

View File

@@ -30,7 +30,7 @@ export interface RestClientOptions {
export function serializeParams<T extends object | undefined = {}>(
params: T,
strict_validation = false,
prefixWith: string = ''
prefixWith: string = '',
): string {
if (!params) {
return '';
@@ -42,7 +42,7 @@ export function serializeParams<T extends object | undefined = {}>(
const value = params[key];
if (strict_validation === true && typeof value === 'undefined') {
throw new Error(
'Failed to sign API request due to undefined parameter'
'Failed to sign API request due to undefined parameter',
);
}
return `${key}=${value}`;
@@ -55,7 +55,7 @@ export function serializeParams<T extends object | undefined = {}>(
export function getRestBaseUrl(
useTestnet: boolean,
restInverseOptions: RestClientOptions
restInverseOptions: RestClientOptions,
): string {
const exchangeBaseUrls = {
livenet: 'https://api.bitget.com',

View File

@@ -36,7 +36,7 @@ function isWsChannelEvent(event: WsBaseEvent): event is WsSnapshotChannelEvent {
/** TypeGuard: event is an account update (balance) */
export function isWsAccountSnapshotEvent(
event: unknown
event: unknown,
): event is WsSnapshotAccountEvent {
return (
isWsSnapshotEvent(event) &&
@@ -48,7 +48,7 @@ export function isWsAccountSnapshotEvent(
/** TypeGuard: event is a positions update */
export function isWsPositionsSnapshotEvent(
event: unknown
event: unknown,
): event is WsSnapshotPositionsEvent {
return (
isWsSnapshotEvent(event) &&
@@ -60,14 +60,14 @@ export function isWsPositionsSnapshotEvent(
/** TypeGuard: event is a UMCBL account update (balance) */
export function isWsFuturesAccountSnapshotEvent(
event: unknown
event: unknown,
): event is WsAccountSnapshotUMCBL {
return isWsAccountSnapshotEvent(event) && event.arg.instType === 'umcbl';
}
/** TypeGuard: event is a UMCBL positions update */
export function isWsFuturesPositionsSnapshotEvent(
event: unknown
event: unknown,
): event is WSPositionSnapshotUMCBL {
return isWsPositionsSnapshotEvent(event) && event.arg.instType === 'umcbl';
}

View File

@@ -11,7 +11,7 @@ import { BitgetInstType, WsTopicSubscribeEventArgs } from './WsStore';
*/
type NetworkMap<
TRequiredKeys extends string,
TOptionalKeys extends string | undefined = undefined
TOptionalKeys extends string | undefined = undefined,
> = Record<TRequiredKeys, string> &
(TOptionalKeys extends string
? Record<TOptionalKeys, string | undefined>
@@ -55,14 +55,14 @@ export const PUBLIC_WS_KEYS = [] as WsKey[];
export const PRIVATE_TOPICS = ['account', 'orders', 'positions', 'ordersAlgo'];
export function isPrivateChannel<TChannel extends string>(
channel: TChannel
channel: TChannel,
): boolean {
return PRIVATE_TOPICS.includes(channel);
}
export function getWsKeyForTopic(
subscribeEvent: WsTopicSubscribeEventArgs,
isPrivate?: boolean
isPrivate?: boolean,
): WsKey {
const instType = subscribeEvent.instType.toUpperCase() as BitgetInstType;
switch (instType) {
@@ -78,7 +78,7 @@ export function getWsKeyForTopic(
default: {
throw neverGuard(
instType,
`getWsKeyForTopic(): Unhandled market ${'instrumentId'}`
`getWsKeyForTopic(): Unhandled market ${'instrumentId'}`,
);
}
}
@@ -110,14 +110,14 @@ export async function getWsAuthSignature(
apiKey: string | undefined,
apiSecret: string | undefined,
apiPass: string | undefined,
recvWindow: number = 0
recvWindow: number = 0,
): Promise<{
expiresAt: number;
signature: string;
}> {
if (!apiKey || !apiSecret || !apiPass) {
throw new Error(
`Cannot auth - missing api key, secret or passcode in config`
`Cannot auth - missing api key, secret or passcode in config`,
);
}
const signatureExpiresAt = ((Date.now() + recvWindow) / 1000).toFixed(0);
@@ -125,7 +125,7 @@ export async function getWsAuthSignature(
const signature = await signMessage(
signatureExpiresAt + 'GET' + '/user/verify',
apiSecret,
'base64'
'base64',
);
return {