Skip to content

Instantly share code, notes, and snippets.

@doorbash
Last active February 19, 2021 06:26
Show Gist options
  • Select an option

  • Save doorbash/570fdcc59e825ceb366c7e6a6272ab52 to your computer and use it in GitHub Desktop.

Select an option

Save doorbash/570fdcc59e825ceb366c7e6a6272ab52 to your computer and use it in GitHub Desktop.
const Binance = require('node-binance-api');
const binance = new Binance().options({
APIKEY: '***',
APISECRET: '***'
});
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json')
const db = low(adapter)
db.defaults({ pairs: [] }).write()
setInterval(() => {
(async () => {
console.log("getting pairs...")
let ticker = await binance.prices();
let entries = Object.entries(ticker).filter(pair => pair[0].endsWith("BUSD") && pair[0].includes("MARS"))
console.log("number of pairs: " + entries.length)
let pairs = db.get('pairs')
for (var i = 0; i < entries.length; i++) {
let pair = entries[i]
if (pair[1] > 0) {
if (pairs.find({ symbol: pair[0] }).value() === undefined) {
// NEW PAIR
let price = pair[1]
let quantity = (50 / price).toFixed(1);
console.log("trying to buy " + quantity + " amount of " + pair[0] + " ...")
binance.marketBuy(pair[0], quantity, (error, response) => {
if (error != null) {
console.error("error", error)
} else {
pairs.push({ symbol: pair[0], price: pair[1] }).write()
// console.info("Market Buy response", response);
console.log("bought " + response["executedQty"] + " amount of " + response["symbol"] + ", cummulativeQuoteQty: " + response["cummulativeQuoteQty"] + " BUSD")
console.log("[!] new pair added : " + pair[0])
}
});
break
}
}
}
})()
}, 10000)
{
"name": "binance",
"version": "1.0.0",
"description": "Binance",
"main": "src/index.js",
"dependencies": {
"node-binance-api": "^0.12.4",
"lowdb": "^1.0.0"
},
"devDependencies": {},
"scripts": {
"start": "node src/index.js"
},
"author": "Milad Doorbash",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment