Skip to content

Commit

Permalink
Merge pull request #15 from cytopia/coinwatch-15
Browse files Browse the repository at this point in the history
Release v0.14
  • Loading branch information
cytopia authored Feb 6, 2018
2 parents 8599777 + 1a57e58 commit 7dfe00c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 40 deletions.
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**[Usage](#usage)** |
**[Screenshots](#screenshots)** |
**[Features](#features)** |
**[Columns](#columns)** |
**[Configuration](#configuration)** |
**[Options](#options)** |
**[API](#api)** |
Expand Down Expand Up @@ -74,6 +75,38 @@ The example shows coinwatch wrapped into `watch` and refresh every 10 seconds.
* Pure text-based output is available for further processing in other tools


## Columns

`coinwatch` offers many columns that can be displayed in any order. A sane limited default is set in the configuration file which does not display all columns. You are free to alter that and adjust `coinwatch` to your needs directly in the configuration file (see **[Configuration](#configuration)**) or quickly enabled/disable columns via command arguments (`-r`). Sorting, ordering and grouping will also work on columns that are not being displayed. Have a look at the following table which shows you all available columns:

| Column name | Default display | Description |
|-------------|-----------------|-------------|
| `name` | no | Name of the cryptocurrency. |
| `symbol` | yes | Abbreviation name of the cryptocurrency. |
| `buyprice` | yes | Price in USD at which the currency was bought. |
| `diffprice` | yes | Price difference in USD between buy time and now. |
| `nowprice` | yes | Current price in USD of the currency. |
| `amount` | yes | Total number of coins you have bought. |
| `invest` | yes | Total amount in USD you have invested for all coins bought. |
| `wealth` | yes | Current amount in USD your coins are worth now. |
| `profit` | yes | How much profit in USD did you make on that currency. |
| `percent` | yes | Percent of profit between buy time and now. |
| `percent1h` | no | Percent of price change in the last hour of that currency. |
| `percent24h`| no | Percent of price change in the last 24 hours of that currency. |
| `percent7d` | no | Percent of price change in the last 7 days of that currency. |
| `cust1` | no | Custom field (see **[Configuration](#configuration)**)|
| `cust2` | no | Custom field (see **[Configuration](#configuration)**)|
| `cust3` | no | Custom field (see **[Configuration](#configuration)**)|

**Note about custom fields:**

Headline and column width of custom fields can be set in the configuration file. The values itself can be added to your trade array and can contain any information you wish to display for a given trade. As an example they could contain information such as:
* At what date did you buy that currency
* At what market did you buy that currency
* The wallet address where the coins are
* Are the coins still online or already downloaded to a cold wallet


## Configuration
When starting `coinwatch` for the first time, it will create a default configuration file in `~/.config/coinwatch/config.yml` with no trades to watch. To get a quick overview, have a look at the [example config](example/config.yml).

Expand All @@ -84,9 +117,9 @@ The configuration file is build up like this:
```yml
# Configure coinwatch
config:
# Specify the column to sort this table
# Specify the default column to sort this table by or leave empty for unsorted.
# Overwrite via -s <column>
sort: name
sort:
# Specify the sort order (asc or desc)
# Overwrite via -o desc
order: asc
Expand Down Expand Up @@ -174,7 +207,7 @@ When adding new cryptocurrencies, you need to make sure that you use the correct

| Screenshot | Explanation |
|------------|-------------|
| ![api](screenshot/api.png) | When visiting the coinmarketcap API page, look for the `id` field of a currency and use its value to add to the configuration file. |
| ![api](screenshot/api.png) | When visiting the coinmarketcap API page, look for the `id` field of a currency and use its value to add to the configuration file.<br/><br/>In case you wanted to add Ethereum and Bitcoin as seen in the example screenshot, you would use `ethereum` and `bitcoin` as names to put into your configuration file. |


### Example
Expand Down Expand Up @@ -254,7 +287,7 @@ OPTIONS:
-s, --sort Specify the column name to sort this table.
See above for available columns.
The table can also be sorted against columns that are not displayed.
The default is: 'name'
The default is unsorted.
-o, --order Specify the sorting order.
Valid orders: 'asc' and 'desc'.
The default order is 'asc'.
Expand Down
71 changes: 38 additions & 33 deletions bin/coinwatch
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ except Exception:

NAME = 'coinwatch'
AUTHOR = 'cytopia'
VERSION = '0.13'
VERSION = '0.14'
API_URL = 'https://api.coinmarketcap.com/v1/ticker/?limit=0'


Expand All @@ -81,7 +81,10 @@ COL_SETTINGS = {
'invest': {'width': 10, 'align': '>', 'prec': 2, 'color': False, 'head': '$ INVEST'},
'wealth': {'width': 10, 'align': '>', 'prec': 2, 'color': False, 'head': '$ WEALTH'},
'profit': {'width': 12, 'align': '>', 'prec': 2, 'color': True, 'head': '$ PROFIT'},
'percent': {'width': 7, 'align': '>', 'prec': 1, 'color': False, 'head': 'PERCENT'}
'percent': {'width': 7, 'align': '>', 'prec': 1, 'color': True, 'head': 'PERCENT'},
'percent1h': {'width': 7, 'align': '>', 'prec': 1, 'color': True, 'head': '% 1h'},
'percent24h': {'width': 7, 'align': '>', 'prec': 1, 'color': True, 'head': '% 24h'},
'percent7d': {'width': 7, 'align': '>', 'prec': 1, 'color': True, 'head': '% 7d'}
}
# All available columns
COL_AVAILABLE = [
Expand All @@ -97,12 +100,14 @@ COL_AVAILABLE = [
'invest',
'wealth',
'profit',
'percent'
'percent',
'percent1h',
'percent24h',
'percent7d'
]
# Default columns to display if not otherwise overwritten via
# configuration file or command line arguments
COL_DEFAULT = [
'name',
'symbol',
'buyprice',
'diffprice',
Expand Down Expand Up @@ -802,7 +807,7 @@ class Coinwatch(object):
__settings = {
'color': False, # Colorize output?
'human': False, # Humanize number output?
'sort': 'name', # Default sort column
'sort': None, # Default sort column
'order': 'asc', # Default sort order
'group': None, # Default grouping
'table': 'thick', # Table border style
Expand Down Expand Up @@ -851,7 +856,7 @@ class Coinwatch(object):
return Num.div(invest, amount)

@staticmethod
def __extract_trade_row_values(currency, symbol, price, trade):
def __extract_trade_row_values(currency, trade):
'''
Extract values of one trade list item, calculate all other necessary
values and combine with current price and crypto name.
Expand All @@ -860,28 +865,31 @@ class Coinwatch(object):
amount = Coinwatch.__get_amount(trade)
invest = Coinwatch.__get_invest(trade)
buyprice = Coinwatch.__get_price(trade)
nowprice = Num.get(price)
nowprice = Num.get(currency['price_usd'])

# Calculate diffprice, wealth, profit and percent
diffprice = Num.sub(nowprice, buyprice)
wealth = Num.mul(nowprice, amount)
profit = Num.sub(wealth, invest)
percent = Num.percent(wealth, invest)
percent = Num.sub(Num.percent(wealth, invest), 100)

return {
'name': currency,
'symbol': symbol,
'cust1': str(trade.get('cust1', '')),
'cust2': str(trade.get('cust2', '')),
'cust3': str(trade.get('cust3', '')),
'buyprice': buyprice,
'diffprice': diffprice,
'nowprice': nowprice,
'amount': amount,
'invest': invest,
'wealth': wealth,
'profit': profit,
'percent': percent
'name': currency['id'],
'symbol': currency['symbol'],
'cust1': str(trade.get('cust1', '')),
'cust2': str(trade.get('cust2', '')),
'cust3': str(trade.get('cust3', '')),
'buyprice': buyprice,
'diffprice': diffprice,
'nowprice': nowprice,
'amount': amount,
'invest': invest,
'wealth': wealth,
'profit': profit,
'percent': percent,
'percent1h': currency['percent_change_1h'],
'percent24h': currency['percent_change_24h'],
'percent7d': currency['percent_change_7d']
}

@staticmethod
Expand Down Expand Up @@ -934,7 +942,7 @@ class Coinwatch(object):
)
# 3. Colorize
if col_settings[val]['color'] and fvalues[val]:
if values[val] < 0:
if Num.get(values[val]) < 0:
fvalues[val] = clr.red() + str(fvalues[val]) + clr.reset()
else:
fvalues[val] = clr.green() + str(fvalues[val]) + clr.reset()
Expand All @@ -943,7 +951,7 @@ class Coinwatch(object):
def __format_summary_row_values(self, totals):
'''Format and return the summary row'''
values = dict()
values['name'] = 'TOTAL'
values['name'] = ''
values['symbol'] = ''
values['cust1'] = ''
values['cust2'] = ''
Expand All @@ -955,7 +963,10 @@ class Coinwatch(object):
values['invest'] = totals['invest']
values['wealth'] = totals['wealth']
values['profit'] = totals['profit']
values['percent'] = Num.percent(totals['wealth'], totals['invest'])
values['percent'] = Num.sub(Num.percent(totals['wealth'], totals['invest']), 100)
values['percent1h'] = ''
values['percent24h'] = ''
values['percent7d'] = ''
return self.__format_trade_row_values(values)

def print_stats(self, currencies, trades):
Expand Down Expand Up @@ -995,12 +1006,7 @@ class Coinwatch(object):
for trade in trades[name]:

# Extract and format row values
values = self.__extract_trade_row_values(
name,
currency['symbol'],
currency['price_usd'],
trade
)
values = self.__extract_trade_row_values(currency, trade)
fvalues = self.__format_trade_row_values(values)

# Add row
Expand Down Expand Up @@ -1103,7 +1109,7 @@ OPTIONS:
-s, --sort Specify the column name to sort this table.
See above for available columns.
The table can also be sorted against columns that are not displayed.
The default is 'name'.
The default is unsorted.
-o, --order Specify the sorting order.
Valid orders: 'asc' and 'desc'.
The default order is 'asc'.
Expand Down Expand Up @@ -1426,8 +1432,7 @@ def main(argv):
validate_config(config)

# Merge cmd args and config file settings
settings = build_settings(settings, config, COL_DEFAULT, 'name', 'asc')

settings = build_settings(settings, config, COL_DEFAULT, None, 'asc')
# Get remote price info
url = Fetch(True)
try:
Expand Down
6 changes: 3 additions & 3 deletions example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

# Configure coinwatch
config:
# Specify the column to sort this table
# Specify the default column to sort this table by or leave empty for unsorted.
# Overwrite via -s <column>
sort: name
sort:
# Specify the sort order (asc or desc)
# Overwrite via -o desc
order: asc
Expand All @@ -46,7 +46,7 @@ config:
# Enable them here or via (-r).
# Those three columns can be added to your trades in order to display custom information,
# such as which market they were bought from or on what date they were bought.
columns: name symbol buyprice diffprice nowprice amount invest wealth profit percent
columns: symbol buyprice diffprice nowprice amount invest wealth profit percent
# Define your custom columns here.
# Set column headline and width.
cust:
Expand Down

0 comments on commit 7dfe00c

Please sign in to comment.