Javascript bot programming using Gemini API, NodeJS and CryptoCompare - DISCUSSION

Hey bro,

I just tried it and it worked. I didn’t even follow the guy on the video.

*I just went to brew.sh and copy this link into my terminal:
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

*Then I entered my mac’s password and everything was installed. After the installation you can give command:
“brew install yarn”

*After yarn is installed you can give command:
“yarn add gemini-api”

2 Likes

Great, I am happy that works. I have found to way also. Let’s move forward.

Hi guys,
I’ve got some troubles with the code and really struggle to get over it. It’s showing me error on line 26 but I even don’t have that many lines. What could be the reason?

Thanks

PS /Users/lukashoryna/Desktop/Code> node index.js
/Users/lukashoryna/Desktop/Code/indicators.js:26
});
^

const CryptoCompareAPICAPIkey = “(a274c63821e7f70e3194bd3c28cb8295d15524763469c7ae5b581b3b4498ab82)”;
const CryptoCompareAPI = require(“cryptocompare”);
CryptoCompareAPI.setApiKey(CCAPIkey);

module. exports = {
movingAverage:function(cryptoAsset,fiatCurrency,hours,callback){
if(hours>169){
console.error(“Only up to 169 hours allowed!”)
return
}
//1 get data from CC
CryptoCompareAPI.histoHour(cryptoAsset, fiatCurrency)
.then(data => {
//2 calculate MA FROM 100 past hours
data = data.reverse()
var sum = 0;
for(var i = 0;i<hours;i++){
sum+=data[i].close;
}
var movingAverage = sum/hours;
callback(movingAverage);
})
.catch(console.error)
}

Thankyou hank you are a star
[email protected]

Help

TypeError: CryptoCompareAPI.setApikey is not a function
at Object. (C:\Users\Nicklas\Desktop\Far\Bot\index.js:9:18)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
PS C:\Users\Nicklas\Desktop\Far\Bot>

1 Like

please attach all you code

@ivan, here is a great tool which helps to easier install software on windows.
The convept is similar to linux repositories or to “homebrew” on Mac OS.

P.S. No docker or visualization involved in case of chocolatey. All is done natively.
P.P.S. I have no relation to the project’s team, so I’m “advertizing” it just because I like what it does and how it works.

Hi,

I am getting this error message:

My code is:

const GeminiAPI = require(“gemini-api”).default;
const secret = “uggRoawkuBZYxtYuc51rSA6uYbg”;
const key = “TmZhtIRwA91pFRMSiicH”;
const restClient = new GeminiAPI({key, secret, sandbox:true});

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

What could be wrong? @ivan

all good… one ; too many

For anyone that can’t connect to gemini, I guess using a VPN would work, and it’ only the sandbox exchange anyway so you should be fine.

Hello,

This is my first project in Javascript! How can I use a value I am getting from an API call and assign it to a variable in Javascript so I can use it in the rest of the code? Been tinkering with this for a while now and I am not able to find a solution online. It seems so simple but have not had any success on this.

buy_price =  restClient.getMyPastTrades({symbol:'BTCUSD'})
.then(trades => {
  buy_price = trades[0]['price']
  return buy_price;
    })
.catch(console.error)

console.log(buy_price)

Here I am trying to get the buy price of my latest order on the gemini sandbox and assign it to a variable so I can use later.

I am getting Promise { pending } when I try this.

Let me know your thoughts

Thank you!

I am struggling creating an indicator file:
TypeError: indicators.hourlyMovingAverage is not a function
Could some one please help me to find where did I did wrong??

This is the index.js:

global.fetch = require("node-fetch");
const GeminiAPI = require("gemini-api").default;
const secret = "ya9WSHtMj1QdsK3ktxSQhNuPKAG";
const key = "account-XOaIsk30KogZtaR8aXfc";
const restClient = new GeminiAPI({key, secret, sandbox:true});

const indicators = require("./indicators.js");

indicators.hourlyMovingAverage('BTC','USD',50,function(result){
  console.log("MA =",result);
})

and this is indicators.js:


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

module.export = {

  hourlyMovingAverage: function(cryptoAsset,fiatCurrency,hours,callback){
    if (hours>169){
      console.error("Only upto 169 hours allowed");
      return
      }

    CryptoCompareAPI.histoHour(cryptoAsset, fiatCurrency)
    .then(data => {
      data = data.reverse();
      var sum = 0;
      for(var i = 0;i<hours;i++){
        sum += data[i].close;
      }
      var movingAverage = sum/hours;
      callback(movingAverage);
      })
    .catch(console.error);
  }
}

I’m getting an error on the first basic order one. The error I’m getting is :

(node:7412) UnhandledPromiseRejectionWarning: #<Object>
(node:7412) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:7412) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My code is simply

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

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

I’m going to have a look at this later, but the kids are up now, but if anyone who knows node/ javascript better than me can point me in the right direction that would be massively appreciated. And yes I’ve removed the key and secret in the post.

OK I’ve fixed the first error. It looks like I was required to put a catch in (might be something to do with the version of node I’m running. The new rest client call, which is all I have changed now looks like this

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

However I’m now getting an error in the output, which I’m guessing is returning from gemini which says

{ result: 'error',
  reason: 'MissingAccounts',
  message: 'Expected a JSON payload with accounts' }

I thought about just editing my first post but thought I’d leave it up just in case anyone else hits that. Any suggestions on this one?

1 Like

Guys can someone help me. I can’t open any kind of newOrder on Gemini. My code example:

restClient.newOrder({amount:1,
price:20000,side:“buy”,symbol:“btcusd”, options:[“immediate-or-cancel”]})
.then(console.log)
.catch(console.error);

The response is:

{result: ‘error’
reason: ‘InvalidSignature’,
message: ‘InvalidSignature’}

The rest is working fine.
What could it be?

I think you and I are having the same problem. My suspicion is that either something has changed in the language (like the catch has slightly) or that the API has changed on Gemini’s side slightly.

I’m not a node js programmer so I can’t trace it through the node code (one of the reasons I wanted to do this course was to get my hands dirty with node js). I am a .net dev though so tomorrow, if no one with more knowledge has replied first, I’m going to try this in .net with the .net api, hopefully I should be able to see if it gets the same issue. I’ll let you know.

Hi Oleg,

I THINK I’ve figured this out and for me it was down to the creation of the API Keys. I hadn’t checked all the boxes I needed to. I’ve created a new key, but this time I set the scope to primary (top right on the create api key section in gemini, currently it defaults to account group… I’m not sure if this makes a difference) and when I created it I checked the boxes for

  • Fund Manager
  • Trading
  • Requires Heartbeat

Now my code works. I’ll admit I had to do this with the .Net stuff so I could dig around but once I figured that gem out I put it back in to the Node code and it runs fine for me.

3 Likes

Hello

I ran into the following error for the newOrder code:

The error is Invalid Signature

My code is as follow:
const GeminiAPI = require(“gemini-api”).default;
const secret = “account-svdyCcfRrmazKr9Cblz0”;
const key = “15YVVHZfB6aDxVmYw3fQYGK5z7G”;
const restClient = new GeminiAPI({key, secret, sandbox:true});

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

Can anyone please help me how I can fix it? Tried to look through the forum and found nothing useful yet.

Appreciate your help :slight_smile:

@ivan Hello Ivan, might you have a look?

I figured it out what was wrong lol

I misplaced the secret and the key.

All good now

Thank you Michael! Thank you for your help!!

1 Like