62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import crypto from 'crypto';
|
|
|
|
export interface AuthLoginResponse {
|
|
accessToken: string;
|
|
mdAccessToken: string;
|
|
expirationTime: string;
|
|
userStatus: string;
|
|
userId: number;
|
|
name: string;
|
|
hasLive: boolean;
|
|
hasSimPlus: boolean;
|
|
hasFunded: boolean;
|
|
hasMarketData: boolean;
|
|
requiredNonProCertification: boolean;
|
|
outdatedSentimentPolicy: boolean;
|
|
orgName: string;
|
|
}
|
|
|
|
export interface AccountItem {
|
|
id: number;
|
|
name: string;
|
|
userId: number;
|
|
accountType: string;
|
|
restricted: boolean;
|
|
closed: boolean;
|
|
clearingHouseId: number;
|
|
riskCategoryId: number;
|
|
autoLiqProfileId: number;
|
|
marginAccountType: string;
|
|
legalStatus: string;
|
|
archived: boolean;
|
|
timestamp: string;
|
|
active: boolean;
|
|
}
|
|
|
|
export interface Contract {
|
|
id: number;
|
|
name: string;
|
|
contractMaturityId: number;
|
|
timestamp: string;
|
|
status: string;
|
|
providerTickSize: number;
|
|
}
|
|
|
|
export const randomUUIDV4 = () => {
|
|
return crypto.randomUUID();
|
|
};
|
|
|
|
export const computeSec = (user: string, password: string, deviceId: string, chl: string) => {
|
|
const key = '035a1259-11e7-485a-aeae-9b6016579351';
|
|
const Ct = ['chl', 'deviceId', 'name', 'password', 'appId'];
|
|
const body = {
|
|
chl: chl,
|
|
deviceId: deviceId,
|
|
name: user,
|
|
password: password,
|
|
appId: 'tradovate_trader(web)',
|
|
};
|
|
const msg = Ct.map((k) => body[k] ?? '').join('');
|
|
return crypto.createHmac('sha256', key).update(msg, 'utf8').digest('hex');
|
|
};
|