Skip to content

problems with "Binance-Peg xxx" crypto #7

@puiseux

Description

@puiseux

Hello,
Thanks for this very useful python script.
This command works fine :
$ ./pycoin.py --crypto BTC,ETH

  Rank  Symbol    Name        Price (USD)    24h-Change (USD)    7d-Change (USD)    24h-Volume (USD)
------  --------  --------  -------------  ------------------  -----------------  ------------------
     1  BTC       Bitcoin      63118.0000               0.12%              1.77%         31908066246
     2  ETH       Ethereum      4230.8800               2.07%             12.74%         16759813047

Source: https://www.coingecko.com - 2021-10-26 11:05:04

BUT this command leads to exception :

$ ./pycoin.py --crypto BTC,ETH,ADA

  File "/Users/puiseux/GitHub/mytrade/./pycoin.py", line 279, in <module>
    main(args.curr, cryptos, args.sort, args.delay > 0)
  File "/Users/puiseux/GitHub/mytrade/./pycoin.py", line 219, in main
    print_selection_multitab(selection, sort_value)
  File "/Users/puiseux/GitHub/mytrade/./pycoin.py", line 176, in print_selection_multitab
    selection = sort_selection(selection, sort_value, currency)
  File "/Users/puiseux/GitHub/mytrade/./pycoin.py", line 166, in sort_selection
    return sorted(selection, key=cases[sort_value.replace("-", "")],
TypeError: '<' not supported between instances of 'NoneType' and 'int'

The problem is that ADA id is "Binance-Peg Cardano" which has rank=None in coingecko (Cardano has rank=3).
This can be roughly solved by changing one line in sort_selection(...) like this :

def sort_selection(selection, sort_value, curr):
    ##############################################
    #cases = {"rank": lambda x: x.rank,                            # <= bad
    cases = {"rank": lambda x: -1 if x.rank is None else x.rank,    # <= better
    ##############################################
             "price": lambda x: x.currencies[curr]["price"],
             "change_24h": lambda x: x.currencies[curr]["percent_change_24h"],
             "change_7d": lambda x: x.currencies[curr]["percent_change_7d"],
             "volume": lambda x: x.currencies[curr]["volume_24h"]}

    return sorted(selection, key=cases[sort_value.replace("-", "")],
                  reverse="-" not in sort_value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions