Okay I have uploaded my 3 files, is that all you need right?
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.
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
@Lehigr2, @PhilD99, you guys can try the same.
Carlos Z
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!
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:
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
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
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
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
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:
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
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$
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
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
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!
Hi Carlos
Yep, working now.
Thank you very much!
Phil
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:
Help, please!
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
Hi ivan, I initially can’t add gemini api and I search it in github…
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
It works now…
Is this okay?
I think you clicked the previous folder.
You, my friend, are a legend!
Hope this will help somebody
first error on policy
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
//beneath .then dont forgot the .catch
.then(response => console.log(response))
.catch(error => console.log(error));
when creating api choose primary not the master
and dont forget to check all the boxes available