Giter VIP home page Giter VIP logo

r055a / multicurrencyconverter Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 50 KB

Python CLI for converting multiple currencies, including crypto and unsupported, combined with or without any variation of ISO-supported codes.

Python 100.00%
crypto cryptocurrencies cryptocurrency currency currency-codes cli python inclusive-coding coingecko-api exchangerate-api travel cash api change converter conversion exchange rate code loose-change

multicurrencyconverter's Introduction

Multi-Currency Converter CLI

A simple Python CLI application for converting any of multiple currencies to a specified target with generated results, including conversion total sum and individual amounts and exchange rates, being up-to-date approximate estimates.

Includes all ISO-supported and unsupported digital, crypto, and optional custom currencies.

Digital Currencies

ISO-supported currency information is available at ExchangeRate-API: Supported Currencies.

The following unsupported currencies are included using fixed exchange rates* to a supported currency:

Code Currency Name Country/State Fixed Exchange Rate
ABK Abkhazian Apsar Abkhazia 1 ABX = 10 RUB
EHP Sahrawi Peseta Western Sahara 1 EHP = 0.00601 EUR
EUZ EuroUžas Republic of Užupis 1 EUZ = 5 EUR
KPW North Korean Won North Korea 1 KPW = 0.000125 USD
MLS** Maltese Scudo Sovereign Military Order of Malta 1 Maltese Scudo = 0.24 EUR
ORA** Ora Orania 1 ORA = 1 ZAR
PND Pitkern Ailen Dollar Pitcairn Islands 1 PND = 1 NZD
PRB Transnistrian Ruble Transnistria 1 PRB = 0.06135 USD
SLE Somaliland Shilling Somaliland 1 SLE = 0.000125 USD

*The accuracy of fixed exchange rates cannot be confirmed and can be subject to change.
**Fabricated currency codes when none otherwise exist for application-specific indexing purposes.

Cryptocurrencies

There are 14,911 cryptocurrencies supported by CoinGecko API, with the following included in this app by default:

Code Currency Name
BTC Bitcoin
ETH Ethereum
BNB Binancecoin
XRP Ripple
ADA Cardano
SOL Solana
DOT Polkadot
DOGE Dogecoin
LTC Litecoin
LINK Chainlink

To optionally include more cryptocurrencies, following these Add Custom Currency Instructions.

Instructions

Requirements

Install

Pip libraries required to run the app listed in the requirements.txt file can be installed executing the command:

pip install -r requirements.txt

Setup - API Key

An API key is required to fetch digital currency data from the ExchangeRate-API.

A key can be set for application use by either creating an environment variable named EXCHANGE_RATE_API_KEY with the key entered as the value, or replace the empty string with it hardcoded to the source code, as in the example:

Before Edit

CURRENCY_EXCHANGE_RATE_API_KEY: str = getenv(
    "EXCHANGE_RATE_API_KEY", ""
)  # add API key as environment variable or replace the empty string.

After Edit

CURRENCY_EXCHANGE_RATE_API_KEY: str = getenv(
    "EXCHANGE_RATE_API_KEY", "85b6a40bda2db784e803da02"
)  # add API key as environment variable or replace the empty string.

Setup - Currency Amount

To convert from any currency, an amount value above the default 0 is first required to be entered before running the application. There is no CLI command for this, it must be completed manually as follows by editing either of the currencies.json or cryptos.json files for entering amount values to given digital currencies and cryptocurrencies, respectively.

For any given currency JSON object, enter a digital value representative of the amount in the currency wanting to be converted to the amount variable, such as in the following example when editing a value of 0.01 GBP:

Before Edit

{
  "currencies": [
    ...
    {
      "currency-code": "GBP",
      "currency-name": "Pound Sterling",
      "nation-name": "United Kingdom",
      "amount": 0,
      "alt-currency": {}
    },
    ...
  ]
}

After Edit

{
  "currencies": [
    ...
    {
      "currency-code": "GBP",
      "currency-name": "Pound Sterling",
      "nation-name": "United Kingdom",
      "amount": 0.01,
      "alt-currency": {}
    },
    ...
  ]
}

It seems more efficient to manually edit the amount values rather than multiple CLI commands per currency. Use the keyboard shortcut CTRL-F to quick-search for a currency in a JSON file when entering an amount.

Setup - Custom Currency

Any currency not included by default can be added following these instructions:

Supported Digital Currency

An ISO-supported currency is simpler to add than an unsupported currency as the alt-currency variable can be excluded from editing and left empty. Scroll to the bottom of the currencies.json file and enter a custom digital currency, such as in the following example for New Zealand Dollar, although already entered, where the amount is 0 by default, but any value can be entered:

{
  "currencies": [
    ...
    {
      "currency-code": "NZL",
      "currency-name": "New Zealand Dollar",
      "nation-name": "New Zealand",
      "amount": 0,
      "alt-currency": {}
    }
  ]
}

Unsupported Digital Currency

For an ISO-unsupported currency to effectively be included for conversion, it must have a fixed exchange rate with either an ISO-supported currency or cryptocurrency listed in the currencies.json or cryptos.json files, respectively, to be valid.

A fixed-exchange-rate value can be entered to the alt-currency variable JSON body, such as in the following example for Fictional Unsupported Currency with a fixed-conversion-rate of 100000000000000 ZWL and where the amount is 0 by default, but any value can be entered:

{
  "currencies": [
    ...
    {
      "currency-code": "FUC",
      "currency-name": "Fictional Unsupported Currency",
      "nation-name": "Fictional Unsupported Currency Imaginary Party Nation",
      "amount": 0,
      "alt-currency": {
        "currency-code": "ZWL",
        "currency-name": "Fictional Unsupported Currency (fixed at 1 FUC = 100000000000000 ZWL)",
        "fixed-conversion-rate": 100000000000000
      }
    }
  ]
}

Cryptocurrency

Entering a custom cryptocurrency is simpler than a digital currency as only the currency-code and currency-name are required in addition to the amount variable. Scroll to the bottom of the cryptos.json file and enter a custom cryptocurrency, such as in the following example for 01coin where the amount is 0 by default, but any value can be entered:

{
  "currencies": [
    ...
    {
      "currency-code": "ZOC",
      "currency-name": "01coin",
      "amount": 0
    }
  ]
}

A custom cryptocurrency code must be supported by the CoinGecko API to be valid

Run

To run the app for converting currency amount(s) to a given base currency, execute the following command:

python currency_converter.py

Follow CLI user prompt instructions to enter a valid base currency for generating converted amount(s).

A base currency must be listed in either of the currencies.json or cryptos.json files to be valid

multicurrencyconverter's People

Contributors

r055a avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.