decent 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/.rubocop.yml +3 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +54 -0
- data/LICENSE.txt +21 -0
- data/README.md +134 -0
- data/bin/decent +2 -0
- data/decent.gemspec +23 -0
- data/lib/decent/api/api.rb +11 -0
- data/lib/decent/api/bitcoin_api.rb +13 -0
- data/lib/decent/api/ether_api.rb +13 -0
- data/lib/decent/api/litecoin_api.rb +13 -0
- data/lib/decent/command/exchange_rate/exchange_rate.rb +13 -0
- data/lib/decent/command/exchange_rate/list_exchange_rate.rb +13 -0
- data/lib/decent/command/exchange_rate/store_exchange_rate.rb +20 -0
- data/lib/decent/command/exchange_rate/update_exchange_rate.rb +16 -0
- data/lib/decent/command/hodling/add_hodling.rb +20 -0
- data/lib/decent/command/hodling/hodling.rb +16 -0
- data/lib/decent/command/hodling/list_hodling.rb +15 -0
- data/lib/decent/command/hodling/remove_hodling.rb +11 -0
- data/lib/decent/command/hodling/show_hodling.rb +21 -0
- data/lib/decent/command/hodling/store_hodling.rb +24 -0
- data/lib/decent/command/hodling/update_hodling.rb +17 -0
- data/lib/decent/setup.rb +65 -0
- data/lib/decent/storage/.gitignore +4 -0
- data/lib/decent/version.rb +3 -0
- data/lib/decent.rb +50 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c28304a031987d93bbfa0153aa1267e7decb616
|
4
|
+
data.tar.gz: 130faa5b59c16eaaa01a635c5e46620bf292b8a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e0be7cb82a6789539cb047bed6925f516971456acc1ec87d644437d7cc17116e34389634aaf7490bc2c75857edf9582faaa921de13891552b4860f0dc2aa1e5
|
7
|
+
data.tar.gz: bc450035307378ca5b04be2e6eb6603529ef95a8adf6976c2b56a3d34706dc56d710d307c7b51617ce932e71b3d6f2767efd6a59f3e31126fe48f39d97ea1004
|
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Created by https://www.gitignore.io/api/ruby
|
2
|
+
|
3
|
+
### Ruby ###
|
4
|
+
*.gem
|
5
|
+
*.rbc
|
6
|
+
/.config
|
7
|
+
/coverage/
|
8
|
+
/InstalledFiles
|
9
|
+
/pkg/
|
10
|
+
/spec/reports/
|
11
|
+
/spec/examples.txt
|
12
|
+
/test/tmp/
|
13
|
+
/test/version_tmp/
|
14
|
+
/tmp/
|
15
|
+
|
16
|
+
# Used by dotenv library to load environment variables.
|
17
|
+
# .env
|
18
|
+
|
19
|
+
## Documentation cache and generated files:
|
20
|
+
/.yardoc/
|
21
|
+
/_yardoc/
|
22
|
+
/doc/
|
23
|
+
/rdoc/
|
24
|
+
|
25
|
+
## Environment normalization:
|
26
|
+
/.bundle/
|
27
|
+
/vendor/bundle
|
28
|
+
/lib/bundler/man/
|
29
|
+
|
30
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
31
|
+
.rvmrc
|
32
|
+
|
33
|
+
### development ###
|
34
|
+
/test.rb
|
35
|
+
/blueprint.md
|
36
|
+
/todo.md
|
37
|
+
|
38
|
+
# End of https://www.gitignore.io/api/ruby
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ast (2.3.0)
|
5
|
+
commander (4.4.3)
|
6
|
+
highline (~> 1.7.2)
|
7
|
+
domain_name (0.5.20170404)
|
8
|
+
unf (>= 0.0.5, < 1.0.0)
|
9
|
+
highline (1.7.8)
|
10
|
+
http-cookie (1.0.3)
|
11
|
+
domain_name (~> 0.5)
|
12
|
+
mime-types (3.1)
|
13
|
+
mime-types-data (~> 3.2015)
|
14
|
+
mime-types-data (3.2016.0521)
|
15
|
+
netrc (0.11.0)
|
16
|
+
parser (2.4.0.0)
|
17
|
+
ast (~> 2.2)
|
18
|
+
powerpack (0.1.1)
|
19
|
+
rainbow (2.2.2)
|
20
|
+
rake
|
21
|
+
rake (12.0.0)
|
22
|
+
rest-client (2.0.2)
|
23
|
+
http-cookie (>= 1.0.2, < 2.0)
|
24
|
+
mime-types (>= 1.16, < 4.0)
|
25
|
+
netrc (~> 0.8)
|
26
|
+
rubocop (0.48.1)
|
27
|
+
parser (>= 2.3.3.1, < 3.0)
|
28
|
+
powerpack (~> 0.1)
|
29
|
+
rainbow (>= 1.99.1, < 3.0)
|
30
|
+
ruby-progressbar (~> 1.7)
|
31
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
32
|
+
rubocop-github (0.4.2)
|
33
|
+
rubocop (~> 0.47)
|
34
|
+
ruby-progressbar (1.8.1)
|
35
|
+
sequel (4.46.0)
|
36
|
+
sqlite3 (1.3.13)
|
37
|
+
unf (0.1.4)
|
38
|
+
unf_ext
|
39
|
+
unf_ext (0.0.7.4)
|
40
|
+
unicode-display_width (1.2.1)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
commander
|
47
|
+
rest-client
|
48
|
+
rubocop (~> 0.48.1)
|
49
|
+
rubocop-github
|
50
|
+
sequel
|
51
|
+
sqlite3
|
52
|
+
|
53
|
+
BUNDLED WITH
|
54
|
+
1.14.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Parker McCurley
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# decent
|
2
|
+
|
3
|
+
A Ruby command line application for managing cryptocurrency holdings.
|
4
|
+
|
5
|
+
## Synopsis
|
6
|
+
|
7
|
+
I like doing things from the command line. And like any command line user worth their
|
8
|
+
salt, I **hodl** some cryptocurrencies. I made `decent` so I can quickly, compulsively
|
9
|
+
access exchange rates and address balances from my highfalutin terminal. Oh, and it's
|
10
|
+
de-cent like de-cen-tra-lized, but I guess the synonym for mediocre works as well.
|
11
|
+
|
12
|
+
Whenever new data is pulled from the web, the outdated data is stored in historic tables
|
13
|
+
which could be leveraged for investment strategy / world domination.
|
14
|
+
|
15
|
+
Currently (as of 0.1.3) supports Bitcoin (BTC), Ethereum (ETH), and Litecoin (LTC).
|
16
|
+
|
17
|
+
## Install
|
18
|
+
|
19
|
+
`gem install decent`
|
20
|
+
|
21
|
+

|
22
|
+
|
23
|
+
**Note: The first time `decent` runs, it will create a SQLite3 database in your home
|
24
|
+
directory like so: `~/.decent/decent.db`**
|
25
|
+
|
26
|
+
## Schema
|
27
|
+
|
28
|
+
decent uses SQLite3.
|
29
|
+
|
30
|
+
### holdings
|
31
|
+
```SQL
|
32
|
+
`id` integer,
|
33
|
+
`nickname` varchar(255),
|
34
|
+
`address` varchar(255),
|
35
|
+
`currency` varchar(255),
|
36
|
+
`balance` doubleprecision,
|
37
|
+
`created_at` timestamp,
|
38
|
+
`updated_at` timestamp
|
39
|
+
```
|
40
|
+
|
41
|
+
### historic_holdings
|
42
|
+
```SQL
|
43
|
+
`id` integer,
|
44
|
+
`holding_id` integer,
|
45
|
+
`address` varchar(255),
|
46
|
+
`currency` varchar(255),
|
47
|
+
`balance` doubleprecision,
|
48
|
+
`recorded_at` timestamp
|
49
|
+
`created_at` timestamp
|
50
|
+
```
|
51
|
+
|
52
|
+
### exchange_rates
|
53
|
+
```SQL
|
54
|
+
`id` integer,
|
55
|
+
`currency` varchar(255),
|
56
|
+
`rate` doubleprecision,
|
57
|
+
`created_at` timestamp,
|
58
|
+
`updated_at` timestamp
|
59
|
+
```
|
60
|
+
|
61
|
+
### historic_exchange_rates
|
62
|
+
```SQL
|
63
|
+
`id` integer,
|
64
|
+
`exchange_rate_id` integer,
|
65
|
+
`currency` varchar(255),
|
66
|
+
`rate` doubleprecision,
|
67
|
+
`recorded_at` timestamp,
|
68
|
+
`created_at` timestamp
|
69
|
+
```
|
70
|
+
|
71
|
+
## Commands
|
72
|
+
|
73
|
+
### Update Exchange Rates
|
74
|
+
|
75
|
+
**Command:** `decent exchange_rate update`
|
76
|
+
|
77
|
+
**Result:** Current exchange rates for all currencies are pulled from Coinbase and
|
78
|
+
stored with a timestamp. The previous values are copied to the `historic_exchange_rates`
|
79
|
+
table.
|
80
|
+
|
81
|
+
### List Exchange Rates
|
82
|
+
|
83
|
+
**Command:** `decent exchange_rate list`
|
84
|
+
|
85
|
+
**Result:** The most recently queried information for each exchange rate will be
|
86
|
+
listed.
|
87
|
+
|
88
|
+
### Add Hodling
|
89
|
+
|
90
|
+
**Command:** `decent hodling add`
|
91
|
+
|
92
|
+
**Result:** Creates a prompt asking for a nickname, address, and currency for a new
|
93
|
+
hodling.
|
94
|
+
|
95
|
+
### Update Hodlings
|
96
|
+
|
97
|
+
**Command:** `decent hodling update`
|
98
|
+
|
99
|
+
**Result:** Current balances for all locally stored address are pulled from the APIs
|
100
|
+
and stored with a timestamp. The previous values are copied to the `historic_holdings`
|
101
|
+
table.
|
102
|
+
|
103
|
+
### List Hodlings
|
104
|
+
|
105
|
+
**Command:** `decent hodling list`
|
106
|
+
|
107
|
+
**Result:** The most recently queried information for each locally stored hodling will
|
108
|
+
be listed.
|
109
|
+
|
110
|
+
### Show Hodling
|
111
|
+
|
112
|
+
**Command:** `decent hodling show -nickname NICKNAME`
|
113
|
+
|
114
|
+
**Result:** The most recently queried information for the hodling with nickname NICKNAME
|
115
|
+
will be displayed, along with its value in USD based on the most recently queried
|
116
|
+
exchange rate for its respective currency.
|
117
|
+
|
118
|
+
### Remove Hodling
|
119
|
+
|
120
|
+
**Command:** `decent hodling remove -nickname NICKNAME`
|
121
|
+
|
122
|
+
**Result:** The most recently queried information for the hodling with nickname NICKNAME
|
123
|
+
will be removed, and that hodling will no longer appear in the `holdings` table.
|
124
|
+
Related entries in the `historic_holdings` table will not be affected.
|
125
|
+
|
126
|
+
## Donations
|
127
|
+
|
128
|
+
I'm not expecting any of these, but here are my public addresses :)
|
129
|
+
|
130
|
+
**Bitcoin:** `1MzRX52tmTqdaVbA4nPnbEVpoYgmP5e6dH`
|
131
|
+
|
132
|
+
**Ethereum:** `0x11b91e4b6d0e149cbedc213c98d177ac0560abd9`
|
133
|
+
|
134
|
+
**Litecoin:** `LXq9vUheGADoSdyHY7HqKWhjixgzYLaJm4`
|
data/bin/decent
ADDED
data/decent.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "decent/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "decent"
|
7
|
+
spec.version = Decent::VERSION
|
8
|
+
spec.authors = ["moondog"]
|
9
|
+
spec.email = ["parkermccurlz@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %{Decent is a command line application for managing cryptocurrency holdings.}
|
12
|
+
spec.homepage = "https://github.com/parkertm/decent"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($\)
|
16
|
+
spec.executables = ["decent"]
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "commander", ["~> 4.0"]
|
20
|
+
spec.add_runtime_dependency "rest-client", ["~> 2.0"]
|
21
|
+
spec.add_runtime_dependency "sequel", ["~> 4.0"]
|
22
|
+
spec.add_runtime_dependency "sqlite3", ["~> 1.3"]
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Decent
|
2
|
+
class BitcoinAPI
|
3
|
+
def self.get_balance(address)
|
4
|
+
url = "https://blockchain.info/q/addressbalance/#{address}"
|
5
|
+
return RestClient.get(url).to_f / 10**8
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get_exchange_rate
|
9
|
+
url = "https://api.coinbase.com/v2/exchange-rates?currency=BTC"
|
10
|
+
return JSON.parse(RestClient.get url)["data"]["rates"]["USD"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Decent
|
2
|
+
class EtherAPI
|
3
|
+
def self.get_balance(address)
|
4
|
+
url = "https://api.blockcypher.com/v1/eth/main/addrs/#{address}/balance"
|
5
|
+
return JSON.parse(RestClient.get url)["balance"].to_f / 10**18
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get_exchange_rate
|
9
|
+
url = "https://api.coinbase.com/v2/exchange-rates?currency=ETH"
|
10
|
+
return JSON.parse(RestClient.get url)["data"]["rates"]["USD"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Decent
|
2
|
+
class LitecoinAPI
|
3
|
+
def self.get_balance(address)
|
4
|
+
url = "https://ltc.blockr.io/api/v1/address/info/#{address}"
|
5
|
+
return JSON.parse(RestClient.get url)["data"]["balance"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get_exchange_rate
|
9
|
+
url = "https://api.coinbase.com/v2/exchange-rates?currency=LTC"
|
10
|
+
return JSON.parse(RestClient.get url)["data"]["rates"]["USD"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Decent
|
2
|
+
class ListExchangeRate
|
3
|
+
def self.execute
|
4
|
+
exchange_rates = Database[:exchange_rates]
|
5
|
+
exchange_rates.each do |exchange_rate|
|
6
|
+
currency = exchange_rate[:currency]
|
7
|
+
rate = exchange_rate[:rate]
|
8
|
+
|
9
|
+
puts "#{currency}: #{rate} USD"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Decent
|
2
|
+
class StoreExchangeRate
|
3
|
+
def self.store(exchange_rate)
|
4
|
+
id = exchange_rate[:id]
|
5
|
+
currency = exchange_rate[:currency]
|
6
|
+
rate = exchange_rate[:rate]
|
7
|
+
recorded_at = exchange_rate[:updated_at]
|
8
|
+
created_at = DateTime.now
|
9
|
+
historic_exchange_rates = Database[:historic_exchange_rates]
|
10
|
+
|
11
|
+
historic_exchange_rates.insert({
|
12
|
+
exchange_rate_id: id,
|
13
|
+
currency: currency,
|
14
|
+
rate: rate,
|
15
|
+
recorded_at: recorded_at,
|
16
|
+
created_at: created_at
|
17
|
+
})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Decent
|
2
|
+
class UpdateExchangeRate
|
3
|
+
def self.execute
|
4
|
+
exchange_rates = Database[:exchange_rates]
|
5
|
+
exchange_rates.each do |exchange_rate|
|
6
|
+
currency = exchange_rate[:currency]
|
7
|
+
id = exchange_rate[:id]
|
8
|
+
rate = API.currency[currency].get_exchange_rate
|
9
|
+
|
10
|
+
if (exchange_rates.where(id: id).update(rate: rate, updated_at: DateTime.now))
|
11
|
+
StoreExchangeRate.store exchange_rate
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Decent
|
2
|
+
class AddHodling
|
3
|
+
def self.execute(args)
|
4
|
+
cli = HighLine.new
|
5
|
+
nickname = cli.ask "What is the nickname of this hodling?", String
|
6
|
+
address = cli.ask "What is the address of this hodling?", String
|
7
|
+
currency = cli.ask "What is the currency of this hodling?", String
|
8
|
+
hodlings = Database[:holdings]
|
9
|
+
|
10
|
+
hodlings.insert({
|
11
|
+
nickname: nickname,
|
12
|
+
address: address,
|
13
|
+
currency: currency,
|
14
|
+
balance: 0.00,
|
15
|
+
created_at: DateTime.now,
|
16
|
+
updated_at: DateTime.now
|
17
|
+
})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Decent
|
2
|
+
class Hodling
|
3
|
+
def self.execute(args)
|
4
|
+
command = args.first
|
5
|
+
commands = {
|
6
|
+
"add" => AddHodling,
|
7
|
+
"list" => ListHodling,
|
8
|
+
"remove" => RemoveHodling,
|
9
|
+
"show" => ShowHodling,
|
10
|
+
"update" => UpdateHodling
|
11
|
+
}
|
12
|
+
|
13
|
+
commands[command].execute args
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Decent
|
2
|
+
class ListHodling
|
3
|
+
def self.execute(args)
|
4
|
+
hodlings = Database[:holdings]
|
5
|
+
hodlings.each do |hodling|
|
6
|
+
nickname = hodling[:nickname]
|
7
|
+
balance = hodling[:balance]
|
8
|
+
currency = hodling[:currency]
|
9
|
+
updated_at = hodling[:updated_at]
|
10
|
+
|
11
|
+
puts "#{nickname} has a balance of #{balance} #{currency} as of #{updated_at}."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Decent
|
2
|
+
class ShowHodling
|
3
|
+
def self.execute(args)
|
4
|
+
hodlings = Database[:holdings]
|
5
|
+
nickname = args[1]
|
6
|
+
hodling = hodlings.where(nickname: nickname).first
|
7
|
+
balance = hodling[:balance]
|
8
|
+
currency = hodling[:currency]
|
9
|
+
updated_at = hodling[:updated_at]
|
10
|
+
|
11
|
+
exchange_rates = Database[:exchange_rates]
|
12
|
+
exchange_rate = exchange_rates.where(currency: currency).first
|
13
|
+
rate = exchange_rate[:rate]
|
14
|
+
rate_updated_at = exchange_rate[:updated_at]
|
15
|
+
value_in_usd = balance * rate
|
16
|
+
|
17
|
+
puts "#{nickname} has a balance of #{balance} #{currency} as of #{updated_at}."
|
18
|
+
puts "At an exchange rate of #{rate} USD, as of #{rate_updated_at}, #{nickname} is worth #{value_in_usd} USD."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Decent
|
2
|
+
class StoreHodling
|
3
|
+
def self.store(hodling)
|
4
|
+
id = hodling[:id]
|
5
|
+
nickname = hodling[:nickname]
|
6
|
+
address = hodling[:address]
|
7
|
+
currency = hodling[:currency]
|
8
|
+
balance = hodling[:balance]
|
9
|
+
recorded_at = hodling[:updated_at]
|
10
|
+
created_at = DateTime.now
|
11
|
+
historic_hodlings = Database[:historic_holdings]
|
12
|
+
|
13
|
+
historic_hodlings.insert({
|
14
|
+
holding_id: id,
|
15
|
+
nickname: nickname,
|
16
|
+
address: address,
|
17
|
+
currency: currency,
|
18
|
+
balance: balance,
|
19
|
+
recorded_at: recorded_at,
|
20
|
+
created_at: created_at
|
21
|
+
})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Decent
|
2
|
+
class UpdateHodling
|
3
|
+
def self.execute(args)
|
4
|
+
hodlings = Database[:holdings]
|
5
|
+
hodlings.each do |hodling|
|
6
|
+
currency = hodling[:currency]
|
7
|
+
address = hodling[:address]
|
8
|
+
id = hodling[:id]
|
9
|
+
balance = API.currency[currency].get_balance address
|
10
|
+
|
11
|
+
if (hodlings.where(id: id).update(balance: balance, updated_at: DateTime.now))
|
12
|
+
StoreHodling.store hodling
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/decent/setup.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "sequel"
|
2
|
+
|
3
|
+
module Decent
|
4
|
+
StorageDirectory = File.expand_path("~/.decent")
|
5
|
+
unless Dir[StorageDirectory].length > 0
|
6
|
+
Dir::mkdir(StorageDirectory)
|
7
|
+
end
|
8
|
+
Database = Sequel.sqlite("#{StorageDirectory}/decent.db")
|
9
|
+
|
10
|
+
unless Database.table_exists? :holdings
|
11
|
+
Database.create_table(:holdings) do
|
12
|
+
primary_key :id
|
13
|
+
String :nickname
|
14
|
+
String :address
|
15
|
+
String :currency
|
16
|
+
Float :balance
|
17
|
+
DateTime :created_at
|
18
|
+
DateTime :updated_at
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
unless Database.table_exists? :historic_holdings
|
23
|
+
Database.create_table(:historic_holdings) do
|
24
|
+
primary_key :id
|
25
|
+
Integer :holding_id
|
26
|
+
String :nickname
|
27
|
+
String :address
|
28
|
+
String :currency
|
29
|
+
Float :balance
|
30
|
+
DateTime :recorded_at
|
31
|
+
DateTime :created_at
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
unless Database.table_exists? :exchange_rates
|
36
|
+
Database.create_table(:exchange_rates) do
|
37
|
+
primary_key :id
|
38
|
+
String :currency
|
39
|
+
Float :rate
|
40
|
+
DateTime :created_at
|
41
|
+
DateTime :updated_at
|
42
|
+
end
|
43
|
+
|
44
|
+
currencies = [
|
45
|
+
"BTC",
|
46
|
+
"ETH",
|
47
|
+
"LTC"
|
48
|
+
]
|
49
|
+
|
50
|
+
currencies.each do |currency|
|
51
|
+
Database[:exchange_rates].insert(currency: currency, rate: 0.00, created_at: DateTime.now, updated_at: DateTime.now)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
unless Database.table_exists? :historic_exchange_rates
|
56
|
+
Database.create_table(:historic_exchange_rates) do
|
57
|
+
primary_key :id
|
58
|
+
Integer :exchange_rate_id
|
59
|
+
String :currency
|
60
|
+
Float :rate
|
61
|
+
DateTime :recorded_at
|
62
|
+
DateTime :created_at
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/decent.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Gem Requirements
|
2
|
+
require "bundler/setup"
|
3
|
+
require "commander/import"
|
4
|
+
require "highline"
|
5
|
+
require "json"
|
6
|
+
require "rest-client"
|
7
|
+
require "rubygems"
|
8
|
+
|
9
|
+
# Application Requirements
|
10
|
+
require "decent/setup"
|
11
|
+
require "decent/command/hodling/hodling"
|
12
|
+
require "decent/command/hodling/add_hodling"
|
13
|
+
require "decent/command/hodling/list_hodling"
|
14
|
+
require "decent/command/hodling/remove_hodling"
|
15
|
+
require "decent/command/hodling/show_hodling"
|
16
|
+
require "decent/command/hodling/store_hodling"
|
17
|
+
require "decent/command/hodling/update_hodling"
|
18
|
+
require "decent/command/exchange_rate/exchange_rate"
|
19
|
+
require "decent/command/exchange_rate/list_exchange_rate"
|
20
|
+
require "decent/command/exchange_rate/store_exchange_rate"
|
21
|
+
require "decent/command/exchange_rate/update_exchange_rate"
|
22
|
+
require "decent/api/bitcoin_api"
|
23
|
+
require "decent/api/litecoin_api"
|
24
|
+
require "decent/api/ether_api"
|
25
|
+
require "decent/api/api"
|
26
|
+
|
27
|
+
module Decent
|
28
|
+
# Initialization
|
29
|
+
program :name, "decent"
|
30
|
+
program :version, "0.2.3"
|
31
|
+
program :description, "A ruby command line application for managing cryptocurrency holdings."
|
32
|
+
|
33
|
+
# Commands
|
34
|
+
command :hodling do |command|
|
35
|
+
command.syntax = "decent hodling"
|
36
|
+
command.description = "Run tasks related to coins you hodl"
|
37
|
+
command.option "-nickname STRING", String, "Selects hodling for task"
|
38
|
+
command.action do |args|
|
39
|
+
Hodling.execute args
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
command :exchange_rate do |command|
|
44
|
+
command.syntax = "decent exchange_rate"
|
45
|
+
command.description = "Run tasks related to exchange rates"
|
46
|
+
command.action do |args|
|
47
|
+
ExchangeRate.execute args
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: decent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- moondog
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sequel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- parkermccurlz@gmail.com
|
72
|
+
executables:
|
73
|
+
- decent
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- bin/decent
|
84
|
+
- decent.gemspec
|
85
|
+
- lib/decent.rb
|
86
|
+
- lib/decent/api/api.rb
|
87
|
+
- lib/decent/api/bitcoin_api.rb
|
88
|
+
- lib/decent/api/ether_api.rb
|
89
|
+
- lib/decent/api/litecoin_api.rb
|
90
|
+
- lib/decent/command/exchange_rate/exchange_rate.rb
|
91
|
+
- lib/decent/command/exchange_rate/list_exchange_rate.rb
|
92
|
+
- lib/decent/command/exchange_rate/store_exchange_rate.rb
|
93
|
+
- lib/decent/command/exchange_rate/update_exchange_rate.rb
|
94
|
+
- lib/decent/command/hodling/add_hodling.rb
|
95
|
+
- lib/decent/command/hodling/hodling.rb
|
96
|
+
- lib/decent/command/hodling/list_hodling.rb
|
97
|
+
- lib/decent/command/hodling/remove_hodling.rb
|
98
|
+
- lib/decent/command/hodling/show_hodling.rb
|
99
|
+
- lib/decent/command/hodling/store_hodling.rb
|
100
|
+
- lib/decent/command/hodling/update_hodling.rb
|
101
|
+
- lib/decent/setup.rb
|
102
|
+
- lib/decent/storage/.gitignore
|
103
|
+
- lib/decent/version.rb
|
104
|
+
homepage: https://github.com/parkertm/decent
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.6.11
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Decent is a command line application for managing cryptocurrency holdings.
|
128
|
+
test_files: []
|