Creating and Monitoring a Sell Order

Creating buy and sell orders is, of course, a fairly vital part of the crypto industry and here we will look at how we can interact with this core functionality

Let's get straight into the script and see how to create a sell order, and then view it.

Account A from before will be creating a market sell order for 10 XHT.

As before, check comments for explanations

//using the index file, get access to the functions we will be using throughout
//Note: make sure the index file is pointed in the correct relative folder to this
//script
const Network = require('./index');

const network = new Network({
    apiUrl: 'https://api.hollaex.network',
    apiKey: '<YOUR_API_KEY>',
    apiSecret: '<YOUR_API__SECRET_KEY>',
    activation_code: '<YOUR_ACTIVATION_CODE>',
});

//main function for adding user and their address
(async () => {
	try {
		//initialise the network
		const init = await network.init();

		//account's IDs
		let idAccountA = 2275;

		//balance before the sell order
		console.log(await network.getUserBalance(idAccountA));

		//fee data (in percentages ie. 0.03 = 0.03% fee)
		let feeData = { fee_structure: { maker: 0.03, taker: 0.03 } };
		//create the order
		await network.createOrder(
			idAccountA, 	//account placing order
			'xht-usdt', 	//symbol of market
			'sell',		//type of order
			10,		//order amount
			'market',	//type of order (limit/ market)
			undefined,	//limit if limit order
			feeData		//feeobject from above
		);

		//balance after the order
		console.log(await network.getUserBalance(idAccountA));

		//see what trades this user has completed
		console.log(await network.getUserTrades(idAccountA));

		//see what active orders this user has
		console.log(await network.getUserOrders(idAccountA));
	} catch (err) {
		console.log(err);
	}
})();

Transfer Assets Script: The Output

As before edited lines for readability, shortened sections noted with '~~':

//Account A before the sell order (line 23)
{ //~~other coin balances~~
  usdt_balance: 14.474006, //initially about 14 XHT
  usdt_available: 14.474006,
  xht_balance: 27.994,     //initially about 28 XHT
  xht_available: 27.994, 
  //~~other coin balances~~
  }
  
  //Here the order is placed, and due to being on the testnet,
  //is instantly snapped up!
  
//Account A after the sell order's completion (line 39)
{ //~~other coin balances~~
  usdt_balance: 16.573376, //about 2 USDT gained 
  usdt_available: 16.573376,
  xht_balance: 17.994,     //sold 10 XHT 
  xht_available: 17.994,
  //~~other coin balances~~
  }
  
//this is all of Account A's trades listed (line 42)
{ count: 13,
  data:
   [ { side: 'buy',
       symbol: 'xht-usdt',
       size: 10,
       price: 0.3,
       timestamp: '2022-06-24T21:58:44.990Z',
       order_id: 'bc6e5053-8453-489e-8804-d2df9069f9c4',
       fee: 0.003,
       fee_coin: 'xht' },
     { //~~ the previous trades done by A ~~
     } ] }
     
//zero open orders as it was fully filled near instantly! (line 45)
{ count: 0, data: [] }

As the amount for my order was fairly small, and it using the shared liquidity system of HollaEx, my list of orders may look empty, but that's just due to how quickly the trade was made. Shows how nifty shared liquidity is, given we only had one user actually doing something on this exchange ain't it?

Last updated