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

Hey @Tyler11, hope you are ok.

First you are trying to install packages directly on the desktop folder, i could suggest to create a folder for all the Course content and code that will be need it.

Second you could try to use windows console (CMD) instead of powershell, some times i also have errors with powershell and then i try the same comand in cmd and it works.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Will do tomorrow, thanks! Getting ready for Good Morning Crypto now…

1 Like

Carlos,

I got that problem solved, now I’m getting this signature error. I read and tried everything in this forum, spent a few hours trying different things in Gemini, cmd vs PowerShell, making changes to .js file. I’m stuck man! Here is my JavaScript and result:

const GeminiAPI = require(“gemini-api”).default;
const key = “account-fJpbLkl5XHJWEgGwXjVQ”;
const secret = “2ygqo83kmZTNBRQDkHnzVQmrvpC3”;
const restClient = new GeminiAPI({key, secret, sandox:true});

restClient.newOrder({amount:1,price:35000,side:“buy”,symbol:“btcusdt”})
.then(response => console.log(response))
.catch(console.error);

C:\Users\TYLER-PC\Documents\Crypto\Atom\tradingBot>node index.js
{
result: ‘error’,
reason: ‘InvalidSignature’,
message: ‘InvalidSignature’
}

Thanks in advance,

Tyler

1 Like

Are you sure your API keys comes from this website: https://exchange.sandbox.gemini.com/

If is true, you might wanna check the permissions on your API key, it is allowed to operate your funds or just read them??

Carlos Z

Carlos,

Hopefully you are making nice gains on this run!

I’ve tried so many different things, starting to feel like I’m wasting time on this… Should this be hard (5 hours)? Tried everything in forum and read API documentation. I have 5 different API keys I’ve tried with all configurations, I have Sandbox primary account and a funded sandbox trading account both with their own keys. Ran in PowerShell as admin, cmd, went through all steps in videos three times starting fresh to verify all. Everything goes smoothly until this point, I’m stumped bro! Hopefully I’m not making a simple mistake haha…

JS:

const GeminiAPI = require(“gemini-api”).default;
const key = “account-41t7eE3xxVNwd6A8BySs”;
const secret = “6PoyyYUjK3TYtgwzhyFQ8BTup58”;
const restClient = new GeminiAPI({key, secret, sandox:true});

restClient.newOrder({amount:1,price:35000,side:“buy”,symbol:“btcusdt”, account:“primary”})
.then(response => console.log(response))
.catch(error => console.error(error));

Error:

C:\Users\TYLER-PC\Documents\Crypto\Atom\tradingBot>node index.js
{
result: ‘error’,
reason: ‘InvalidSignature’,
message: ‘InvalidSignature’
}

Heading over to C++ for now, will come back to this.

Thanks again,

Tyler

  • Is there a known working key and secret I can paste in to my JavaScript to test? If that doesn’t work at least I know the problem is somewhere else…
2 Likes

Hey @Tyler11, I tried your API keys in my script and i got some erros also from your keys.

I dont know why but apparently your account is out of funds, it might be good if you can show me the options actiaved for that API key, aslo double check that the account have funds (it should have like 100K $ and tons of btc and eth, since this is a testing environment, we are not using real money).

I know my code is working good, so it should be able to work with any API keys from gemini sandbox that I setup. Just in case you wanna verify some functions, here is my code:

//GEMINI CONFIG
const GeminiAPI = require("gemini-api").default
/*
//this are my personal API keys, for testing purposes only
const key = "account-5hmfRHz791N4PLpleOmJ";
const secret = "27sn6asLRQkipgKB68XMBR6QpuTq"
const geminiClient = new GeminiAPI({key, secret, sandbox:true});
*/

const key = "account-41t7eE3xxVNwd6A8BySs"
const secret = "6PoyyYUjK3TYtgwzhyFQ8BTup58"
const geminiClient = new GeminiAPI({key, secret, sandbox:true})

//GEMINI LOGIC
/*
// @dev Create new trade order
// @var _amount, float
// @var _price, int
// @var _side, string
// @var _symbol string
*/
function newOrder(_data, callback){
  geminiClient.newOrder({amount:_data.amount,
    price:_data.price,
    side:_data.side,
    symbol:_data.symbol,
    options:_data.options})
    .then(_res => {
      callback(_res)
    })
  .catch(console.error);
}
/*
//Get all trading symbols Ex: "btcusd"
*/
function getAllSymbols(callback){
  geminiClient.getAllSymbols()
  .then(_res => {
    callback(_res)
  })
  .catch(console.error);
}
/*
//get market price and data from a symbol Ex: "btcusd"
// @var _symbol string
*/
function getTicker(_symbol, callback){
  geminiClient.getTicker(_symbol)
  .then(_res => {
    callback(_res)
  })
  .catch(console.error);
}
/*
//cancel an order by ID
// @var _order_id, integer
*/
function cancelOrder(_order_id, callback){
  geminiClient.cancelOrder({order_id:_order_id})
  .then(_res => {
    callback(_res)
  })
  .catch(console.error);
}
/*
//cancel ALL my orders
*/
function cancelAllActiveOrders(callback){
  geminiClient.cancelAllActiveOrders()
  .then(_res => {
    callback(_res)
  })
  .catch(console.error);
}
/*
//get all my trading active orders
// @var _symbol string
*/
function getMyActiveOrders(_symbol, callback){
  geminiClient.getMyActiveOrders({symbol:_symbol})
  .then(_res => {
    callback(_res)
  })
  .catch(console.error);
}
/*
//get status from an order by ID
// @var _order_id, integer
*/
function getMyOrderStatus(_order_id, callback){
  geminiClient.getMyOrderStatus({order_id:_order_id})
  .then(_res => {
    callback(_res)
  })
  .catch(console.error);
}
/*
//get Balances
// @var _symbol string
*/
function getMyAvailableBalances(_symbol, callback){
  geminiClient.getMyAvailableBalances({symbol:_symbol})
  .then(_res => {
    callback(_res)
  })
  .catch(console.error);
}

