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/
-
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"
}
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/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/Coinmarket.js b/src/model/Coinmarket.js
index f26c811..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
@@ -27,7 +29,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)
@@ -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
}
}
@@ -131,11 +134,21 @@ 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
}
+
+ /**
+ * 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]
+ }
+ }
}
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/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)
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))
+ })
})