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

@ivan I hope you don’t mind me asking but Could you please be so kind and share what microphone you guys are using when doing these videos it is amazing sound quality. I need to buy a new microphone, so I thought it would be a good idea to buy one of equal quality to what you guys are using.

Thank you and Kind Regards,

Nils :innocent: :stuck_out_tongue_winking_eye: :+1:

1 Like

I am 100% sure, that I have installed everything. But I have no idea, why this did not work. :neutral_face:
I have redone everything from scratch and it did work this time :grinning:

1 Like

Hi; I downloaded NodeJS for MacOS 64bit and received a successful installation message. I then searched for powershell in the spotlight search and I don’t find the window you are indicating to confirm NodeJS has been installed. Any suggestions where to look.
Thanks

2 Likes

Hi @Youwho, hope you are well.

Try to use the console of your OS, then you can try this command to show the version installed of node node -v.

Carlos Z

Gemini Sandbox user interface does not have an accessible API setting (please see screenshot).
The Sandbox seems to have both an updated + a less advanced mode compared to the one used in the course.
How to workaround this?

Mette, using Gemini from Denmark

1 Like

Hi @Mette, hope you are well.

You almost done, the API settings are accessible when you click on Account and then settings, after that you should be able to see the left menu of the settings and there should be the API settings.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hi Carlos aka thecil
I am fine thank you, and now, thanks to your assistance, even splendid :wink:
It works fine now. Retried today, and now the left menu appears - i did’nt yesterday.
Back on track :slight_smile:

1 Like

Hi again … jep, another problem.
Everything installed and working when performing the decribed testing in powershell.
When executing this script, I get the error: SyntaxError: Unexpected token ‘.’

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

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

1 Like

You have this same issue :nerd_face:

Check it and let me know if is working now.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

Hi Carlos
Your were right,- I did a mistake in entering the key.
My API key does not start with “account-”, but “master-”.
The secret starts with neither - just a code.
It still does not work, and has error: SyntaxError: Unexpected token ‘.’

1 Like

check the code line that the console is showing, apparently you have a dot . mistyped somewhere that code line.

Carlos Z

Hi @thecil , I was doing great until Ivan decided to make a callback within the moving average function: I get the following error message, using the following code. Could you help out please? (remember I’m running everyhting on an Ubuntu Huawei laptop)

ReferenceError: callback is not defined
    at /home/javier/tradingBot/index.js:51:5
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
function movingAverage (cryptoAsset, fiat, hours) {
  if(hours>169) {
    console.log("only up to 169 hours allowed")
  }

  CryptoCompareAPI.histoHour(cryptoAsset, fiat)
  .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)
}

movingAverage("BTC", "USD" , 100, function() {
  console.log("MA: ", result);
});
1 Like

Hey @javier_ortiz_mir, glad to know your well.

ReferenceError: callback is not defined means that callback variable is not defined, the callback can be used when you have an asynchronous function that should wait for another function to return a result.

Mainly used on asynchronous functions, mean you need to use an async keyword.
Here is my function to get the hourly MA so you can get a good idea on how to syntax an async function.

/*
// @dev Calculate Hourly Moving Average
// @var _asset, string
// @var _pair, string
// @var _hours, integer
*/
async function hourlyMovingAverage(_asset, _pair, _hours, callback){
  if(_hours>169){console.log("Only up to 169 hours allowed."); return}
  let _data = await cCompare.histoHour(_asset, _pair, function(_res){
    _res.reverse()
    let _sum = 0
    for(let _i = 0; _i < _hours; _i++){
      _sum += _res[_i].close
    }
    let _movingAverage = Math.floor(_sum/_hours)
    callback(_movingAverage)
  })

}

Carlos Z.

thanks @thecil you have been most comprehensive tutor here at the academy. I already noticed my mistake, nice implementation you have by the way, very respectful of all the conventions (the fact that you start with an underline all of the variables of a function, and you use async) … However, I found a new inconvenient when doing the minutely and daily MA. I cannot get the daily MA to work, I have tried starting from i=1 or finishing when i+1<days , thinking that as the last day is not closed, maybe tha property is still undefined… PLease help, here is the error and the code (I lonly put the daily MA code, since all the others are working fine now)


javier@javier-MACHC-WAX9:~/tradingBot$ node index.js
TypeError: Cannot read property 'close' of undefined
    at /home/javier/tradingBot/indicators.js:41:22
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Hourly MA:  32535.032400000007
Minuteley MA:  35501.647

  dailyMovingAverage:function (cryptoAsset, fiat, days, callback) {
    if(days>169) {
      console.error("only up to 169 days allowed");
      return;
    }

    CryptoCompareAPI.histoDay(cryptoAsset, fiat)
    .then(data => {
      data = data.reverse()
      var sum = 0;
      for(var i=0; i < days; i++) {
        sum+=data[i].close;
      }
      var movingAverage = sum/days;
      callback(movingAverage);
    })
    .catch(console.error)
  },
1 Like

When executing index.js I got this error:

(node:9614) UnhandledPromiseRejectionWarning: #<Object>
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9614) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:9614) [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.

In my case, the issue was missing account- part in the key.
Later I realized that adding a .catch statement would indicate it.

Hey @javier_ortiz_mir, hope you are well.

Its showing an issue on the codeline 41 of you indicators.js file, maybe you wanna check it or send me exactly what function have that code line, also it could be an issue on the API request of CryptoCompare because i remember that I face some issues that the data that you request from the API some times it fails to get.

That was one of the reasons on why I change the logic of my functions to async functions, so i can exactly point which variable should get the API data (the response) properly using the await method, It was a little bit complicate to fix the issues on “why the last time work and now it does not”, the callback method is a more efficient then using .then and .catch.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

(node:9614) 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(). 
To terminate the node process on unhandled promise rejection, 
use the CLI flag `--unhandled-rejections=strict` 
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)

Means that you should use the .catch method to handle the promise or error in case it does not response correctly.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Aw man…I perservered…I almost gave up last night but I erased the “.then” line for us to see a “response” and it worked…

Guys and girls, PLEASE dont give up on looking for solutions. Please give yourself some patience and honestly if you get frustrated take a half a day and try again…

In my case I had a hard time getting Yarn to install at first.

  • Had to change the “Execution Policy” running PowerShell as an administrator.
  • Then the code wouldn’t execute the order in this lesson, so I created another API key. The first one was a Master then I created a Primary…not sure if that mattered but I did it anyway…nothing
  • Now I just happened to see that it shows Syntax Error Unexpected token “.” = the only thing with a “.” is the “.default” and “.then” - so I erased .“then” and it sorta made a processing pause. I happened to check the sandbox exchange and what do you know…an order is there.
    I cant see the response through the code but oh well.

DONT GIVE UP! Take your time going through the comments on here and be PATIENT. If you run out of patience, give yourself some time. I am beginner as heck and that was pushing some limits! lol

1 Like

Any help with this NONCE error would be greatly appreciated. I looked up and down on here and cant seem to find a working solution.

thanks guys,

1 Like

I had the same problem. To fix this you need to create an API key as a Primary so then the key is format account-XXXXXXXX. It will not work if the key was created as Master.

That should fix your issue!