Problem solved I think it was the spacing at the very top function.
var strategy = function(){
IT WORKS!
Problem solved I think it was the spacing at the very top function.
var strategy = function(){
IT WORKS!
global.fetch = require("node-fetch");
ERROR
node-fetch
changed to ES modules by default:
SOLUTION:
npm uninstall node-fetch
npm install node-fetch@2
Heyy there. I am having problems with the gemini web page, I don’t know what to do. Can someone, help me pls?
what is your issue?
https://exchange.sandbox.gemini.com/balances check this website you should be able to have an account;
make sure you validate your account by clicking on the email from gemini or an sms sent to your phone. otherwise the API settings wont work.
then go to settings and set your API; avoid the master key to use ; create a primary API and save it.
example:
const GeminiAPI = require("gemini-api").default;
const secret = "< secret key";
const key = "account-secret account key";
const restClient = new GeminiAPI({key, secret, sandbox:true});
all right i finish the course
and the forum was great to fix some of the updates/ on the node-fetch upgrade … i got stuck but the forum saved me time
the only change I made on the code is to set the MA value to added into my sell or buy bitcon at the MA price; so i will buy or sell something instead of a fix number; i increased timer to 10 sec… so i can catch with my slow the results
module.exports = {
marketBuyBitcoin:function(ticker){
return restClient.newOrder({
amount:1,
price:ticker,
side:"buy",
symbol:"btcusd",
options:["immediate-or-cancel"]})
exchange.bitcoinPrice(ma)
.then(res => {
var price = res.last;
console.log("MA :", ma);
console.log("Price :", price)
if(price < ma && !hasPosition){
console.log("BUY!")
exchange.marketBuyBitcoin()
.then(res => {
console.log("bought successfull");
hasPosition = true;
setTimeout(strategy,10000);
})
.catch(error => console.error)```
Thanks Aldrin, let me look into that. If I cannot move on, Could I request your help?
Hi,
I came across a failure when running following:
baichen@MacProM1:~/GeminiApi$ node index.js
node:internal/modules/cjs/loader:1125
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/baichen/GeminiApi/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /Users/baichen/GeminiApi/node_modules/node-fetch/src/index.js from /Users/baichen/GeminiApi/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /Users/baichen/GeminiApi/node_modules/node-fetch/src/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/baichen/GeminiApi/node_modules/node-fetch/package.json.
at new NodeError (node:internal/errors:363:5)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1125:13)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Function.Module._load (node:internal/modules/cjs/loader:828:14)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (/Users/baichen/GeminiApi/index.js:1:16)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:988:32) {
code: 'ERR_REQUIRE_ESM'
}
Code:
global.fetch = require("node-fetch");
const GeminiAPI = require("gemini-api").default;
const key = "xxxx";
const secret = "xxxx";
const CCAPIKey = "xxx";
const restClient = new GeminiAPI({key,secret,sandbox:true});
const CryptoCompareAPI = require("cryptocompare");
CryptoCompareAPI.setApiKey(CCAPIKey);
you have to either upgrade or downgrade your node-fetch ; I believe i had the same error and i did this and then it worked out.
const GeminiAPI = require("gemini-api").default;
const secret = "xxxxxxxxxxxxx";
const key = "xxxxxxxxxxxxxx";
const restClient = new GeminiAPI({key, secret, sandbox: true});
restClient.newOrder({amount:10,price:100,side:"buy",symbol:"btcusd"})
.then(response => console.log(response)).catch(error => console.log(error));
Hi everyone, I am running into the following problem in powershell:
{
result: ‘error’,
reason: ‘InvalidNonce’,
message: “Nonce ‘1660911401386’ is not within 30 seconds of server time ‘1660911402’’”
}
Does anyone know what this means?
You might need to sync the time of your OS system.
Carlos Z
Hi Carlos Z,
Do I need to sync it within my VScode? Or otherwise, what steps do I need to take to do that?
global.fetch = require("node-fetch");
const GeminiAPI = require("gemini-api").default;
const secret = "dNsEFuPFuCpiapFQHM5Ct74vnjk";
const key = "account-OlJPSozAdkw68CyuOjht";
const CCAPIKey = "b27f6a9f0c3c4bb4e4960ec7006c2c04df9c379796c4b09aa29e476a69115767";
const restClient = new GeminiAPI({key, secret, sandbox: true});
const CryptoCompareAPI = require("cryptocompare");
CryptoCompareAPI.setApiKey(CCAPIKey);
/*restClient.newOrder({amount:1,price:1200,side:"buy",symbol:"ethusd"})
.then(response => restClient.cancelOrder({order_id: response.order_id})).then(response => console.log(response)).catch(error => console.log(error));*/
//CryptoCompareAPI.coinList()
//.then(coinList => {
// console.log(coinList)
//})
// 1 get data from CC
CryptoCompareAPI.histoHour('BTC', 'USD')
.then(data => {
data = data.reverse()
for(let i = 0;i<100;i++){
console.log(i);
console.log(data[i].close)
}
})
.catch(console.error)
// 2 calculate MA from 100 past hours
// 3 check continuously if price is crossing 100 MA => BUY/SELL/HOLD
My code seems to be correct but I get this error. Can you help me with this?
Kind regards.
PS C:\Users\Gijs\Documents\botprogramming> node index.js
internal/modules/cjs/loader.js:1089
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\Gijs\Documents\botprogramming\node_modules\node-fetch\src\index.js
require() of ES modules is not supported.
require() of C:\Users\Gijs\Documents\botprogramming\node_modules\node-fetch\src\index.js from C:\Users\Gijs\Documents\botprogramming\index.js is an ES module file as it is a .js file whose nearest parent package.json contains “type”: “module” which defines all .js files in that package scope as ES modules.
Instead rename C:\Users\Gijs\Documents\botprogramming\node_modules\node-fetch\src\index.js to end in .cjs, change the requiring code to use import(), or remove “type”: “module” from C:\Users\Gijs\Documents\botprogramming\node_modules\node-fetch\package.json.
←[90m at Object.Module._extensions…js (internal/modules/cjs/loader.js:1089:13)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:937:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:961:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:92:18)←[39m
at Object. (C:\Users\Gijs\Documents\botprogramming\index.js:1:16)
←[90m at Module._compile (internal/modules/cjs/loader.js:1072:14)←[39m
←[90m at Object.Module._extensions…js (internal/modules/cjs/loader.js:1101:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:937:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m {
code: ←[32m’ERR_REQUIRE_ESM’←[39m
}
This might be the same issue that we had long time ago, take a look at this post, which should be the solution to that issue:
Carlos Z
Yes that did the trick for me. Thanks!
atom is obsolete, will the code works the same in VS code?
Yes, Visual Code is what is commonly used so far for programming, using atom or VS will achieve the same goal.
Carlos Z
Hi again,
When I try to import node-fetch using
global.fetch = require(“node-fetch”);
and then run index.js via powershell, power shell gives me this error message:
Error [ERR_REQUIRE_ESM]: require() of ES Module
Instead change the require to a dynamic import() which is available in all CommonJS modules.
I think what it means is I need to change
global.fetch = require(“node-fetch”);
to something else, something along the line of:
const fetch = require(“node-fetch”);
I’ve tried several ways to try to rectified this problem, but none of it work. Did someone also have this problem? how can I solve this?
thanks
found a work around from stackoverflow: https://stackoverflow.com/questions/69087292/requirenode-fetch-gives-err-require-esm
for all those in the future that had a similar problem, the link above may be able to help you as well.
is there any other services better than coin market cap VS crypto compare, which one is better?
are there other website or services that has better services than these two, whether it’s free or paid?
Thare are also this 2, both have a free version to be use.
https://coinpaprika.com/api/
https://1inch.io/api/
Carlos Z