Untitled
unknown
plain_text
2 years ago
1.6 kB
2
Indexable
//copy everything from here and below //pair you want to trade; other examples 'adausdt' 'ethusdt' const pair = 'btcusdt'; // ENTER your access id const ACCESS_ID = 'yourAccessIDHere'; // ENTER your secret key const SECRET_KEY = 'yourSecretKeyHere'; //related to libraries for connecting to API const crypto = require('crypto'); const Axios = require('axios'); //helps with formatting function createDictText(params) { var keys = Object.keys(params).sort(); var qs = keys[0] + '=' + params[keys[0]]; for (var i = 1; i < keys.length; i++) { qs += '&' + keys[i] + '=' + params[keys[i]]; } return qs; } function createAuthorization(params) { var text = createDictText(params) + '&secret_key=' + SECRET_KEY; return crypto.createHash('md5').update(text).digest('hex').toUpperCase(); } const axios = Axios.create({ baseURL: 'https://api.coinex.com/v1', headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36', post: { 'Content-Type': 'application/json', }, }, timeout: 10000, }); // async function getLast() { //paramters for getting last price const params3 = { market: pair, }; //submit get request for last price const res3 = await axios.get('/market/ticker', { headers: { authorization: createAuthorization(params3), }, params: params3, }); //specifying variables for data let lastPrice = res3.data.data.ticker.last; //print data console.log('Last: ', lastPrice); } getLast();