module.exports =
{
  newOrder,
  getAllSymbols,
  getTicker,
  cancelOrder,
  cancelAllActiveOrders,
  getMyActiveOrders,
  getMyOrderStatus,
  getMyAvailableBalances
}

I think it could be a config on your API keys, try mines just to discard errors in your code.

Carlos Z

Hello again haha!

I tried your code and keys, still can’t get it to work. When I try to run your code there is a 1-2 second pause then the command prompt reappears in my tradingBot folder. There must be a system setting holding me back? I tried using VPN and turned my antivirus off, cmd and powershell as admin. No change.

I found some info on execution policy that may be the problem? Let me know what you think, see below.

Set-ExecutionPolicy Restricted <-- Will not allow any powershell scripts to run.  Only individual commands may be run.

Set-ExecutionPolicy AllSigned <-- Will allow signed powershell scripts to run.

Set-ExecutionPolicy RemoteSigned <-- Allows unsigned local script and signed remote powershell scripts to run.

Set-ExecutionPolicy Unrestricted <-- Will allow unsigned powershell scripts to run.  Warns before running downloaded scripts.

Set-ExecutionPolicy Bypass <-- Nothing is blocked and there are no warnings or prompts.

Thanks again,

Tyler

PS. My default ‘primary’ sandbox account is funded with all permissions checked in API key settings. Also created a Sandbox 'Trading" account which is fully funded with it’s own keys, all permissions checked. Created new user set up as Trader with full permissions. I’ve tried so many things lol. I’m determined to figure this out :slight_smile:

1 Like

Hey @Tyler11, are those “set-executionPolicy” appears to you in the powershell when trying to run the code?

You could try the windows console instead of powershell, some times I also have problems with powershell and then I use the windows console (cmd) and works.

Carlos Z

Hey man… I’ll try running the code on another computer today, will let you know what happens. It should be working, your code doesn’t run on my PC. Going to bed now, I’m long BTC and ETH on ByBit haven’t slept much lately haha!

Thanks,

Tyler

1 Like

Hello everyone getting an error when trying to install yarn add gemini-api on powershell…

PS C:\Course\Algotrading\Code> yarn add gemini-api
yarn : File C:\Users\elgin\AppData\Roaming\npm\yarn.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • yarn add gemini-api
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
1 Like

Hi @Elgin_Que, hope you are great.

You are using powershell to run the commands right? Some times the powershell show that error if you do not open it as administrator, also you could try to use the same command but on windows console (cmd). Try it and let me know if you are facing the same error :nerd_face:

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hi team,

Im based in UK, never looked at programming before doing this course so all very new. I know was recorded a while ago, so just wondering if there is a recommended api to use now, or the ones on the course are perfect?

Thanks

Hi,

In Atom, when I type the code as suggested, it does not create syntax.

Please advise.

Thanks

1 Like

Hi guys, my WPowerShell gets me this message when I try to run buy order
Does somebody know what is it about?
result: ‘error’,
reason: ‘InvalidSignature’,
message: ‘InvalidSignature’

My code looks like this:
const GeminiAPI = require (“gemini-api”).default;
const secret = “2GxkM3sHHFWY48EpdxVLrSzjTq8F”;
const key = “NSzewmv9B4b0i2kzQPza”;
const CCAPIKEY = “9587d57e52f021966c44742c2e36c09c9b48049c3b7e966badef0edb408bdcff”
const restClient = new GeminiAPI ({key, secret, sandbox:true});
restClient.newOrder ({amount:10, price:1100, side:“buy”, symbol:“ethusd”})
.then (response => console.log (response))
.catch (error => console.log (error));

1 Like

Hello There,

I have some troubles to get the first order. Here is my code:
const GeminiAPI = require(“gemini-api”).default;
const secret = “xx”;
const key = “account-xx”;

const restClient = new GeminiAPI({key, secrtet, sandbox:true});

restClient.newOrder({amount:1, price:35000, side:“buy”, symbol:“btcusd”})
.then(response => console.log(response))

And I always get this error (I am using mac btw):

SyntaxError: Error parsing /Users/Sergey/Desktop/Algoritmic Trading/JavaScript/package.json: Unexpected string in JSON at position 11
at parse ()
at readPackage (node:internal/modules/cjs/loader:295:20)
at readPackageScope (node:internal/modules/cjs/loader:320:19)
at shouldUseESMLoader (node:internal/modules/run_main:40:15)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:71:24)
at node:internal/main/run_main_module:17:47 {
path: ‘/Users/Sergey/Desktop/Algoritmic Trading/JavaScript/package.json’
}

also used “.catch(console.error)” (same error)

I think that happens because “package.json” looks like string.

Has anyone ideas how to solve it? thanks!

1 Like

Hey there!

I had the same issue, and the “InvalidSignature” made me suspicious of the key.
In the end I found my key wasn’t correct on the script… probably you already checked this, but just in case…

Alex

1 Like

You have to save the file whit .js at the end to make it a javascript file. EX: fileName.js

Carlos Z.

Hi @Gorana, hope you are great.

@AlexC.
Please check the structure of your API keys, here is a example to follow for this subject:

Carlos Z.

Are you sure you have installed Gemini Api? it should be inside of the node_modules folder.

Carlos Z

Not asking anything, just to say that from when @ivan was making this video, price of btc has gone up 10x :smiling_face_with_three_hearts:

2 Likes