forked from igorek17000/alunajs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
102 lines (62 loc) · 1.66 KB
/
index.ts
File metadata and controls
102 lines (62 loc) · 1.66 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import compression from 'compression'
import express, {
Request,
Response,
} from 'express'
import { aluna } from '../src/aluna'
import {
IAlunaExchangeAuthed,
IAlunaExchangePublic,
} from '../src/lib/core/IAlunaExchange'
export function main() {
const port = 9090
const app = express()
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(compression({ level: 9 }))
app.get('/exchanges', handleExchangeCommands)
app.get('/web3', handleWeb3Commands)
app.listen(port)
console.info('Playground running at:', port)
}
export const handleExchangeCommands = async (req: Request, res: Response) => {
const {
exchangeId,
key,
secret,
passphrase,
method: scopeMethod,
...params
} = req.body
const [scope, method] = scopeMethod.split('.')
try {
let exchange: IAlunaExchangePublic | IAlunaExchangeAuthed
if (key && secret) {
const credentials = { key, secret, passphrase }
exchange = aluna(exchangeId, { credentials })
} else {
exchange = aluna(exchangeId)
}
const response = await exchange[scope][method](params)
console.info(response)
res.status(200).json(response)
} catch (error) {
res.status(200).json(error)
}
}
export const handleWeb3Commands = async (req: Request, res: Response) => {
const {
method: scopeMethod,
...params
} = req.body
const [scope, method] = scopeMethod.split('.')
try {
const web3 = aluna.web3()
const response = await web3[scope][method](params)
console.info(response)
res.status(200).json(response)
} catch (error) {
res.status(200).json(error)
}
}
main()