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

Hi Terry, where do I find the account key? Thank you :slight_smile:

I had the same problem…for me the problem was that I was missing the ‘s’ on ‘export’…

Hi, I’m trying to execute a BTC market order by using use the “immediate-or-cancel” order execution option, coupled with an aggressive limit price but not able to execute it and powershell is returning reason: ‘ExceedsPriceLimits’,


  order_id: '1023980881',
  id: '1023980881',
  symbol: 'btcusd',
  exchange: 'gemini',
  avg_execution_price: '0.00',
  side: 'buy',
  type: 'exchange limit',
  timestamp: '1629110166',
  timestampms: 1629110166725,
  is_live: false,
  is_cancelled: true,
  is_hidden: false,
  was_forced: false,
  executed_amount: '0',
  client_order_id: 'niS10hCxy',
  reason: 'ExceedsPriceLimits',
  options: [ 'immediate-or-cancel' ],
  price: '50000.00',
  original_amount: '1',
  remaining_amount: '1'

Here’s my code…any advice?

restClient.newOrder({
  amount:1,
  price:50000,
  side:"buy",
  symbol:"btcusd",
  options:["immediate-or-cancel"]
})
.then(res=>console.log(res))
.catch(error=>console.error(error));

I managed to execute an ETH market order but not BTC…

 order_id: '1024089476',
  id: '1024089476',
  symbol: 'ethusd',
  exchange: 'gemini',
  avg_execution_price: '3276.54',
  side: 'buy',
  type: 'exchange limit',
  timestamp: '1629117975',
  timestampms: 1629117975434,
  is_live: false,
  is_cancelled: false,
  is_hidden: false,
  was_forced: false,
  executed_amount: '1',
  client_order_id: 'HCJRsLgnM',
  options: [ 'immediate-or-cancel' ],
  price: '4800.00',
  original_amount: '1',
  remaining_amount: '0'
1 Like

same issue here realy gettting to me

thanks this video could do with an update as its quite old and newbies will struggle after dong all of the above im getting this
SyntaxError: Unexpected token ‘.’
←[90m at wrapSafe (internal/modules/cjs/loader.js:988:16)←[39m
←[90m at Module._compile (internal/modules/cjs/loader.js:1036:27)←[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
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m

1 Like

result: ‘error’,
reason: ‘InvalidSignature’,
message: ‘InvalidSignature’

after altering the code i then get this

result: ‘error’,
reason: ‘MissingAccounts’,
message: ‘Expected a JSON payload with accounts’

1 Like

Hey @cryptocol, wejobs, hope you guys are ok.

Would be great if you can share your code on the following way, so i can replicate the issue and help you solve it :face_with_monocle:

Carlos Z

1 Like

const GeminiAPI = require(“gemini-api”).default;
const secret = “master-434343434”;
const key = “3434343434”;
const restClient = new GeminiAPI ({key, secret, sandbox:true});

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

@thecil thanks for the quick reply

1 Like

Thanks @thecil I finished the course using eth instead of btc and got the trading bot to work out okay… :grinning:

1 Like

your accounts values are incorrect, here is an example on how it should look like:

const key = "account-434343434";
const secret = "3434343434"

Carlos Z

1 Like

hi
now throwin the error
Error: Cannot find module ‘C:\index.js’
←[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:745:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
code: ←[32m’MODULE_NOT_FOUND’←[39m,
requireStack: []

thnaks alot sir saved me some time @Hank

finally fixed changed api to primary and not master

thanks so much

1 Like

Hi All!

Has someone encountered this error yet?

Code:

const GeminiAPI = require("gemini-api").defeault;
const secrett = "account-2LmPDdKwxRHLGLZScJR4VNHKEqzY";
const key = "EDYa9Us199Dh8tPyP6Pj";
const restClient = new GeminiAPI({key, secrett, sandbox:true});

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

I got following error in powershell:

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

TypeError: GeminiAPI is not a constructor
at Object. (C:\Users\Riki\Desktop\Algorithmic Trading\index.js:4:20)
←[90m at Module._compile (internal/modules/cjs/loader.js:1063:30)←[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

found it! Always so easy to mistype.

hi guys can i get some assistance in setting up a bot that can covert to usdt at its highest point
and convert to btc at its lowest point please on the hourly time frame

HELLO, I NEED HEL WITH MY PROGRAM, I AM FOLLOWING INSTRUCTION ON THE VIDEO, BUT I DONT KNOW HOW TO ADDRESS THIS ERROR. PLEASE HELP!!

PS C:\Users\Brend\Desktop\TRADING BOT> node index.js
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^

[UnhandledPromiseRejection: 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(). The promise rejected with the reason “#”.] {
code: ←[32m’ERR_UNHANDLED_REJECTION’←[39m
}

THIS IS THE CODE I AM USING, I DELETED THE KEYS.

const GeminiAPI = require(“gemini-api”).default;

const secret = “”;
const key = “”;

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

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

Hello Guys!

I am on the CrytoCompare section and have run into the following problem:

This is my code:

global.fetch = require("node-fetch");
const GeminiAPI = require("gemini-api").default;
const secret = "account-2LmPDdKwxRHLGLZScJR4VNHKEqzY";
const key = "EDYa9Us199Dh8tPyP6Pj";
const restClient = new GeminiAPI({key, secret, sandbox:true});
const CCAPIKey = "7070fb1cec78efbc4e88a389419001a97a0e232562f374c1321e3b03ebb7bc5f";

const CryptoCompareAPI = require("cryptocompare");
CryptoCompareAPI.setApiKey(CCAPIKey);

/*restClient.newOrder({amount:10,price:650,side:"buy", symbol: "ethusd"})
.then(response => restClient.cancelOrder({order_id:response.order_id}))
.then(response => console.log(response))
.catch(console.error);*/

CryptoCompareAPI.coinList()
.then(coinList => {
  console.log(coinList)
})
.catch(console.error);

If I run the code I got the following message in PS: internal/modules/cjs/loader.js:1080
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\Riki\Desktop\Algorithmic Trading\node_modules\node-fetch\src\index.js
require() of ES modules is not supported.
require() of C:\Users\Riki\Desktop\Algorithmic Trading\node_modules\node-fetch\src\index.js from C:\Users\Riki\Desktop\Algorithmic Trading\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\Riki\Desktop\Algorithmic Trading\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\Riki\Desktop\Algorithmic Trading\node_modules\node-fetch\package.json.

So if I understand this correctly I need to change the node fetch requrie part to import, if I do I got the following error:

import

this fetch thing is in the cryptocompare => index.js file and just having a return value, nothing else.

   return fetch(url)
    .then(res => {
      if (!res.ok) {
        throw new Error(`${res.status} ${res.statusText}`)
      }
      return res.json()
    })
    .then(body => {
      if (body.Response === 'Error') throw body.Message
      return body
    })
}

Any thoughts on this?