Skip to content

Commit 5c6655f

Browse files
committed
v0.1.0
0 parents  commit 5c6655f

File tree

14 files changed

+19336
-0
lines changed

14 files changed

+19336
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.aws-sam

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
parserOptions: {
4+
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
5+
sourceType: "module"
6+
},
7+
extends: [
8+
"plugin:@typescript-eslint/recommended", // recommended rules from the @typescript-eslint/eslint-plugin
9+
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
10+
],
11+
rules: {
12+
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
13+
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
14+
}
15+
};

.gitignore

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
samconfig.toml
2+
.idea
3+
4+
# Created by https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam
5+
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,node,linux,windows,sam
6+
7+
### Linux ###
8+
*~
9+
10+
# temporary files which can be created if a process still has a handle open of a deleted file
11+
.fuse_hidden*
12+
13+
# KDE directory preferences
14+
.directory
15+
16+
# Linux trash folder which might appear on any partition or disk
17+
.Trash-*
18+
19+
# .nfs files are created when an open file is removed but is still being accessed
20+
.nfs*
21+
22+
### Node ###
23+
# Logs
24+
logs
25+
*.log
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
lerna-debug.log*
30+
31+
# Diagnostic reports (https://nodejs.org/api/report.html)
32+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
33+
34+
# Runtime data
35+
pids
36+
*.pid
37+
*.seed
38+
*.pid.lock
39+
40+
# Directory for instrumented libs generated by jscoverage/JSCover
41+
lib-cov
42+
43+
# Coverage directory used by tools like istanbul
44+
coverage
45+
*.lcov
46+
47+
# nyc test coverage
48+
.nyc_output
49+
50+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
51+
.grunt
52+
53+
# Bower dependency directory (https://bower.io/)
54+
bower_components
55+
56+
# node-waf configuration
57+
.lock-wscript
58+
59+
# Compiled binary addons (https://nodejs.org/api/addons.html)
60+
build/Release
61+
62+
# Dependency directories
63+
node_modules/
64+
jspm_packages/
65+
66+
# TypeScript v1 declaration files
67+
typings/
68+
69+
# TypeScript cache
70+
*.tsbuildinfo
71+
72+
# Optional npm cache directory
73+
.npm
74+
75+
# Optional eslint cache
76+
.eslintcache
77+
78+
# Optional stylelint cache
79+
.stylelintcache
80+
81+
# Microbundle cache
82+
.rpt2_cache/
83+
.rts2_cache_cjs/
84+
.rts2_cache_es/
85+
.rts2_cache_umd/
86+
87+
# Optional REPL history
88+
.node_repl_history
89+
90+
# Output of 'npm pack'
91+
*.tgz
92+
93+
# Yarn Integrity file
94+
.yarn-integrity
95+
96+
# dotenv environment variables file
97+
.env
98+
.env.test
99+
.env*.local
100+
101+
# parcel-bundler cache (https://parceljs.org/)
102+
.cache
103+
.parcel-cache
104+
105+
# Next.js build output
106+
.next
107+
108+
# Nuxt.js build / generate output
109+
.nuxt
110+
dist
111+
112+
# Storybook build outputs
113+
.out
114+
.storybook-out
115+
storybook-static
116+
117+
# rollup.js default build output
118+
dist/
119+
120+
# Gatsby files
121+
.cache/
122+
# Comment in the public line in if your project uses Gatsby and not Next.js
123+
# https://nextjs.org/blog/next-9-1#public-directory-support
124+
# public
125+
126+
# vuepress build output
127+
.vuepress/dist
128+
129+
# Serverless directories
130+
.serverless/
131+
132+
# FuseBox cache
133+
.fusebox/
134+
135+
# DynamoDB Local files
136+
.dynamodb/
137+
138+
# TernJS port file
139+
.tern-port
140+
141+
# Stores VSCode versions used for testing VSCode extensions
142+
.vscode-test
143+
144+
# Temporary folders
145+
tmp/
146+
temp/
147+
148+
### OSX ###
149+
# General
150+
.DS_Store
151+
.AppleDouble
152+
.LSOverride
153+
154+
# Icon must end with two \r
155+
Icon
156+
157+
158+
# Thumbnails
159+
._*
160+
161+
# Files that might appear in the root of a volume
162+
.DocumentRevisions-V100
163+
.fseventsd
164+
.Spotlight-V100
165+
.TemporaryItems
166+
.Trashes
167+
.VolumeIcon.icns
168+
.com.apple.timemachine.donotpresent
169+
170+
# Directories potentially created on remote AFP share
171+
.AppleDB
172+
.AppleDesktop
173+
Network Trash Folder
174+
Temporary Items
175+
.apdisk
176+
177+
### SAM ###
178+
# Ignore build directories for the AWS Serverless Application Model (SAM)
179+
# Info: https://aws.amazon.com/serverless/sam/
180+
# Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html
181+
182+
**/.aws-sam
183+
184+
### Windows ###
185+
# Windows thumbnail cache files
186+
Thumbs.db
187+
Thumbs.db:encryptable
188+
ehthumbs.db
189+
ehthumbs_vista.db
190+
191+
# Dump file
192+
*.stackdump
193+
194+
# Folder config file
195+
[Dd]esktop.ini
196+
197+
# Recycle Bin used on file shares
198+
$RECYCLE.BIN/
199+
200+
# Windows Installer files
201+
*.cab
202+
*.msi
203+
*.msix
204+
*.msm
205+
*.msp
206+
207+
# Windows shortcuts
208+
*.lnk
209+
210+
# End of https://www.toptal.com/developers/gitignore/api/osx,node,linux,windows,sam

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/*

.prettierrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: "all",
4+
singleQuote: true,
5+
printWidth: 120,
6+
tabWidth: 4
7+
};

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# binance-rest-api-proxy
2+
3+
A service which proxies any Binance REST API calls to make them originate from a region you like.
4+
Default configuration creates AWS Lambda function and URL in eu-west-3 (Paris) region. This can be changed in the package.json.
5+
6+
## Usage
7+
8+
* You need AWS CLI installed and configured (search AWS Docs to do it).
9+
* You need AWS `sam` CLI tool (search AWS Docs to do it).
10+
* You will probably need Docker Desktop installed.
11+
12+
1. `npm install`
13+
2. `npm run deploy`
14+
15+
If everything is deployed you will get the service URL in the terminal.
16+
Now, using this URL you can make any requests to Binance REST API, by replacing `https://api.binance.com/api/v3/` with this URL in requests:
17+
* `https://api.binance.com/api/v3/ticker/price` -> `<ServiceURL>/ticker/price`
18+
19+
It supports all Binance REST API requests that do not include HTML body.
20+
It supports the `x-mbx-apikey` HTTP header.
21+
22+
If you fill like this project helped you, you can support me on Patreon:
23+
* [patreon.com/bogdantimes](https://patreon.com/bogdantimes)
24+
25+
🫡

events/event.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"requestContext": {
3+
"http": { "method": "GET" },
4+
},
5+
"headers": {},
6+
"rawPath": "/ticker/price",
7+
"rawQueryString": "symbol=BTCBUSD",
8+
}

fetchBinance.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
2+
3+
export const handler = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult> => {
4+
console.log(`Event: ${JSON.stringify(event, null, 2)}`);
5+
6+
const resource = (event as any).rawPath ?? `ping`;
7+
const query = (event as any).rawQueryString ?? ``;
8+
const method = (event.requestContext as any).http.method;
9+
const url = `https://api.binance.com/api/v3${resource}?${query}`;
10+
11+
console.log(method, url);
12+
13+
const binanceRequest = fetch(url, {
14+
method,
15+
headers: {
16+
'x-mbx-apikey': (event.headers?.[`x-mbx-apikey`] as string) ?? ``,
17+
},
18+
});
19+
20+
return await binanceRequest
21+
.then(async (binanceResponse) => {
22+
return await binanceResponse
23+
.text()
24+
.then((text) => {
25+
return {
26+
statusCode: binanceResponse.status,
27+
body: text,
28+
};
29+
})
30+
.catch((error) => {
31+
return {
32+
statusCode: 500,
33+
body: error,
34+
};
35+
});
36+
})
37+
.catch((error) => {
38+
return {
39+
statusCode: 500,
40+
body: error,
41+
};
42+
});
43+
};

jest.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
export default {
7+
transform: {
8+
'^.+\\.ts?$': 'esbuild-jest',
9+
},
10+
clearMocks: true,
11+
collectCoverage: true,
12+
coverageDirectory: 'coverage',
13+
coverageProvider: 'v8',
14+
testMatch: ['**/tests/unit/*.test.ts'],
15+
};

0 commit comments

Comments
 (0)