Skip to content

Commit 129ecc1

Browse files
committed
Merge branch 'release/1.5.0'
2 parents 40c67d3 + f450315 commit 129ecc1

9 files changed

Lines changed: 134 additions & 65 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
<a name=""></a>
2+
# 1.5.0
3+
4+
5+
### Bug Fixes
6+
7+
* **integrations:** fix binance module typo ([#12](https://github.com/benmarten/CryptoETF/issues/12)) ([e6e75ca](https://github.com/benmarten/CryptoETF/commit/e6e75ca))
8+
9+
10+
### Features
11+
12+
* **integration:** implement Bitgrail API ([#11](https://github.com/benmarten/CryptoETF/issues/11)) ([e31c2f2](https://github.com/benmarten/CryptoETF/commit/e31c2f2))
13+
14+
15+
116
<a name=""></a>
217
# 1.4.0
318

@@ -6,7 +21,7 @@
621

722
* adds option to hide missing coins ([3fd1b9c](https://github.com/benmarten/CryptoETF/commit/3fd1b9c))
823
* save output to file ([0de2b1f](https://github.com/benmarten/CryptoETF/commit/0de2b1f))
9-
* **integration:** adds GDAX integration ([#10](https://github.com/benmarten/CryptoETF/issues/10)) ([e91975a](https://github.com/benmarten/CryptoETF/commit/e91975a))
24+
* **integration:** add GDAX integration ([#10](https://github.com/benmarten/CryptoETF/issues/10)) ([e91975a](https://github.com/benmarten/CryptoETF/commit/e91975a))
1025
* **integration:** adds Kraken integration ([#7](https://github.com/benmarten/CryptoETF/issues/7)) ([7e1ba78](https://github.com/benmarten/CryptoETF/commit/7e1ba78))
1126

1227
<a name=""></a>

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CryptoETF has API integrations with the following exchanges:
2727
- HitBTC. Join Here: https://hitbtc.com/?ref_id=5a3596f643b9e
2828
- Bitfinex. Join Here: https://www.bitfinex.com
2929
- Kraken. Join Here: https://www.kraken.com
30+
- Bitgrail. Join Here: https://bitgrail.com
3031

3132
With these exchanges, you can easily build yourself your own CryptoETF.
3233

settings.example.json

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,54 @@
11
{
22
"accounts": {
3-
"poloniex": [
4-
{
3+
"poloniex": [{
4+
"apiKey": "",
5+
"apiSecret": ""
6+
}],
7+
"coinbase": [{
8+
"apiKey": "",
9+
"apiSecret": ""
10+
}],
11+
"gdax": [{
12+
"apiKey": "",
13+
"apiSecret": "",
14+
"password": ""
15+
}],
16+
"bittrex": [{
17+
"apikey": "",
18+
"apisecret": ""
19+
}],
20+
"binance": [{
21+
"key": "",
22+
"secret": ""
23+
}],
24+
"hitbtc": [{
25+
"apiKey": "",
26+
"apiSecret": ""
27+
}],
28+
"bitfinex": [{
29+
"apiKey": "",
30+
"apiSecret": ""
31+
}],
32+
"kraken": [{
33+
"apiKey": "",
34+
"apiSecret": ""
35+
}],
36+
"bitgrail": [{
537
"apiKey": "",
638
"apiSecret": ""
7-
}
8-
],
9-
"coinbase": [
10-
{
11-
"apiKey": "",
12-
"apiSecret": ""
13-
}
14-
],
15-
"gdax": [
16-
{
17-
"apiKey": "",
18-
"apiSecret": "",
19-
"password": ""
20-
}
21-
],
22-
"bittrex": [
23-
{
24-
"apikey": "",
25-
"apisecret": ""
26-
}
27-
],
28-
"binance": [
29-
{
30-
"key": "",
31-
"secret": ""
32-
}
33-
],
34-
"hitbtc": [
35-
{
36-
"apiKey": "",
37-
"apiSecret": ""
38-
}
39-
],
40-
"bitfinex": [
41-
{
42-
"apiKey": "",
43-
"apiSecret": ""
44-
}
45-
],
46-
"kraken": [
47-
{
48-
"apiKey": "",
49-
"apiSecret": ""
50-
}
51-
]
39+
}]
5240
},
5341
"symbolMapping": {
5442
"USD": "USDT",
5543
"STR": "XLM",
5644
"IOTA": "MIOTA",
5745
"XBT": "BTC"
5846
},
59-
"otherHoldings": [
60-
{
61-
"BCH": 1.0
62-
},
63-
{
64-
"BTG": 1.0
65-
}
66-
],
47+
"otherHoldings": [{
48+
"BCH": 1.0
49+
}, {
50+
"BTG": 1.0
51+
}],
6752
"options": {
6853
"targetValueUsd": 50000,
6954
"rebalanceDeltaPct": 1.0,

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Portfolio from './model/Portfolio'
22
import Coinmarket from './model/Coinmarket'
33
import Coin from './model/Coin'
44
import Utils from './Utils'
5-
import fs from 'fs';
5+
import fs from 'fs'
66

77
const settings = require('../settings.json')
88

@@ -46,10 +46,10 @@ async function refreshPortfolio() {
4646
Portfolio.removeCoin('USDT')
4747

4848
if (settings.outputFile) {
49-
fs.writeFile(settings.outputFile, Portfolio.getJson(), 'utf8', function(err){
50-
if (err) throw err;
49+
fs.writeFile(settings.outputFile, Portfolio.getJson(), 'utf8', function(err) {
50+
if (err) throw err
5151
console.log(`Saved data to ${settings.outputFile}...`)
52-
});
52+
})
5353
}
5454

5555

src/model/Portfolio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,6 @@ export default class Portfolio {
225225
}
226226

227227
static getJson() {
228-
return JSON.stringify(portfolio, null, 2);
228+
return JSON.stringify(portfolio, null, 2)
229229
}
230230
}

src/model/integrations/BinanceWallet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PromiseUtils from '../../PromiseUtils'
22
import Coin from '../Coin'
33
// noinspection NpmUsedModulesInstalled
4-
import Binance from 'Binance'
4+
import Binance from 'binance'
55

66
const settings = require('../../../settings.json')
77

@@ -40,4 +40,4 @@ export default class BinanceWallet {
4040
}
4141
)
4242
}
43-
}
43+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import PromiseUtils from '../../PromiseUtils'
2+
import Coin from '../Coin'
3+
// noinspection NpmUsedModulesInstalled
4+
import request from 'request-promise'
5+
import crypto from 'crypto'
6+
import querystring from 'querystring'
7+
8+
const settings = require('../../../settings.json')
9+
10+
export default class BitgrailWallet {
11+
static getBalance() {
12+
return PromiseUtils.forEachPromise(settings.accounts.bitgrail, this._getBalanceForCredential)
13+
}
14+
15+
/**
16+
* Returns the balances for a Bitgrail account.
17+
* @param credential The Bitgrail api credentials.
18+
* @return {Promise} The account balances.
19+
*/
20+
static _getBalanceForCredential(credential) {
21+
return new Promise((resolve, reject) => {
22+
let params = {
23+
'nonce': new Date().getTime()
24+
}
25+
let options = {
26+
method: 'POST',
27+
uri: 'https://bitgrail.com/api/v1/balances',
28+
form: params,
29+
json: true,
30+
headers: {
31+
'KEY': credential.apiKey,
32+
'SIGNATURE': BitgrailWallet._signParameters(credential, params)
33+
}
34+
}
35+
return request(options)
36+
.then(data => {
37+
let result = []
38+
let balances = data.response
39+
for (let symbol in balances) {
40+
let amount = balances[symbol].balance
41+
result.push(new Coin(symbol, amount, 'Bitgrail'))
42+
}
43+
resolve(result)
44+
45+
})
46+
.catch(err => {
47+
reject(err)
48+
})
49+
}
50+
)
51+
}
52+
53+
static _signParameters(credential, body) {
54+
body = querystring.stringify(body)
55+
let hmac = crypto.createHmac('sha512', credential.apiSecret)
56+
return hmac.update(body).digest('hex')
57+
}
58+
}

src/model/integrations/KrakenWallet.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default class KrakenWallet {
1717
*/
1818
static _getBalanceForCredential(credential) {
1919
return new Promise((resolve, reject) => {
20-
const kraken = new KrakenClient(credential.apiKey, credential.apiSecret, {timeout: 10000});
20+
const kraken = new KrakenClient(credential.apiKey, credential.apiSecret, {timeout: 10000})
21+
// noinspection JSCheckFunctionSignatures
2122
kraken.api('Balance', function(err, data) {
2223
if (err) {
2324
return reject(err)
@@ -27,7 +28,7 @@ export default class KrakenWallet {
2728
for (let symbol in balances) {
2829
let amount = balances[symbol]
2930
if (symbol.length === 4 && symbol[0] === 'X') {
30-
symbol = symbol.substr(1,3);
31+
symbol = symbol.substr(1, 3)
3132
}
3233
result.push(new Coin(symbol, amount, 'Kraken'))
3334
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import assert from 'assert'
2+
import BitgrailWallet from "../../../src/model/integrations/BitgrailWallet";
3+
4+
describe('Testing Bitgrail integration', () => {
5+
it('Testing initial connection and balances', async () => {
6+
let wallet = await BitgrailWallet.getBalance()
7+
assert(wallet.length > 0)
8+
})
9+
})

0 commit comments

Comments
 (0)