From b5b896a3cf93ab60aa0e11da525c5af051147044 Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 6 Feb 2018 08:29:02 +0100 Subject: [PATCH 1/2] Don't sort table by default --- README.md | 8 ++++---- bin/coinwatch | 9 ++++----- example/config.yml | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d2d8219..c3e9952 100644 --- a/README.md +++ b/README.md @@ -84,9 +84,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 - sort: name + sort: # Specify the sort order (asc or desc) # Overwrite via -o desc order: asc @@ -174,7 +174,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.

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 @@ -254,7 +254,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'. diff --git a/bin/coinwatch b/bin/coinwatch index 31eb1cd..1838047 100755 --- a/bin/coinwatch +++ b/bin/coinwatch @@ -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' @@ -802,7 +802,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 @@ -1103,7 +1103,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'. @@ -1426,8 +1426,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: diff --git a/example/config.yml b/example/config.yml index 71be909..967e29f 100644 --- a/example/config.yml +++ b/example/config.yml @@ -32,9 +32,9 @@ # Configure coinwatch config: - # Specify the column to sort this table + # Specify the column to sort this table by default or leave empty. # Overwrite via -s - sort: name + sort: # Specify the sort order (asc or desc) # Overwrite via -o desc order: asc From 1a57e5846a78d509294adb3ac34acff902e8b6fe Mon Sep 17 00:00:00 2001 From: cytopia Date: Tue, 6 Feb 2018 09:20:48 +0100 Subject: [PATCH 2/2] Add more columns as well as their explanation --- README.md | 33 ++++++++++++++++++++++++ bin/coinwatch | 62 +++++++++++++++++++++++++--------------------- example/config.yml | 4 +-- 3 files changed, 69 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index c3e9952..b501914 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ **[Usage](#usage)** | **[Screenshots](#screenshots)** | **[Features](#features)** | +**[Columns](#columns)** | **[Configuration](#configuration)** | **[Options](#options)** | **[API](#api)** | @@ -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). diff --git a/bin/coinwatch b/bin/coinwatch index 1838047..ba70d7c 100755 --- a/bin/coinwatch +++ b/bin/coinwatch @@ -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 = [ @@ -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', @@ -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. @@ -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 @@ -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() @@ -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'] = '' @@ -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): @@ -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 diff --git a/example/config.yml b/example/config.yml index 967e29f..cb48636 100644 --- a/example/config.yml +++ b/example/config.yml @@ -32,7 +32,7 @@ # Configure coinwatch config: - # Specify the column to sort this table by default or leave empty. + # Specify the default column to sort this table by or leave empty for unsorted. # Overwrite via -s sort: # Specify the sort order (asc or desc) @@ -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: