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

Here is my code from Atom

InkedPicture1_LI

1 Like

did you add it with yarn? make sure gemini api file is in your code folder. If not, then it may still need to be added.

great, so it is working now? Sorry i was late to your replies

Yes I installed yarn and gemini api file is in the folder, I followed exactly what Ivan did in the videos. I keep getting a ‘Unhandled Promise Rejection warning’.

@ivan. the “yarn add gemini-api” does not work as your video shows. I keep getting a security error. how do I move forward?

Screenshot 2021-04-16 214134

1 Like

Hey @cryptatticus, @VincentC, hope you guys are great.

The issue you have is with powershell, try to run the same commands with CMD (windows console), you can try npm install gemini-api if you have npm installed, yarn is another package manager like npm, you can also install it with npm install yarn.

Then the problem that you mention @VincentC:

Means that one of your functions should be asynchronous function.

Please provide your code in the following way so i can be able to test it for you and check what errors did you have on it:
https://forum.ivanontech.com/t/faq-how-to-post-code-in-the-forum/35357/2

Carlos Z

1 Like

Hi @ivan, just to ask you if you know if Binance still without API sandbox mode for work with fake money?

I want to use Binance API to build my bot but I also want to work with fake money on the beginning.

Thank you.

1 Like

Hello everyone i have an issue. When i type "yarn add gemini-api " i get an error . Без име
Please help me

1 Like

I think Binance does not have an exchange sandbox (which is the platform for fake money), so no environment like binance but with fake money :frowning:. (thats why we pick gemini for the course, they do have a sandbox to play around).

Carlos Z

1 Like

You might have an issue with yarn installation on powershell, you can try run the yarn command in CMD (windows console) and check if it returns a different message.

But you do not need to use yarn add gemini-api to install it, when you run npm install gemini-api is the same command has the first one (yarn or npm are package managers).

So after you have installed gemini-api through npm, you should be able to invoke it on your code by:
const restClient = new GeminiAPI({ key, secret, sandbox: false });

Carlos Z

Loving the course @ivan and @filip,

i’ve installed node, set up gemini and when inputting node index.js on Powershell I get the following:

SyntaxError: Missing initializer in const declaration
←[90m    at wrapSafe (internal/modules/cjs/loader.js:979:16)←[39m
←[90m    at Module._compile (internal/modules/cjs/loader.js:1027:27)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m
PS C:\Users\dell\Desktop\Trading Bot>

code as follows

const GeminiAPI = require ("gemini-api").default;
const secret = "hidden secret key";
const key "F4C5TcIpdZi3lM7Y1Ilm";
const restClient = new GeminiAPI ({key, secret, sandbox:true});

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

any help would be much appreciated.

Thanks guys

1 Like

you are not assigning the value with =

Carlos Z

Thanks Carloz, always appreciated

1 Like

Hi Carloz, apologies me again

I’ve fixed as per yours above but still getting the error message:

SyntaxError: Unexpected token '.'
←[90m    at wrapSafe (internal/modules/cjs/loader.js:979:16)←[39m
←[90m    at Module._compile (internal/modules/cjs/loader.js:1027:27)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m
PS C:\Users\dell\Desktop\Trading Bot>

Code as follows:

const GeminiAPI = require ("gemini-api").default;
const secret = "SAXTr4t13WYX5VV2a8rTqaZR8Pb";
const key = "F4C5TcIpdZi3lM7Y1Ilm";
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

at the end of the first code line, remove the ;.

Remember that newOrder is an async function so the basic structure is:

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

Carlos Z

Hi Carloz hope all is well,

Many thanks for your reply, completely makes sense now.

I am however still getting an error message as follows:

PS C:\WINDOWS\system32> Set-Location -Path "C:\Users\dell\Desktop\TradingBot"
PS C:\Users\dell\Desktop\TradingBot> node index.js
(node:11540) UnhandledPromiseRejectionWarning: #<Object>
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11540) 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:11540) [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.
PS C:\Users\dell\Desktop\TradingBot> node index.js

Code as follows:

const GeminiAPI = require("gemini-api").default;
const secret = "SAXTr4t13WYX5VV2a8rTqaZR8Pb";
const key = "F4C5TcIpdZi3lM7Y1Ilm";
const restClient = new GeminiAPI ({key, secret, sandbox:true});

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


Appreciate all your help of late @thecil

try to add .catch(console.error) at the end of your .then().

So that will trigger an error message from the server in case you have some error in the parameters.

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

Carlos Z

Thanks Carloz, will do

Hi @thecil I think we’re getting somewhere, i’ve included the .catch(console.error) and received the following:

PS C:\Users\dell\Desktop\TradingBot> node index.js
{
  result: 'error',
  reason: 'InvalidSignature',
  message: 'InvalidSignature'
}

Could you let me know what the signature refers to?

Thanks again

1 Like

Your key should start with account- then the numbers, verify your Gemini API keys.

Carlos Z