Advertisement
GlobalLiquidity

Untitled

Oct 10th, 2019
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export const SHRIMPY_API_KEY = '77f83febf27243f68c88b2db2fd19a2991f283803a0e38c061110885b5b6cf6e';
  2.  
  3. export const shrimpySignatureGenerator = (requestPath: string, method: string, nonce: Number, body?: object): string => {
  4.     // This is base64 encoded
  5.     const secret = '6ace4542baa020b467951f299f628820613983d0c159dff92843ded0835825ab9fa0617e13a0e0bfc066ade8f033cb9ddf008b3a8a3d7a8debb4c709896aa1a5';
  6.  
  7.     // create the prehash string by concatenating required parts
  8.     const prehashString = requestPath + method + nonce + (body || '');
  9.  
  10.     // decode the base64 secret
  11.     const key = new Buffer(secret, 'base64');
  12.  
  13.     // create a sha256 hmac with the secret
  14.     const hmac = crypto.createHmac('sha256', key);
  15.  
  16.     // hash the prehash string and base64 encode the result
  17.     return hmac.update(prehashString).digest('base64');
  18. }
  19.  
  20.  
  21.  
  22. async getToken()
  23.     {
  24.         Logger.log("ShrimpyMarketDataSource : Getting Token : ");
  25.  
  26.         let proxyUrl:string = 'http://52.14.231.154:8080/';
  27.         const url: string = `https://dev-api.shrimpy.io/v1/ws/token`;
  28.         const requestUrl = `/v1//ws/token`;
  29.         const nonce = Date.now();
  30.         const shrimpySignature = shrimpySignatureGenerator(requestUrl, 'GET', nonce);
  31.         const headers = {
  32.             'DEV-SHRIMPY-API-KEY': SHRIMPY_API_KEY,
  33.             'DEV-SHRIMPY-API-NONCE': nonce.toString(),
  34.             'DEV-SHRIMPY-API-SIGNATURE': shrimpySignature
  35.         };
  36.         const response: Response = await fetch(proxyUrl + url, {
  37.             method: 'GET',
  38.             headers
  39.         });
  40.         const token = await response.json();
  41.  
  42.         Logger.log("ShrimpyMarketDataSource : Got Token : " + token);
  43.  
  44.         this.shrimpySocketToken = token;
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement