-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchBinance.ts
More file actions
46 lines (41 loc) · 1.41 KB
/
fetchBinance.ts
File metadata and controls
46 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
export const handler = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult> => {
const resource = (event as any).rawPath ?? `ping`;
const query = (event as any).rawQueryString ?? ``;
const method = (event.requestContext as any).http.method;
const url = `https://api.binance.com/api/v3${resource}${query ? `?${query}` : ''}`;
console.log(method, url);
try {
const response = await fetch(url, {
method,
headers: {
'x-mbx-apikey': (event.headers?.[`x-mbx-apikey`] as string) ?? ``,
},
});
let respText = '';
if (resource.includes('exchangeInfo')) {
const exInfo = await response.json();
exInfo.symbols = exInfo.symbols.map((s: any) => {
return {
symbol: s.symbol,
status: s.status,
filters: s.filters,
};
});
respText = JSON.stringify(exInfo);
} else {
respText = await response.text();
}
console.log(response.status, respText.slice(0, 1000));
return {
statusCode: response.status,
body: respText,
};
} catch (e) {
console.error(e);
return {
statusCode: 500,
body: e as string,
};
}
};