Gemini API - Practical Assignment

#1

If you have troubles with this assignment, please ask questions in this thread.

#2

My implementation of below API calls in “Gemini API - Practical Assignment”

  1. Use getMyAvailableBalances to see your current balances.
  2. Create a few (3-5) different buy limit orders using newOrder function. Make sure that the price is too low for Gemini to fulfil your buy order.
  3. Using getMyActiveOrders get a list of all your active orders. Do you recognise the orders you created in the last step?
  4. Cancel your orders using cancelAllActiveOrders .
  5. Using getMyActiveOrders get a list of all your active orders. Have they been cancelled?

BOT_Working

#3

@ivan , Is it ok to put the solution here?

#4

I can recognize the generated orders and they do get cancelled eventually.

My solution :


const main = require("async-main").default;
const GeminiAPI = require("gemini-api").default;

const JsonBeautify = require("json-beautify");


const secret = "2zLLJdd7tptRGUy1wEqafuaAtztv";
const key = "account-75fGnAH8Fpkrh76UqZYW";


const geminiApiConfig = 
{
   key,
   secret,
   sandbox: true
};
const restClient = new GeminiAPI(geminiApiConfig);


function JsonBeautifyDefault(json)
{
	const result = 
		JsonBeautify(
			/*value:*/ json,
			/*replacer:*/ null,
			/*space:*/ 2,
			/*limit:*/ 80
		);

	return result;
}


const ORDERS_COUNT = 3;
function GenerateOrders()
{
	var result = [];

	for (i = 0; i < ORDERS_COUNT; i++)
	{
		const orderDto = 
		{
			amount: 10 * (i + 1),
			price: 100 * (ORDERS_COUNT - i),
			side: "buy",
			symbol: "BTCUSD"
		};

		result.push(orderDto);
	}

	return result;
}


async function ExecAssignmentLogicAsync()
{
	try
	{
		const orders = GenerateOrders();
		console.log('generated orders : ' + JsonBeautifyDefault(orders));

		for (i = 0; i < ORDERS_COUNT; i++)
		{
			// TODO: maybe run in parallel and apply map/reduce 
			await restClient.newOrder(orders[i]);
		}

		var activeOrders = await restClient.getMyActiveOrders();
		console.log('active orders : ' + JsonBeautifyDefault(activeOrders));

		await restClient.cancelAllActiveOrders();
		console.log('orders cancelled');
		var activeOrdersAfterCancel = await restClient.getMyActiveOrders();

		console.log('after cancel : ' + JsonBeautifyDefault(activeOrdersAfterCancel));
	}
	catch (error)
	{
		console.log(error);
	}
}

main( ExecAssignmentLogicAsync );

Output :