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

Hey @Victrix, hope yoy are ok.

I think you are not using the correct commands to install yarn, here is a good tutorial for it:

https://tecadmin.net/install-yarn-macos/

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

Carlos Z.

1 Like

Hi,

I am on Mac

My index.js looks like this:
const GeminiAPI = require(“gemini-api”).default;
const secret = “XXXXXX”;
const key = “account-XXXXXXX”;
const restClient = new GeminiAPI({key, secret, sandbox:true});
//Amount of asset, limit order price
restClient.newOrder({amount:10,price:100,side:“buy”,symbol:“btcusd”})
//To get response
.then(response => console.log(response))
.catch(error => console.error(error));

but it does not seem to work:
{
result: ‘error’,
reason: ‘InvalidSignature’,
message: ‘InvalidSignature’
}

I have also noticed that my package.json file is all green.

How do I fix this? thanks!

1 Like

Hi @jessicayoung , hope you are great.

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

Carlos Z.

In one of the beginning videos for this course (Algo trading and TA), Ivan, you say a knowledge of Javascript (JS) is needed for TA and Algo. You then instruct us to look for JS portion in the “smart contract programing course.” I see 3 courses that contain “smart contract” in the name: Eth smart contract 101, Eth smart contracting 201, and Eth smart contract security. Looking through those mentioned, I don’t see any “JS” section. What am I missing??? Please advise which course you’re talking about, specifically, please, and what the title/section I can find JS listed under. And, is it listed as “JS” or something else?
Thanks,
Nick

1 Like

Hey @Staywell, hope you are ok.

Since the recording of that video, we have been improving the Academy UI a lot, so part of the content is structured in a new way.

Here you can find all the courses: https://academy.ivanontech.com/courses

100% • 75% • 50%

You will find our JavaScript course in that list, also this is the link to it: https://academy.ivanontech.com/products/javascript-programming-for-blockchain-developers

Indeed you need to know JS to move forward into the TA & Algo Trading course which include programming a trading bot in JS.

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

Carlos Z.

Hello, can somebody help me? I get a error in powershell when I start index.js

SyntaxError: Unexpected token ‘.’

I don´t know where is the mistaken.
Thanks for help.

1 Like

Hey @Vikthor, hope you are ok.

You syntax for the async function newOrder is not correct.

The basic structure is:

  geminiClient.newOrder({
    amount:_data.amount,
    price:_data.price,
    side:_data.side,
    symbol:_data.symbol,
    options:_data.options
    })
    .then(_res => {
      console.log(_res)
    })
  .catch(console.error);

.then runs an internal function, so you are missing the brackets {}.

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

Carlos Z.

1 Like

thank you alot Carloz.

hi
i am receiving this message when i try to set the bot to do a new order
image

1 Like

hi @thecil , can you help me with this issue please

1 Like

Hey @Grant38, hope you are great!

I can help you but I need to check your code, please share it so i can review it properly.

But from the console error, apparently you are missing the method to handle the promise of a function, you are requesting a data from an API function but you propably forgot to handle the request with a promise (.then or catch). Any way I will need to see the code to be sure about it! :face_with_monocle:

You can use the “Preformatted Text” Button to encapsulate any kind of code you want to show.


function formatText(){

let words = “I’m a preformatted Text box, Please use me wisely!”

}

prefromatted_text-animated

preformatted text

Carlos Z.

Hello, i have a problem to install Gemini with yarn. i always get the info that yarn cannot get started because Skripts is not activated in the System?
PSSecurity Exception-
UnauthorizedAcess-
I tried a few times but it doesnt work!

Would be grat if i can get help!

Thanks

1 Like

Hello I need help. My programm says allways

Executing strategy
C:\Users\24118\Dropbox\1 IVAN Academy\Java Script\Atom\Ivan trading bot\index.js:13
indicators.hourlyMovingAverage(“BTC”,“USD”,100,function(ma){
^

TypeError: indicators.hourlyMovingAverage is not a function
at strategy (C:\Users\24118\Dropbox\1 IVAN Academy\Java Script\Atom\Ivan trading bot\index.js:13:14)
at Object. (C:\Users\24118\Dropbox\1 IVAN Academy\Java Script\Atom\Ivan trading bot\index.js:19:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47

but I dont found the mistake in code:

here is indicators.js

const CCAPIKey = “551639c4572f4d251d15d92936f3bbbe713c93dbd567681849ded2cfbcabb498”
const CryptoCompareAPI = require(“cryptocompare”);
CryptoCompareAPI.setApiKey(CCAPIKey);

module.export = {

hourlyMovingAverage:function(cryptoAsset,fiatCurrency,hours,callback){

if(hours>169){
  console.error("Only 169 allowed!")
  return
}

// 1 get data from CC
CryptoCompareAPI.histoHour(cryptoAsset, fiatCurrency)
.then(data => {
  // 2 caculate MA from 100 past hours
  data = data.reverse()
  var sum = 0;
  for(var i = 0;i<hours;i++){
    sum+=data[i].close;
  }

  var movingAverage = Math.floor(sum/hours);
  callback(movingAverage);

})
.catch(console.error)

}

}

and here the index.js:

global.fetch = require(“node-fetch”);
const indicators = require("./indicators.js");
const exchange = require("./exchange.js")

var strategy = function(){
// IF BTC < MA ==> buy (if we have no position)
// IF BTC > MA ==> sell (if we have a position)

console.log(“Executing strategy”);

indicators.hourlyMovingAverage(“BTC”,“USD”,100,function(ma){
console.log("MA: ", ma);
setTimeout(strategy,1000);
})

}

strategy();

Why ist says:
TypeError: indicators.hourlyMovingAverage is not a function

thanks for the help.

1 Like

adding

account

and

catch

Really fixed it, but then I got

node index.js
<html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.

Hey @MartinK, hope you great.

Could you please provide an Screenshot on the problem you are facing? That can give us a better picture on the error that the console is showing to you :nerd_face:

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

Carlos Z.

Hey @Vikthor, hope you are ok.

Could you please share the code properly to run it?

Also apparently you have an error with the syntax starting at:

hourlyMovingAverage:function(cryptoAsset,fiatCurrency,hours,callback)

Try to have an space between the name of the module to export and the function, ending up like this:

hourlyMovingAverage: function(cryptoAsset,fiatCurrency,hours,callback)

Here you can find my repository so you can use it has guide line:
https://github.com/thecil/TA_AlgoCourse

You can use the “Preformatted Text” Button to encapsulate any kind of code you want to show.


function formatText(){

let words = “I’m a preformatted Text box, Please use me wisely!”

}

prefromatted_text-animated

preformatted text

Carlos Z.

@thecil
image

1 Like

i fixed my issue i think.

the trick was to write SUDO ahhead of the npm command.

" sudo npm install yarn --global "

for all the mac users that ran into the access denied issue

1 Like

try with .then(response => { console.log(response) } );

Carlos Z

Hello @thecil Carloz, unfortunatly problem not solved. I now loaded the code to github. Can you please check there and tell me my mistake?

Thanks Vikthor

https://github.com/Vikthor1981/trading_bot.git

1 Like