Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const SHRIMPY_API_KEY = '77f83febf27243f68c88b2db2fd19a2991f283803a0e38c061110885b5b6cf6e';
- export const shrimpySignatureGenerator = (requestPath: string, method: string, nonce: Number, body?: object): string => {
- // This is base64 encoded
- const secret = '6ace4542baa020b467951f299f628820613983d0c159dff92843ded0835825ab9fa0617e13a0e0bfc066ade8f033cb9ddf008b3a8a3d7a8debb4c709896aa1a5';
- // create the prehash string by concatenating required parts
- const prehashString = requestPath + method + nonce + (body || '');
- // decode the base64 secret
- const key = new Buffer(secret, 'base64');
- // create a sha256 hmac with the secret
- const hmac = crypto.createHmac('sha256', key);
- // hash the prehash string and base64 encode the result
- return hmac.update(prehashString).digest('base64');
- }
- async getToken()
- {
- Logger.log("ShrimpyMarketDataSource : Getting Token : ");
- let proxyUrl:string = 'http://52.14.231.154:8080/';
- const url: string = `https://dev-api.shrimpy.io/v1/ws/token`;
- const requestUrl = `/v1//ws/token`;
- const nonce = Date.now();
- const shrimpySignature = shrimpySignatureGenerator(requestUrl, 'GET', nonce);
- const headers = {
- 'DEV-SHRIMPY-API-KEY': SHRIMPY_API_KEY,
- 'DEV-SHRIMPY-API-NONCE': nonce.toString(),
- 'DEV-SHRIMPY-API-SIGNATURE': shrimpySignature
- };
- const response: Response = await fetch(proxyUrl + url, {
- method: 'GET',
- headers
- });
- const token = await response.json();
- Logger.log("ShrimpyMarketDataSource : Got Token : " + token);
- this.shrimpySocketToken = token;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement