Gemini API - Practical Assignment

Use getMyAvailableBalances to see your current balances.

image

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.
image
image

Using getMyActiveOrders get a list of all your active orders. Do you recognise the orders you created in the last step?

In deed i do!!!

Cancel your orders using cancelAllActiveOrders .

image

Using getMyActiveOrders get a list of all your active orders. Have they been cancelled?

YUP!!

1 Like

It now somehow works with 2+ orders but from different coins, tried a fourth one and the error appeared.

global.fetch = require("node-fetch");
const GeminiAPI = require("gemini-api").default;

const secret = "NMWhhwLiixjgPucEtbJFPt4ExaK";

const key = "account-kJGpYiaMOqtxZkiAQbho";

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

const CCAPIKey = "e65acb6b14ab3b11775e6d7d421ca589464d41257812fedb4a55fd0f0d6bb2d8"

const CryptoCompareAPI = require("cryptocompare");
CryptoCompareAPI.setApiKey(CCAPIKey);

restClient.newOrder({amount:10, price:100, side:"buy", symbol:"btcusd"})
.then(response => restClient.cancelOrder({order_id:response.order_id}))
.then(response => console.log(response))
.catch(error => console.log(error));

restClient.newOrder({amount:10, price:100, side:"buy", symbol:"ethusd"})
.then(response => restClient.cancelOrder({order_id:response.order_id}))
.then(response => console.log(response))
.catch(error => console.log(error));

restClient.newOrder({amount:10, price:100, side:"buy", symbol:"linkusd"})
.then(response => restClient.cancelOrder({order_id:response.order_id}))
.then(response => console.log(response))
.catch(error => console.log(error));

restClient.newOrder({amount:10, price:100, side:"buy", symbol:"aaveusd"})
.then(response => restClient.cancelOrder({order_id:response.order_id}))
.then(response => console.log(response))
.catch(error => console.log(error));

Screenshot Assignment_1 ScreenshotAssignment_2a ScreenshotAssignment_2b!
Screenshot Assignment_2c
ScreenshotAssignment_2d
ScreenshotAssignment_3
ScreenshotAssignment_4 ScreenshotAssignmnet_5

1 Like

@PhilD99
i d k if you had a problem with rate-limiters from gemini, but this site was pretty helpful to me in implementing a sleep / delay operation in javascript so that i didnā€™t have to run the code snippets individuallyā€¦
https://www.sitepoint.com/delay-sleep-pause-wait/

i got everything working individually before i came here to check anyone elseā€™s work, but when i saw PhilDā€™s, i went ahead and tried to fix it up all into one script, for which i need the above helpā€¦ final code below:

console.log ("trader_bot active");

const GeminiAPI = require("gemini-api").default
const secret = "xxxx";
const key = "xxxx";

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

// got this 'sleep', i.e. delay, function and the entire 'async {await}' stuff from https://www.sitepoint.com/delay-sleep-pause-wait/ ...
// ...WAY after i figured out the rest of this
function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

(async () => {
// Use getMyAvailableBalances to see your current balances.
sleep(500).then(() => { restClient.getMyAvailableBalances()
  .then(console.log)  // decided to go ahead and forget about the whole '.then(response=>console.log(response));' ...
  .catch(console.log); }); // ...bc this, their suggestion, works fine afaict...
//  Create a few (3-5) different buy limit orders using newOrder function.
//  (Make sure that the price is too low for Gemini to fulfill your buy order.)
sleep(1000).then(() => { restClient.newOrder({amount:10,price:.01,side:"buy",symbol:"ETHUSD"})
  .then(console.log)
  .catch(console.log); });
sleep(2000).then(() => { restClient.newOrder({amount:10,price:.01,side:"buy",symbol:"BTCUSD"})
  .then(console.log)
  .catch(console.log); });
sleep(4000).then(() => { restClient.newOrder({amount:10,price:.01,side:"buy",symbol:"ETHBTC"})
  .then(console.log)
  .catch(console.log); });
//  Using getMyActiveOrders get a list of all your active orders. Do you recognize the orders you created in the last step?
await restClient.getMyActiveOrders()
  .then(console.log)
  .catch(console.log);
//  Cancel your orders using cancelAllActiveOrders.
sleep(8000).then (() => { restClient.cancelAllActiveOrders()
  .then(console.log)
  .catch(console.log); });
//  Using getMyActiveOrders get a list of all your active orders. Have they been canceled?
sleep(10000).then(() => { restClient.getMyActiveOrders()
  .then(console.log)
  .catch(console.log); });
//  completing the 'async' function closing syntax
})();

i kept looking for the confirmation that ivan got in the video (ā€œis_cancelled: trueā€), but I kept getting the same that PhilD did, which makes sense when returning active orders (empty array because there are none), so iā€™m satisfied with that. ===edit: i guess it also makes sense because ivan was using cancelOrder and not cancelAllActiveOrders)===

Thanks B_S

Iā€™ll try it out!

`const GeminiAPI = require("gemini-api").default;
const secret = "******";
const key = "account-*******";
const restClient = new GeminiAPI({key, secret, sandbox:true});

restClient.getMyAvailableBalances()
.then(response => console.log(response))
.catch(console.error);

restClient.newOrder({ amount:10, price:100, side:"buy", symbol:"btcusd"})
.then(response => console.log(response))
.catch(console.error);

restClient.newOrder({ amount:10, price:100, side:"buy", symbol:"ethusd"})
.then(response => console.log(response))
.catch(console.error);

restClient.newOrder({ amount:10, price:20, side:"buy", symbol:"ltcusd"})
.then(response => console.log(response))
.catch(console.error);*

restClient.getMyActiveOrders()
.then(response => console.log(response))
.catch(console.error);

restClient.cancelAllActiveOrders()
.then(response => console.log(response))
.catch(console.error);

restClient.getMyActiveOrders()
.then(response => console.log(response))
.catch(console.error);
`

I got this error while executing the program
As you can see in screenshotā€¦
please help Iā€™m not able to procced furtherā€¦

@ivan
@thecil

Would you be able to share a github repository for this project? that way i can easily replicate your errror :nerd_face:

Carlos Z