API Example Scripts
Here are a few examples of some useful real-life scripts that could be implemented using the HollaEx API
Here are some more complex scripts that following the process on the previous page could be implemented and make your life easier.
Get Sign Ups
Retrieve the number of user sign-ups per month
const hollaex = require("hollaex-node-lib");
const client = new hollaex({
apiURL: "<YOUR_EXCHANGES_URL>",
apiKey: "<USER_API_KEY>",
apiSecret: "<USER_API_KEY_SECRET>",
});
//Get the number of exchange user signups by each month.
const getSignups = async () => {
try {
const months= ["January","February","March","April","May","June",
"July", "August","September","October","November","December"];
const signups = {};
for(let i = 0; i < months.length; i++) {
const date = new Date();
const month = date.setMonth(date.getMonth() - i);
code
const res = await client.getExchangeUsers({ startDate: new Date(month) });
signups[`${months[date.getMonth()]}- ${date.getFullYear()}`] = res.data.length;
}
return signups;
} catch (error) {
return error.message;
}
}
getSignups().then(res => console.log(res);
Reward New Users with USDT
Once users verify their account, deposit 5 USDT into their USDT wallet
const hollaex = require("hollaex-node-lib");
const client = new hollaex({
apiURL: "<YOUR_EXCHANGES_URL>",
apiKey: "<USER_API_KEY>",
apiSecret: "<USER_API_KEY_SECRET>",
});
//Get newly registered users of last month and give them 5 USDT gift.
const sendUsdtToVerifiedUsers = async () => {
try {
const date = new Date();
const lastMonth = date.setMonth(date.getMonth() - 1);
const res = await client.getExchangeUsers({ startDate: new Date(lastMonth) });
for(const user of res.data) {
await client.createExchangeDeposit(user.id, 'usdt', 5);
}
} catch (error) {
return error.message;
}
}
sendUsdtToVerifiedUsers().then(res => console.log(res);
Alert Admin to Large Deposits
Notify the admin by email if a deposit of over $10,000 worth is made, and give the details of the deposit
const hollaex = require("hollaex-node-lib");
const client = new hollaex({
apiURL: "<YOUR_EXCHANGES_URL>",
wsURL: "<YOUR_EXCHANGE_WS_URL>",
apiKey: "<USER_API_KEY>",
apiSecret: "<USER_API_KEY_SECRET>",
});
//Send a custom alert email to the exchange administrator if there is a deposit of more than $10,000 to the exchange of any coin.
const sendCustomAlertMail = async () => {
try {
const date = new Date();
const lastMonth = date.setMonth(date.getMonth() - 1);
const deposits = await client.getExchangeDeposits({ format:'all', startDate: new Date(lastMonth) });
const conversions = await client.getOraclePrice([...new Set(deposits.data.map(deposit => deposit.currency))], { quote: 'usdt', amount: 1 });
for(const deposit of deposits.data) {
if(conversions[deposit.currency] * deposit.amount > 10000) {
await client.sendExchangeUserEmail(1, "alert",
{
"type": "Deposit more than $10,000 detected",
"data": `We detected a deposit worth more than $10,000 from last month,
Currency: ${deposit.currency}, Amount: $${conversions[deposit.currency] * deposit.amount}, User_id: $${deposit.user_id}, Deposit creation date: ${deposit.created_at}`
})
}
}
} catch (error) {
return error.message;
}
}
sendCustomAlertMail().then(res => console.log(res);
Send Custom HTML Email to New Users
With the HTML of an email contained in a variable, send this HTML as an email to all new users
const hollaex = require("hollaex-node-lib");
const client = new hollaex({
apiURL: "<YOUR_EXCHANGES_URL>",
apiKey: "<USER_API_KEY>",
apiSecret: "<USER_API_KEY_SECRET>",
});
//Send a custom raw email every day to users who signed up with the last 24 hours to welcome them to the exchange.
const sendCustomRawEmail = async () => {
try {
const date = new Date();
const last24Hours = date.setHours(date.getHours() - 24);
let users = await client.getExchangeUsers({ startDate: new Date(last24Hours) })
const htmlContent = "<div><b>Welcome to the exchange again!</b></div>";
await client.sendRawEmail(
users.data.map(user => user.email),
htmlContent,
{ title : 'Welcome' });
} catch (error) {
return error.message;
}
}
sendCustomRawEmail().then(res => console.log(res);
Find the Most Active Trader
Find the user who has traded the highest volume over all assets in the past month
const hollaex = require("hollaex-node-lib");
const client = new hollaex({
apiURL: "<YOUR_EXCHANGES_URL>",
apiKey: "<USER_API_KEY>",
apiSecret: "<USER_API_KEY_SECRET>",
});
// Find the most active trader on the exchange with the highest volume in the last one month of exchange operation.
const getTradeWithMostVolume = async () => {
try {
const date = new Date();
const lastMonth = date.setMonth(date.getMonth() - 1);
let trades = await client.getExchangeTrades({ startDate: new Date(lastMonth), format: 'all' });
const userVolumes = {}
const coins = [];
const setUserVolumes = (traderId, symbol, size) => {
if(!userVolumes[traderId]) userVolumes[traderId] = {}
if(!userVolumes[traderId][symbol]) userVolumes[traderId][symbol] = 0;
userVolumes[traderId][symbol] += size
}
if(trades.data.length > 0){
for (const trade of trades.data) {
const tradeCoin = trade?.symbol?.split('-')?.[0];
if(!coins.includes(tradeCoin)) coins.push(tradeCoin);
if (trade.maker_id != null && !isNaN(trade.maker_id)) {
setUserVolumes(trade.maker_id, tradeCoin, trade.size);
}
if (trade.taker_id != null && !isNaN(trade.taker_id)) {
setUserVolumes(trade.taker_id, tradeCoin, trade.size);
}
}
const conversions = await client.getOraclePrice(coins, { quote: 'usdt', amount: 1 });
let highestTrader = { userId: null, volume: 0 };
for ([userId, tradeObject] of Object.entries(userVolumes)) {
for ([symbol, size] of Object.entries(tradeObject)) {
const conversion = conversions[symbol] * size;
userVolumes[userId][symbol] = conversion;
if (highestTrader.volume < conversion) {
highestTrader.userId = userId;
highestTrader.coin = symbol;
highestTrader.volume =conversion;
}
}
}
return highestTrader;
}
else { return 'Trade not found'; }
} catch (error) {
return error.message;
}
}
getTradeWithMostVolume().then(res => console.log(res);
Last updated