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

This is very strange, i might need to download your project and try to replicate the error from my side.

The same for you guys @Lehigr2, @PhilD99.

It probably might be an npm version but i want to try some stuffs by my own, because my old project does not give me any error.

https://github.com/thecil/TA_AlgoCourse

Carlos Z

Thanks Carlos

Appreciate your help.

PhilD99

@thecil @Lehigr2 @PhilD99

Yes if you can check what I have right now I can send but github wont let me upload the node modules folder whic contains a lot of files.

I have a strong suspicion that the problem is when we add the cryptocompare part from yarn. (at least the version right now).

When you do the steps right now with today’s version are you still getting through?

So the question is, how do I send through all of my code to you? Because right now github not letting me because it is being too big.

Also I have tried to use your code but getting the same ES Module error.

I think the problem is on the npm version, I have kept with v12.0 because is the one that does not give me too many weird issues (like this one you guys are facing).

Now there is no need to upload the node_modules folder to github, with the package.json i can download your project and run npm install, then it will download me all the dependecies modules for your project to be able to run.

Also is good practice to not upload the node_modules folder, I always add it to the gitignore file which will not upload the folders or file that I name in it.

Carlos Z

Okay I have uploaded my 3 files, is that all you need right?

https://github.com/Riki0923/Algorithmic-Trading

1 Like

Perfect, I have managed to run your code properly. I think the issue is on the module node-fetch at the latest version, I just switch the version dependency in your package.json so I force it to download the same version that I have in my old version, and it does the trick.

image
NOTE: please remember to delete your node_modules folder and then change the version on the dependecies and then npm install again.

Then I was able to run your script properly :nerd_face:

image

@Lehigr2, @PhilD99, you guys can try the same.

Carlos Z

3 Likes

It works for me. I had actually changed my package.json to this version based on your github code. It didn’t work for me a few days ago, but after reading this post, I thought, you need to run npm install for the change to take effect. That did it, works fine. Thanks!

1 Like

Hi Carlos

Thanks for all that. I switched the “node-fetch” dependency on the package.json from “^3.0.0” to “^2.6.1” on atom. However, when I tried to execute node.js on Powershell I still got the same error message as I showed in my post on sept 11. Not sure where to go from here. Here’s my index.js code:

global.fetch = require(“node-fetch”);
const GeminiAPI = require(“gemini-api”).default;
const secret =“2xq5nUgLZgVsrjXuEHfqEyGGNqr1”;
const key = “account-Wn5E071DQtIZPyY69S5g”;
const CCAPIKey = “0875c533d882b9ea12e78d9a25e6db88ba3336313ae9aefdb6d35a2d2db87c1c”;
const restClient = new GeminiAPI({key, secret, sandbox:true});

const CryptoCompareAPI = require(“cryptocompare”);
CryptoCompareAPI.setApiKey(CCAPIKey);

CryptoCompareAPI.coinList()
.then(coinList => {
console.log(coinList)
})

Oh yeah finally got through! Thank you very much.

I am on the indicator creation part now and I am getting this error:

callback

code in indicator:

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

module.exports = {

movingAverage: function (cryptoAsset, fiatCurrency, hours){

  if(hours>169){
    console.error("Only up to 168 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<100; i++){
      sum+=data[i].close
    }

    var movingAverage = sum/hours;
    callback(movingAverage);
  })
  .catch(console.error)
}


}

code on the main index file:

global.fetch = require('node-fetch')
const GeminiAPI = require("gemini-api").default;
const secret = "uJVwHaon5Jrp9CB9LMYD8UFtucZ";
const key = "account-3mD9hql52ePPk7VuJFDR";
const restClient = new GeminiAPI({key, secret, sandbox:true});
const indicators = require("./indicators.js");

/*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));*/

//100 hour MA

indicators.movingAverage("ETH", "USD", 100, function(){
  console.log("MA: ", result)
})

// 3 check continouslay if price is crossing 100 MA => BUY/SELL/uJVwHaon5Jrp9CB9LMYD8UFtucZ

@thecil

Ignore what I have just wrote above, I have finished the course.

One more question remains, because I think I am going to continue by my own as Ivan suggested on Bitmex. Can I open a topic if I get stuck there in the forum?

Because probably I can run into some issues and if I get really stuck I can appreciate some help from you. I really want to go on with this and I think next week I am going to start it.

Anyway BIG thank you for the help in the node fetch part, was really easy to fix in the end but yes, still lot to learn :smile:

See ya later.

Yes, you are free to, but the forum team might not be able to help, still might be other students that would find interesting and give you a feedback :nerd_face:

Still you should try it out, if there is no module for bitmex api, you might have to create yours, by using fetch and bitmex api, build your own methods (like i did with my project, you can use it as example to get all the gemini api methods, something like that is the same process for all APIs, just that gemini have a module, while the others, you might have to build it yourself).

Carlos Z.

It might be because your are configuring your version to be “above 2.6.1” meaning, it could download a higher version if exists, so it will (and probably) download(ed) the latest version, you have to be specific on the version :nerd_face:

Carlos Z

Hi Carlos

Thanks for all your trouble. I changed it to “2.6.1” but still the same error message. Here’s a screen shot of the package.json on atom:
Screenshot (15)

I notice it’s all in green - not in different colours. Don’y know if this means anything.

I’m thinking maybe I should just delete/uninstall all the files and start again from node.js installation?

PhilD99

1 Like

I’m getting a weir error:

Joels-MacBook-Pro-3:JS joelstaehlin$ node index.js

(node:72631) UnhandledPromiseRejectionWarning: #

(Use node --trace-warnings ... to show where the warning was created)

(node:72631) 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:72631) [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.

Joels-MacBook-Pro-3:JS joelstaehlin$ yarn --version

1.22.11

Joels-MacBook-Pro-3:JS joelstaehlin$CleanShot 2021-09-16 at 19.07.33@2x

But my code seems to be fine and I have yarn installed. Help, please! I’m on MacOS with the M1 Chip, in case that makes a difference.

Remember that you have to delete your node_module folder and npm install again to download the new modules versions.

Also the syntax color does not matter, Atom use that syntax color for .json files, while I’m using VS Code which just highlight it on another color.

Carlos Z

2 Likes

Your newOrder function should end with:

.catch(error => console.log(error));

All functions that contains a .then function should have a .catch at the end, to catch any error in case there is any.

Carlos Z

1 Like

That worked! Thank you! Also had to adjust the API settings, but only figured that out once the error message was displayed correctly! On to the next chapter!

1 Like

Hi Carlos

Yep, working now.

Thank you very much!

Phil

@thecil

Hi,

I’m using the latest Mac with the M1 chip and had the same issue. I downgraded my node version to 10.21.0 through the link you provided but now there is a new error.


Joels-MacBook-Pro-3:JS joelstaehlin$ node index.js
/Users/joelstaehlin/Documents/Areas/Cryptocurrency/Academy/JS/node_modules/node-fetch/src/index.js:9
import http from ‘http’;
^^^^

SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object. (/Users/joelstaehlin/Documents/Areas/Cryptocurrency/Academy/JS/index.js:1:16)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:789:10)


My code is:

CleanShot 2021-09-18 at 13.31.32@2x


Help, please! :raised_hands:

1 Like

Hey @spicydumpling, hope you are well.

Thats the same issue that other students got few days ago, please take a look into this post to know how to fix that issue:

Carlos Z

1 Like