Created
October 12, 2017 22:03
-
-
Save eddanger/356f135af2172f521782742d9277eda5 to your computer and use it in GitHub Desktop.
My little script to check my returns on my bittrex account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const ccxt = require ('ccxt') | |
const asTable = require ('as-table') | |
const log = require ('ololog').configure ({ locate: false }) | |
require ('ansicolor').nice; | |
// The amount of BTC I moved into my Bittrex account | |
const investedBTC = 0.18469975; | |
// The amount of BTC I invested in each currency | |
const investedBTCPerCurrency = { | |
'NEO': 0, | |
'RDD': 0, | |
'SWIFT': 0, | |
'XRP': 0, | |
'EMC2': 0, | |
'QTUM': 0, | |
'CVC': 0, | |
'VTC': 0, | |
'APX': 0.00277011, | |
'XLM': 0, | |
'ETH': 0.18809189 | |
}; | |
(async() => { | |
// instantiate the exchange | |
let bittrex = new ccxt.bittrex ({ | |
'apiKey': 'TOP-secret', | |
'secret': 'TOP-secret' | |
}) | |
try { | |
let totalBTC = 0 | |
let usdPricePerBTC = 0 | |
let markets = await bittrex.loadMarkets() | |
let balance = await bittrex.fetchBalance() | |
let symbol = `BTC/USDT` | |
let marketInfoForSymbol = await bittrex.market(symbol) | |
let ticker = await bittrex.fetchTicker (symbol, '1m') | |
usdPricePerBTC = ticker['last'] | |
for (let index = 0; index < balance.info.length; index++) { | |
let info = balance.info[index] | |
let symbol | |
if (info['Currency'] == 'BTC') { | |
symbol = `${info['Currency']}/USDT` | |
} else { | |
symbol = `${info['Currency']}/BTC` | |
} | |
let marketInfoForSymbol = await bittrex.market(symbol) | |
// console.log(marketInfoForSymbol) | |
if (marketInfoForSymbol['id']) { | |
// log(marketInfoForSymbol) | |
// console.log(await bittrex.fetchOrderBook(marketInfoForSymbol['id'])) | |
// console.log (await bittrex.fetchOHLCV (`${info['Currency']}/BTC`, '1m')) // one minute | |
let ticker = await bittrex.fetchTicker (symbol, '1m') | |
if (info['Currency'] == 'BTC') { | |
usdPricePerBTC = ticker['last'] | |
} | |
let btc | |
if (info['Balance'] > 0) { | |
let btc = info['Balance'] * ticker['last'] | |
if (info['Currency'] == 'BTC') { | |
totalBTC += info['Balance'] | |
} else { | |
totalBTC += info['Balance'] * ticker['last'] | |
let inUSD = usdPricePerBTC * btc | |
let returnPercentage = (btc / investedBTCPerCurrency[info['Currency']] * 100.0) - 100 | |
log( | |
info['Currency'].green, info['Balance'], | |
'Return'.yellow, `${returnPercentage.toFixed(2)}%`, | |
'Last'.green, ticker['last'], | |
'Bid/Ask'.yellow, ticker['bid'], ticker['ask'], | |
'USD'.green, `$${inUSD.toFixed(2)}`, | |
'BTC'.green, btc.toFixed(6), | |
) | |
} | |
// let orders = await bittrex.fetchOrders(symbol) | |
// | |
// console.log(orders) | |
} | |
} | |
} | |
let inUSD = usdPricePerBTC * totalBTC | |
let returnPercentage = (totalBTC / investedBTC * 100.0) - 100 | |
log('-------------------------------------------------------'.yellow) | |
log( | |
'Total BTC'.green, totalBTC.toFixed(6), 'USD'.green, `$${inUSD.toFixed(2)}`, 'Return'.green, `${returnPercentage.toFixed(2)}%` | |
) | |
} catch (e) { | |
if (e instanceof ccxt.DDoSProtection || e.message.includes ('ECONNRESET')) { | |
log.bright.yellow ('[DDoS Protection] ' + e.message) | |
} else if (e instanceof ccxt.RequestTimeout) { | |
log.bright.yellow ('[Request Timeout] ' + e.message) | |
} else if (e instanceof ccxt.AuthenticationError) { | |
log.bright.yellow ('[Authentication Error] ' + e.message) | |
} else if (e instanceof ccxt.ExchangeNotAvailable) { | |
log.bright.yellow ('[Exchange Not Available Error] ' + e.message) | |
} else if (e instanceof ccxt.ExchangeError) { | |
log.bright.yellow ('[Exchange Error] ' + e.message) | |
} else if (e instanceof ccxt.NetworkError) { | |
log.bright.yellow ('[Network Error] ' + e.message) | |
} else { | |
throw e; | |
} | |
} | |
}) () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "cryptobot", | |
"version": "1.0.0", | |
"description": "Make money with robots!", | |
"main": "lib/cryptobot.js", | |
"author": "Michael Wood <[email protected]>", | |
"license": "MIT", | |
"scripts": { | |
"build": "webpack", | |
"test": "yarn build && mocha --compilers js:babel-core/register " | |
}, | |
"devDependencies": { | |
"babel-core": "^6.26.0", | |
"babel-loader": "^7.1.2", | |
"babel-preset-env": "^1.6.0", | |
"babel-preset-es2015": "^6.24.1", | |
"babel-preset-stage-0": "^6.24.1", | |
"webpack": "^3.6.0" | |
}, | |
"dependencies": { | |
"ansicolor": "^1.1.70", | |
"as-table": "^1.0.24", | |
"asciichart": "^1.5.2", | |
"ccxt": "^1.8.69", | |
"node-fetch": "^1.7.3", | |
"ololog": "^1.0.57" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment