-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
52 lines (42 loc) · 1.11 KB
/
bot.js
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
const CryptoJS = require("crypto-js");
require("dotenv").config();
// Crate a .env file with the API_KEY and API_SECRET values
const apiKey = process.env.API_KEY;
const apiSecret = process.env.API_SECRET;
const action = "order_new";
const mode = "market";
const type = "buy";
const amountBRL = process.env.AMOUNT_BRL;
const timestamp = Math.floor(Date.now() / 1000);
const body = {
timestamp,
mode,
type,
total: amountBRL,
};
const queryString = new URLSearchParams(body);
const signature = CryptoJS.HmacSHA256(
queryString.toString(),
apiSecret
).toString(); // Using CryptoJS library
const url = "https://bitnuvem.com/tapi/" + action;
const fetchData = async () => {
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
api_key: apiKey,
request_body: queryString.toString(),
signature: signature,
}).toString(),
});
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
};
fetchData();