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

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

Hey, one of my friend john is using gemini exchange he suggest me to use gemini exchange. I have read the various gemini review in order to avoid any loss of my cryptos.

Hello Guys, I keep getting this error message when executing the buy order:

error

My code is:

code

Does someone know what the problem might be? Cheers! @ivan

Found the error! :wink:

HI @ivan

The quiz, question 1 does not allow me to select multiple answers.

I didn’t understand the question therefore.

HI @ivan

Im using Mac book pro. Any information on how to install everything?

Im not sure if I installed everything correctly… Is Powershell the Windows pendant to Terminal right? Or do you discuss how to use everything in the Javascript course? I have not done it yet. What is your recommendation for proceeding with Mac?

So far output on Terminal:

1 Like

@ivan @filip or anyone else here

Guys, I cannot continue from this point but I want to finish the 2 courses before my subscribtiion expires. Pls let me know.

  1. powershell … ?

  2. how to proceed the following lessons with windows.

Im doing the Javascript course meanwhile… but not sure if I will understand what you mean afterwards…

Sorry about the lack of answers from Ivans part. We will fix the quiz.

You are correct in that you should use the terminal if you are on mac. And it looks like you are set up correctly with node. You don’t have to care about Powershell, it’s the terminal Windows users will use.

What’s the issue you are having with node?

Thanks for the answer Filip. So far I wasn’t able to continue with the classes. I first need to finish the Javascript course before I return to the last bit in the TA course. Challenge is that your classes are always referring to Windows. But I was able to install Atom and now working on the JavaScript.

If I have more questions at a later stage, I will post here again.

Great! Just tag me if you need further help :slight_smile:

1 Like

Running scripts is disabled on my
system. How to install gamini-api?

1 Like