@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)===