From 666e30555a03ea6c37d91a0f58afb17770364390 Mon Sep 17 00:00:00 2001 From: Ben Marten Date: Fri, 5 Jan 2018 17:02:01 -0800 Subject: [PATCH 1/7] fix(ui): fix rebalance indicator --- src/Utils.js | 10 ++++------ src/model/Portfolio.js | 5 +++-- test/testUtils.js | 5 +++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Utils.js b/src/Utils.js index 6e6e1b3..51a47e1 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -1,5 +1,3 @@ -import * as Settings from './Settings' - export default class Utils { static pad(width, string, padding) { return (width <= string.length) ? string : this.pad(width, padding + string, padding) @@ -40,12 +38,12 @@ export default class Utils { } /** - * Determines if drift is above treshold defined in settings. + * Determines if drift is above the provided treshold. * @param drift The current drift. + * @param treshold The treshold. * @return {string} 'Y', if drifted, '' if not. */ - static hasDriftedAboveTreshold(drift) { - return (Math.abs(drift) * 100 > (Settings.options.rebalanceDeltaTotalPct || - Settings.options.rebalanceDeltaPct)) ? 'Y' : '' + static hasDriftedAboveTreshold(drift, treshold) { + return (Math.abs(drift) * 100 > treshold) ? 'Y' : '' } } diff --git a/src/model/Portfolio.js b/src/model/Portfolio.js index dae18d8..8be8b70 100644 --- a/src/model/Portfolio.js +++ b/src/model/Portfolio.js @@ -162,7 +162,7 @@ export default class Portfolio { Format.bitcoin((targetBtc - coin.getBtcValue()) / Coinmarket.getBtcEth(), 8), Format.money(targetUsd - coin.getUsdValue()), Format.percent(drift), - Utils.hasDriftedAboveTreshold(drift), + Utils.hasDriftedAboveTreshold(drift, Settings.options.rebalanceDeltaPct), coin.getExchangesString() ]) targetSum['allocationActualPct'] += allocationActualPct || 0 @@ -186,7 +186,8 @@ export default class Portfolio { '', Format.money(targetSum['targetUsd'] - this.getSumUsd()), Format.percent(drift), - Utils.hasDriftedAboveTreshold(drift), + Utils.hasDriftedAboveTreshold(drift, (Settings.options.rebalanceDeltaTotalPct || + Settings.options.rebalanceDeltaPct)), '']) // noinspection JSUnusedGlobalSymbols diff --git a/test/testUtils.js b/test/testUtils.js index 1a5dd06..aff549e 100644 --- a/test/testUtils.js +++ b/test/testUtils.js @@ -12,4 +12,9 @@ describe('Testing utils', () => { assert(Utils.round(1.5666, 2) === 1.57) assert(Utils.round(1.5666, 10) === 1.5666) }) + + it('Test hasDriftedAboveTreshold', () => { + assert(Utils.hasDriftedAboveTreshold(0.11, 10)) + assert(!Utils.hasDriftedAboveTreshold(0.09, 10)) + }) }) From 860ac07c77676ff244a3873c96cf05130ec24163 Mon Sep 17 00:00:00 2001 From: Ben Marten Date: Fri, 5 Jan 2018 17:31:37 -0800 Subject: [PATCH 2/7] fix(coinmarket): fix logic that returns only topX coins --- src/model/Coinmarket.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/model/Coinmarket.js b/src/model/Coinmarket.js index f26c811..15f73fd 100644 --- a/src/model/Coinmarket.js +++ b/src/model/Coinmarket.js @@ -131,9 +131,9 @@ export default class Coinmarket { static getCoins(limit) { let result = {} for (let key in coins) { - result[key] = new Coin(coins[key].symbol, 0, null, coins[key].rank) - if (result[key].rank === limit) { - break + let coin = coins[key] + if (!limit || parseInt(coin.rank) <= limit) { + result[key] = new Coin(coin.symbol, 0, null, coin.rank) } } return result From 3398def13f23f78e3ab444a10ad21d1224e23a94 Mon Sep 17 00:00:00 2001 From: Ben Marten Date: Fri, 5 Jan 2018 17:31:06 -0800 Subject: [PATCH 3/7] test(coinmarket): fix coinmarkettest related to all coin change --- test/model/testCoinmarket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/model/testCoinmarket.js b/test/model/testCoinmarket.js index 21bf1a2..351b51a 100644 --- a/test/model/testCoinmarket.js +++ b/test/model/testCoinmarket.js @@ -35,7 +35,7 @@ describe('Testing coinmarketcap.com integration', () => { it('test getCoins, and limit', async () => { await Coinmarket.init() let result = await Coinmarket.getCoins() - assert(Object.keys(result).length === 100) + assert(Object.keys(result).length > 0) result = await Coinmarket.getCoins(10) assert(Object.keys(result).length === 10) result = await Coinmarket.getCoins(1) From e19ae53bc4b7d4270d7ca131f32f684bc146bad2 Mon Sep 17 00:00:00 2001 From: Ben Marten Date: Fri, 5 Jan 2018 17:06:51 -0800 Subject: [PATCH 4/7] chore(*): add vim to gitignore --- .gitignore | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dcf1fa2..72190ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# Global Gitignore templates from here: https://github.com/github/gitignore + ### WebStorm # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 @@ -49,6 +51,7 @@ crashlytics.properties crashlytics-build.properties fabric.properties + ### NodeJS # Logs @@ -111,9 +114,25 @@ typings/ .env +### Vim +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] + +# Session +Session.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags + + ### Other .DS_Store settings.json yarn.lock dist/ - From 45a72f2e99214fcc731bffc657cd0234b30e16a4 Mon Sep 17 00:00:00 2001 From: Jesse CreateThis Date: Thu, 4 Jan 2018 14:26:10 -0500 Subject: [PATCH 5/7] feat(coinmarket): include all possible coins --- src/model/Coinmarket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/Coinmarket.js b/src/model/Coinmarket.js index 15f73fd..1ee687c 100644 --- a/src/model/Coinmarket.js +++ b/src/model/Coinmarket.js @@ -27,7 +27,7 @@ export default class Coinmarket { static _getCoinStats() { let options = { - uri: 'https://api.coinmarketcap.com/v1/ticker/', + uri: 'https://api.coinmarketcap.com/v1/ticker/?limit=0', json: true } return request(options) From 50bd63cfd95f973d10773696a95ef882a60b40ab Mon Sep 17 00:00:00 2001 From: Ben Marten Date: Sat, 6 Jan 2018 12:22:20 -0800 Subject: [PATCH 6/7] fix(coinmarket): fixed duplicate symbol handling --- settings.example.json | 3 +++ src/model/Coinmarket.js | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/settings.example.json b/settings.example.json index ddbd454..2807da6 100644 --- a/settings.example.json +++ b/settings.example.json @@ -38,6 +38,9 @@ "apiSecret": "" }] }, + "symbolNameMapping": { + "Bitgem": "BITG" + }, "symbolMapping": { "USD": "USDT", "STR": "XLM", diff --git a/src/model/Coinmarket.js b/src/model/Coinmarket.js index 1ee687c..a859a68 100644 --- a/src/model/Coinmarket.js +++ b/src/model/Coinmarket.js @@ -1,6 +1,8 @@ // noinspection NpmUsedModulesInstalled import request from 'request-promise' import Coin from './Coin' +import * as Settings from './../Settings' + let coins = {} let totalMarketCapUsd @@ -45,7 +47,7 @@ export default class Coinmarket { * @prop coin.market_cap_usd The market cap for the given coin in USD. */ static init() { - console.log('Retrieving coinmarketcap statistics...') + console.log('Retrieving Coinmarketcap statistics...') return this._getTotalMarketCapUsd().then(_totalMarketCapUsd => { totalMarketCapUsd = _totalMarketCapUsd return this._getCoinStats().then(coinsRefreshed => { @@ -54,6 +56,7 @@ export default class Coinmarket { let coin = coinsRefreshed[i] if (coin) { coin['market_cap_pct'] = coin.market_cap_usd / totalMarketCapUsd + this.modifySymbolIfNeeded(coin) coins[coin.symbol] = coin } } @@ -138,4 +141,14 @@ export default class Coinmarket { } return result } + + /** + * This modifies the symbol based on the settings. This is needed because there are two coins with BTG symbol. + * @param coin The raw coin. + */ + static modifySymbolIfNeeded(coin) { + if (Settings.symbolNameMapping && Settings.symbolNameMapping[coin.name]) { + coin.symbol = Settings.symbolNameMapping[coin.name] + } + } } From 6e2e590f01959666f001b1caf79b9e22a44b04c8 Mon Sep 17 00:00:00 2001 From: Ben Marten Date: Sat, 6 Jan 2018 12:53:39 -0800 Subject: [PATCH 7/7] CryptoETF 1.6.0 --- CHANGELOG.md | 17 +++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 588d106..c1a756d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ + +# [1.6.0](https://github.com/benmarten/CryptoETF/compare/1.5.1...1.6.0) (2018-01-06) + + +### Bug Fixes + +* **coinmarket:** fix logic that returns only topX coins ([860ac07](https://github.com/benmarten/CryptoETF/commit/860ac07)) +* **coinmarket:** fixed duplicate symbol handling ([50bd63c](https://github.com/benmarten/CryptoETF/commit/50bd63c)) +* **ui:** fix rebalance indicator ([666e305](https://github.com/benmarten/CryptoETF/commit/666e305)) + + +### Features + +* **coinmarket:** include all possible coins ([45a72f2](https://github.com/benmarten/CryptoETF/commit/45a72f2)) + + + ## [1.5.1](https://github.com/benmarten/CryptoETF/compare/1.5.0...1.5.1) (2018-01-01) diff --git a/package-lock.json b/package-lock.json index 8580b1c..3c84057 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5402,5 +5402,5 @@ "integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc=" } }, - "version": "1.5.1" + "version": "1.6.0" } diff --git a/package.json b/package.json index 98ccc21..e3506c0 100644 --- a/package.json +++ b/package.json @@ -31,5 +31,5 @@ "testLocal": "./node_modules/.bin/nyc mocha --require babel-core/register test/**/*.js test/**/**/*.js", "test": "NODE_ENV=test npm run testLocal" }, - "version": "1.5.1" + "version": "1.6.0" }