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

Greetings, having issues connecting my powershell/Atom account to my gemini sandbox. Anyone able to see what I am doing incoreectly? Thanks in advance

1 Like

Hey guys so i get this merror message. What’s the matter here?

global.fetch = require(“node-fetch”);
const GeminiAPI = require(“gemini-api”).default;
const secret = “2SrRCw2ZJDTqc5wfFzTvLcWq3Va”;
const key = “account-jv3DuBrPOahId5fahuXc”;
const CCAPIKey = “96339dfb1ded44102d3bf07aa4813dbc99ebf0a445a7d3926cb3e60ac6b7d156”;
const restClient = new GeminiAPI({key, secret, sandbox:true});

const CryptoCompareAPI = require(“cryptocompare”);
CryptoCompareAPI.setApiKey(CCAPIKey);
restClient.newOrder({amount:10,price:10,side:“buy”,symbol:“btcusd”})
.then(response => console.log(response))
.catch(error => console.log(error));

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

1 Like

Hey @Stahlin_Jonas, hope you are well.

Please take a look into this post which is related to your issue, the solution is to change the fetch version to a lower one.

Carlos Z

Your key is wrong, the format of it should start with “account-xxxxxxxx”. Check the gemini api account for it :nerd_face:

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

Carlos Z

I can’t use gemini in germany… any recommendations for other exchanges that work in a simular way so i can follow the course?

1 Like

Hi Carlos, i have tried as per your instructions but i am still getting error message require is not defined. Please see my code below


My packages .json

Can you help, please?@thecil

1 Like

Bitfinex, the api is a bit more complex but they also have sandbox account.

hey @thecil
i’m having some network issues… is there a way to install yarn from a manually downloaded source code? e.g. from their github
OR
can i use the wget function from my local folder where we’ve been working for these assignments? or is it something that you can only access from another folder?

new problem
(edit: on a mac, btw)
eventually got the yarn to install locally*, but of course when i try yarn add gemini-api, it tells me the command “yarn” is not found… i tried sudo npm install yarn --global, but my user can’t get that access (“Missing write access to /usr/local/lib/node_modules”), and my master password isn’t working there…

by installed locally i mean

MyComputer:TA w filip and ivan users$ npm install yarn

> [email protected] preinstall /Users/weakuser 1/Documents/crypto training/TA w filip and ivan/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No repository field.

+ [email protected]
added 1 package and audited 1 package in 45.338s
found 0 vulnerabilities

MyComputer:TA w filip and ivan users$ yarn add gemini-api
-bash: yarn: command not found

MOST RECENT EDIT:
finally just used npm install gemini-api and got no errors so far…
i’d like to use your credentials @thecil (that i got from here Javascript bot programming using Gemini API, NodeJS and CryptoCompare - DISCUSSION) or ivan’s from the video in order to check that anything there is working and avoid having to go through the entire account setup process with gemini (i try to minimize the number of centralized accounts i use in order to avoid all the risks associated with centralization)
Please LET ME KNOW if that’s not ok! i’ll hold off for a day or two

1 Like

fyi: “terminal” is the app he’s talkingabout in case you’re still wondering… i realize it’s a bit late, but i happened to be poking around haha

hey @Leo1, hope you are well.

Could you please share an screenshot about the console error that is showed to you?

Also please share your code in the following way so i can copy/paste easily :nerd_face:

Carlos Z

@thecil, would it be worth it to solve some problems in this thread by you guys giving out some keys/credentials and telling people to head over to something like https://npm.runkit.com/gemini-api ? not having to download and install anything from terminal/powershell would certainly be helpful to me, and i don’t think would detract too much from the class, although i don’t know if that fits your guys’ goals…

if you’re not too busy, i’m also wondering what destructured means in this context (what is { getTIcker } literally in this case?):

// The methods are bound properly, so feel free to destructure them:
const { getTicker } = restClient;
getTicker('btcusd')
  .then(data =>
    console.log(`Last trade: $${data.last} / BTC`)
  )

i think i got one of those (on a mac) and it was fixed by adding a “catch line” like so after the .then…:

restClient.newOrder({amount: 10, price: 27000, side:"buy", symbol:"btcusd"})
.then(response => console.log(response))
.catch(console.log);

yeah i know it’s been a while, but just in case…!

Thanks mate!
I ll have a try.

anyone know what is wrong here, can’t run my program in powershell. SyntaxError: Unexpected identifier
←[90m at Object.compileFunction (node:vm:352:18)←[39m
←[90m at wrapSafe (node:internal/modules/cjs/loader:1031:15)←[39m
←[90m at Module._compile (node:internal/modules/cjs/loader:1065:27)←[39m
←[90m at Object.Module._extensions…js (node:internal/modules/cjs/loader:1153:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m at node:internal/main/run_main_module:17:47←[39m

@thecil

global.fetch = require ("node-fetch");

is there anything wrong with the above code?
if not, why do i get the folllowing?

*****$ node tradebot4TA.js
trader_bot active
internal/modules/cjs/loader.js:1102
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /****/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /******/node_modules/node-fetch/src/index.js from /*****/tradebot4TA.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 index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /*****/node_modules/node-fetch/package.json.

    at new NodeError (internal/errors.js:322:7)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/Users/weakuser 1/Documents/crypto training/TA w filip and ivan/tradebot4TA.js:4:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32) {
  code: 'ERR_REQUIRE_ESM'
}

ok NOW knowing that i did not yarn add node-fetch, but used npm i node-fetch… what difference does that make? (i haven’t been able to get yarn working, but npm worked for gemini and cryptocompare up until global.fetch…

Hi @thecil thanks for coming back to me. I have found where the issue was. Basically in the package.json the type need to be changes to common.js instead of module as well. it is line 17 on my screenshot.
Hope it will help some lost soul in the future :slight_smile:

1 Like

Hey @B_S, hope you are great!

Please take a look to this reply, which is releated to the same issue that you have with the fetch module.

Carlos Z

1 Like

733.12 seconds of updating node-fetch… and another 30 of running my new and improved trad-bot… it’s working all right!

1 Like

Hi, I can’t figure out how to get the npm package over to atom even though I followed the video and went through the correct steps on how to set up the npm package

1 Like

whoooof, it’s a long road for some of these machine vagaries… this course in particular was subject to more of the “out-of-date” or machine-specific type of issues than the others i’ve tkaen; that said, i’m not sure how to help with this problem (i just tried installing to my local folder, which worked), but two big ones that came up for me were the node-fetch downgrade (just a couple posts above yours here), and yarn not wanting to play nice (so i skipped it and just used npm for the remainder of the course)… also using a vpn or similar might’ve been messing up my connectivity in the first place…