Hey @VincentC, hope you are ok.
As @cryptoforyou has mention, your declaration if incorrect.
You have getALLSymbols()
where it should be getAllSymbols
.
Carlos Z
Hey @VincentC, hope you are ok.
As @cryptoforyou has mention, your declaration if incorrect.
You have getALLSymbols()
where it should be getAllSymbols
.
Carlos Z
whoops, those ()s atrnt part of the code
im having trouble getting the “Hold” portion of the loop coming back. It always ends after confirming the buy. what have i done now??
//Index
global.fetch = require("node-fetch");
const indicators = require("./indicators.js");
const exchange = require("./exchange.js");
var hasPosition = false;
var strategy = function(){
//IF BTC < MA ==> BUY (If we have no position)
//IF BTC > ma ==> SELL (if we have a position)
console.log(" ");
console.log("=================");
console.log("Executing strategy");
indicators.hourlyMovingAverage("BTC", "USD", 100, function(ma){
exchange.bitcoinPrice()
.then(res => {
var price = res.last;
console.log("MA:", ma);
console.log("price:", price);
if(price < ma && !hasPosition){
console.log("buy!");
exchange.marketBuyBitcoin()
.then(res=>{
console.log("buy successful");
hasPosition = true;
setTimeout(strategy,1000);
})
.catch(error => console.error)
}
else if(price > ma && hasPosition){
console.log("sell!");
exchange.marketBuyBitcoin()
.then(res=>{
console.log("Sell successful");
hasPosition = false;
setTimeout(strategy,1000);
})
.catch(error => console.error)
}
else{
console.log("hold");
setTimeout(strategy,1000);
}
})
});
}
strategy();
//exchange
module.exports = {
marketBuyBitcoin:function(){
return restClient.newOrder({amount:1, price:100000, side:"buy", symbol:"btcusd", options:["immediate-or-cancel"]})
},
marketSellBitcoin:function(){
return restClient.newOrder({amount:1, price:1, side:"sell", symbol:"btcusd", options:["immediate-or-cancel"]})
},
bitcoinPrice:function(){
return restClient.getTicker("btcusd");
}
}
//Indicators
module.exports = {
hourlyMovingAverage:function hMovingAverage(cryptoAsset, fiatCurrency, hours, callback){
if(hours>169){
console.error("only up to 169 hours allowed!")
return
}
CryptoCompareAPI.histoHour(cryptoAsset, fiatCurrency)
.then(data => {
data = data.reverse();
var sum = 0;
for(var i = 0;i<hours;i++){
sum+=data[i].close;
}
var hMovingAverage = Math.floor(sum/hours);
callback(hMovingAverage);
})
.catch(console.error);}
,
dailyMovingAverage:function dMovingAverage(cryptoAsset,fiatCurrency,days,callback){
if(days>300){
console.error("only up to 300 days allowed!")
return
}
CryptoCompareAPI.histoDay(cryptoAsset, fiatCurrency, {limit:"none"})
.then(data => {
data = data.reverse();
var sum = 0;
for(var i = 0;i<days;i++){
sum+=data[i].close;
}
var dMovingAverage = sum/days;
callback(dMovingAverage);
})
.catch(console.error);}
,
minutelyMovingAverage:function mMovingAverage(cryptoAsset,fiatCurrency,minutes,callback){
if(minutes>1400){
console.error("only up to 1440 minutes allowed!")
return
}
CryptoCompareAPI.histoMinute(cryptoAsset, fiatCurrency)
.then(data => {
data = data.reverse();
var sum = 0;
for(var i = 0;i<minutes;i++){
sum+=data[i].close;
}
var mMovingAverage = sum/minutes;
callback(mMovingAverage);
})
.catch(console.error);}
};
Please can someone help me. I’m on lecture 14 of the bot programming section and everytime I enter node index.js it keeps showing me this warning:
(node:10140) UnhandledPromiseRejectionWarning: #
(Use node --trace-warnings ...
to show where the warning was created)
(node:10140) 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:10140) [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.
If anyone can assist I would really appreciate it! Thanks
can you copy your code or screen shot plz? hope all is well!
I need help.
Error: Cannot find module ‘gemini-api’
Require stack:
i keep getting this error code. what am I doing wrong?
Hi Vincent, I think I managed to solve it. I was incorrectly adding npm to wrong directory. Thanks for responding, I’ll definitely be in contact if I run into any other errors!
Hi Vincent, here is the code. I thought I fixed it but I keep running into the same problem. Thanks in advance for your help.
Here is my code from Atom
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?
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
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.
Hello everyone i have an issue. When i type "yarn add gemini-api " i get an error .
Please help me
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 . (thats why we pick gemini for the course, they do have a sandbox to play around).
Carlos Z
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
you are not assigning the value with =
Carlos Z