Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
benmarten committed Jan 6, 2018
2 parents d8f45a7 + 6e2e590 commit 3757d50
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 17 deletions.
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -49,6 +51,7 @@ crashlytics.properties
crashlytics-build.properties
fabric.properties


### NodeJS

# Logs
Expand Down Expand Up @@ -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/

17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
<a name="1.6.0"></a>
# [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))



<a name="1.5.1"></a>
## [1.5.1](https://github.com/benmarten/CryptoETF/compare/1.5.0...1.5.1) (2018-01-01)

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 3 additions & 0 deletions settings.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"apiSecret": ""
}]
},
"symbolNameMapping": {
"Bitgem": "BITG"
},
"symbolMapping": {
"USD": "USDT",
"STR": "XLM",
Expand Down
10 changes: 4 additions & 6 deletions src/Utils.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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' : ''
}
}
23 changes: 18 additions & 5 deletions src/model/Coinmarket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// noinspection NpmUsedModulesInstalled
import request from 'request-promise'
import Coin from './Coin'
import * as Settings from './../Settings'


let coins = {}
let totalMarketCapUsd
Expand All @@ -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)
Expand All @@ -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 => {
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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]
}
}
}
5 changes: 3 additions & 2 deletions src/model/Portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/model/testCoinmarket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

0 comments on commit 3757d50

Please sign in to comment.