Package: denarius
denariuscurrency and other utilitiesIf you don’t find a way to make money while you sleep, you will work
until you die. – Warren Buffettintroductiondenarius is a project, not a finished product. It features various
utilities for collating cryptocurrency, mining, financial and other
data, for plotting data and for accessing bank accounts. It features
analyses of data for systematic descriptions, for predictions, for
arbitrage etc.setupsudoapt-getinstallsqlitewgethttps://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gztar-xvzfgeckodriver-v0.19.1-linux64.tar.gzrmgeckodriver-v0.19.1-linux64.tar.gzchmod+xgeckodriversudocpgeckodriver/usr/local/bin/sudopip2installgit+https://github.com/veox/python2-krakenex.gitsudopip3installgit+https://github.com/veox/python3-krakenex.gitsudopipinstalldenarius--upgrade--process-dependency-linksBitcoin valuesThe functionticker_Bitcoinreturns data of the following form:{'volume':2050.1665002833397,'last':992.2553834529656,'timestamp':1487551580.0,'bid':991.8303740083114,'vwap':993.3415187004156,'high':1002.9278428409522,'low':981.3656970154892,'ask':992.2553834529656,'open':993.3887419720438}It accesses data from Bitstamp.featuredescriptionlastlast Bitcoin pricehighlast 24 hours price highlowlast 24 hours price lowvwaplast 24 hours volume weighted average pricevolumelast 24 hours volumebidhighest buy orderasklowest sell ordertimestampUNIX timestamp date and timeopenfirst price of the dayThe functiondata_historical_Bitcoinreturns by default data of the
following form:{'bpi':{'2017-02-17':992.1077,'2017-02-16':969.2414,'2017-02-15':952.6512,'2017-02-14':954.1432,'2017-02-13':940.7982,'2017-02-12':940.1764,'2017-02-11':949.3397,'2017-02-10':933.4325,'2017-02-19':991.254,'2017-02-18':997.0854},'time':{'updated':'Feb 20, 2017 00:20:08 UTC','updatedISO':'2017-02-20T00:20:08+00:00'},'disclaimer':'This data was produced from the CoinDesk Bitcoin Price Index. BPI value data returned as EUR.'}With the optionreturn_list, it returns data of the following form:[['2017-02-10',933.4325],['2017-02-11',949.3397],['2017-02-12',940.1764],['2017-02-13',940.7982],['2017-02-14',954.1432],['2017-02-15',952.6512],['2017-02-16',969.2414],['2017-02-17',992.1077],['2017-02-18',997.0854],['2017-02-19',991.254]]With the optionreturn_UNIX_times, it returns data of the following
form:[[1486684800,933.4325],[1486771200,949.3397],[1486857600,940.1764],[1486944000,940.7982],[1487030400,954.1432],[1487116800,952.6512],[1487203200,969.2414],[1487289600,992.1077],[1487376000,997.0854],[1487462400,991.254]]LocalBitcoinsLocalBitcoins data is available via its API. For example, the following
URL gives data on current trades in GBP available by national bank
transfer:https://localbitcoins.com/buy-bitcoins-online/GB/united-kingdom/national-bank-transfer/.jsonThe data returned by the API is of a formlike
this.The functionvalues_Bitcoin_LocalBitcoinreturns the price values
returned by calling the API in this way.importdenariusdenarius.values_Bitcoin_LocalBitcoin()The scriptloop_save_LocalBitcoins_values_to_database.pyloop
records LocalBitcoins data to database. To address closed gateways
arising from repeat calls, the script could be used in a way like the
following:whiletrue;doloop_save_LocalBitcoins_values_to_database.py--timeperiod=3600sleep5400doneThe scriptlogin_web_LocalBitcoins.pyis available for a quick login
to LocalBitcoins using Selenium. It depends on the credentials file~/.lbcexisting and containing information of the following form:username="xxxxxxxxxx"passcode="xxxxxxxxxx"secret="xxxxxxxxxxxxxxxxxxxxxxxx"databasesA database of Bitcoin values can be saved in the following ways:importdenariusdenarius.save_database_Bitcoin(filename="database.db")importdenariusdenarius.save_database_Bitcoin(filename="database_Bitcoin_EUR.db",currency="EUR")denarius.save_database_Bitcoin(filename="database_Bitcoin_GBP.db",currency="GBP")graphsThe functionsave_graph_Bitcoincreates a graph of Bitcoin
historical values over a specified time. The functionsave_graph_LocalBitcoinscreates a graph of LocalBitcoins Bitcoin
lowest prices in GBP as recorded in a database by the scriptloop_save_LocalBitcoins_values_to_database.py.denarius_graph_BitcoinThe scriptdenarius_graph_Bitcoin.pydisplays a PyQt GUI with a
graph of the last Bitcoin values.denarius_graph_Bitcoin.py--helpdenarius_graph_Bitcoin.pydenarius_graph_Bitcoin.py--currency=EUR--days=100LocalBitcoinsA graph can be generated of Bitcoin GBP value versus LocalBitcoins GBP
lowest value:importdenariusdenarius.save_graph_Bitcoin_LocalBitcoins()A graph can be generated of Bitcoin GBP value versus LocalBitcoins GBP
lowest 5 values:importdenariusdenarius.save_graphs_Bitcoin_LocalBitcoins()A graph can be generated of LocalBitcoins normalized prices over days:A graph can be generated of LocalBitcoins normalized prices over weeks:A graph can be generated of LocalBitcoins non-normalized prices over
weeks:Bollinger bandsKanoPoolKanoPool records for addresses can be recorded to CSV in a way like the
following:denarius_loop_save_KanoPool.py--helpdenarius_loop_save_KanoPool.py--addresses=1Miner7R28PKcTRbEDwQt4ykMinunhTehs--interval=10The CSV data can be analysed using the Jupyter NotebookKanoPool.ipynb.NanopoolNanopool records for addresses can be recorded to CSV in a way like the
following:denarius_loop_save_Nanopool.py--helpdenarius_loop_save_Nanopool.py--addresses=0xbd3f1126d4c20f72a77e38dfda18622a6d663cd0The CSV fields are, in order, as follows:datetimeaccountbalanceearnings_per_day_BTCearnings_per_day_ETHearnings_per_day_EURearnings_per_hour_BTCearnings_per_hour_ETHearnings_per_hour_EURearnings_per_minute_BTCearnings_per_minute_ETHearnings_per_minute_EURearnings_per_month_BTCearnings_per_month_ETHearnings_per_month_EURearnings_per_week_BTCearnings_per_week_ETHearnings_per_week_EURhashratehashrate12hrhashrate1hrhashrate24hrhashrate3hrhashrate6hrhashrate_poolpool_minerspool_workersSlush PoolSlush Pool records for an address can be recorded to CSV in a way like
the following:denarius_loop_save_SlushPool.py--helpdenarius_loop_save_SlushPool.py--addresses=1Miner7R28PKcTRbEDwQt4ykMinunhTehs--interval=60--alarm=11800000--slushloginname=user--slushworkername=worker1The CSV fields are, in order, as follows:addresshash ratesharesUNIX timestampunconfirmed reward in Bitcoinconfirmed reward in Bitcointotal reward (confirmed + unconfirmed) in Bitcointotal payout since script launch in Bitcoinnumber of blocks found since script launchThe CSV data can be analysed using the Jupyter NotebookSlushPool.ipynb.banksThe banks module provides utilities for getting transactions of a bank
account (Monzo, Starling or RBS) using theMonzo
API, theStarling
APIand theTeller.io API(background on Teller.io and
Stevie
Graham.
To use this module, credentials files should be created.Access theMonzo developers portaland create a new OAuth confidential client. Set the redirect URL for the
client tohttps://github.com/pawelad/pymonzo. Create a URL of the
following form using the client ID string:https://auth.getmondo.co.uk/?response_type=code&redirect_uri=https://github.com/pawelad/pymonzo&client_id=<YOUR_CLIENT_ID>Access this URL and authorize the client application. The confirmation
e-mail sent contains a URL of the following form:https://github.com/pawelad/pymonzo?code=<YOUR_AUTH_CODE>&state=Copy the authorization code from this URL and then access the URL to
authorize the client application.Launch an interactive Python session and, using the client credentials
and thepymonzoAPI interface, generate an access token and a
refresh token.client_id="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"client_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"auth_code="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"frompymonzoimportMonzoAPImonzo=MonzoAPI(client_id=client_id,client_secret=client_secret,auth_code=auth_code)This saves an authorization that lasts 48 hours to the file~/.pymonzo-token, which contains a dictionary of the following form:{"access_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","client_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","client_secret":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","expires_at":1517106306.8881364,"expires_in":172799,"refresh_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","token_type":"Bearer","user_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxx"}Now, API access can be tested by calling themonzopyMonzo API
interface without any arguments (such that it loads tokens from the file~/.pymonzo-tokenand manages token refreshes).frompymonzoimportMonzoAPImonzo=MonzoAPI()print(monzo.accounts())print(monzo.balance())print(monzo.transactions())For Starling, the credentials file (by default~/.starling) should
be created and its content should be a Starling personal access token.
This is acquired by creating a Starling personal account, then creating
a Starling developers account, linking these accounts, and then
generating a personal access token. More advanced access is possible
using OAuth2.For RBS, the credentials file (by default~/.rbs) should have
content of the following form:token_teller="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"account_code_teller="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"Pandas DataFrames of transactions can be retrieved in ways like the
following:importdenarius.banksdf=denarius.banks.transactions_DataFrame_Monzo()df=denarius.banks.transactions_DataFrame_RBS()df=denarius.banks.transactions_DataFrame_Starling()A payment can be searched for in ways like the following:denarius.banks.payment_in_transactions_Monzo(reference="271828182",amount=314)denarius.banks.payment_in_transactions_RBS(reference="271828182",amount=314)denarius.banks.payment_in_transactions_Starling(reference="271828182",amount=314)These functions search the “counterparty_reference”, “description” and
“notes” fields of a DataFrame of bank account transactions for a
specified reference. If the reference is found, the specified amount of
the payment is compared to the sum of amounts found for the specified
reference in the “amount” field. If a payer name is specified, it is
checked against the payer name of the transaction. They return a
dictionary of the following form:{"reference_found":bool,# True if reference found"payer_name_match":boolorNone,# True if payer name matched, False if payer name not matched, None if no payer name to check"payer_name_observed":string,# payer name observed"amount_correct":bool,# True if sum of amounts found is amount specified"valid":bool,# True if reference found and amount correct"transactions"DataFrame,# DataFrame of matches"amount_difference":float# difference between amount specified and sum of amounts found}So, these functions could be used in a straightforward boolean way to
check if a payment has been made:denarius.banks.payment_in_transactions_Monzo(reference="271828182",amount=314)["valid"]They also could be used in a more involved way to account for occasions
in which a payment is found but has an incorrect amount and a further
payment with the same reference must be requested.Both thetransactions_DataFrameandpayment_in_transactionsfunctions have the optionprint_tablewhich can print to terminal a
table of the transactions under consideration:df=denarius.banks.transactions_DataFrame_Monzo(print_table=True)The scriptprint_table_bank_account.pyuses this functionality to
print to terminal a table of transactions from a specified bank.There is the functionpayment_in_transactions_bankwhich is a
wrapper for the more specialised functions likepayment_in_transactions_Monzo. It takes a bank name as an argument
and uses the appropriate functionality for the bank specified.KrakenThe Kraken module provides utilities for getting current balances of
currencies held, buying Bitcoin for Euros at the last market price, and
sending Bitcoin from Kraken to an address, the key for which has been
verified on Kraken. The scriptsprint_Kraken_balances.py,print_Kraken_last_price_BTC_EUR.pyandbuy_BTC_for_EUR_last_price_on_Kraken.pyall use these
functionalities.The Kraken module depends on the credentials file~/.krakenexisting
and containing the key on the first line and the secret on the second
line.Bitcoin can be sent from Kraken to an address key in a way like the
following:importdenarius.Krakendenarius.Kraken.start_API()print(denarius.Kraken.send_XBT(amount=0.1,address_key="BIGMONEY"))The scriptlogin_web_Kraken.pyis available for a quick login to
Kraken using Selenium. It depends on the credentials file~/.kraken_credentialsexisting and containing information of the
following form:username="xxxxxxxxxx"passcode="xxxxxxxxxx"secret="xxxxxxxxxxxxxxxxxxxxxxxx"RBSThe RBS module provides utilities for getting the balance and recent
transactions of an RBS account using the RBS banking web interface,
Selenium and Firefox. For convenience, account details can be stored in
a credentials file, which is assumed by default to be~/.rbs. The
account code is an alphanumeric code extracted from the web interface.
The content of a credentials file is of the following form, which is
Python code:customer_number="XXXXXXXXXX"PIN="XXXXXX"passcode="XXXXXXXXXXXXXXXXXXXX"account_code="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"A dictionary of the current balance and a pandas DataFrame of recent
transactions is returned by the functionRBS.account_status.importdenarius.RBSstatus=RBS.account_status()balance=status["balance"]df=status["transactions"]The DataFrame features the fieldsdate,descriptionandamount. A transaction containing a certain reference or description
could be selected in the following way:df[df["description"].str.contains("transaction reference 123")]The existence of a transaction can be tested in a way like the
following:ifdf[df["description"].str.contains("transaction reference 123")].values.any():print("transaction found")else:print("transaction not found")The scriptget_account_balance_RBS.pyis available to open an RBS
account web interface and to display the current balance and recent
transactions in the terminal, optionally in a loop.get_account_balance_RBS.py--loopThe scriptdetect_transaction_RBS.pyis available to search for a
transaction or transactions with a specified reference.detect_transaction_RBS.py--reference=123The scriptloop_save_RBS_to_CSV.pyis available to loop save RBS
transactions and balance to CSV, merging with recorded CSV data to avoid
recording duplicates.SantanderThe Santander module provides utilities for getting recent transactions
using the Santander banking web interface, Selenium and Firefox. Account
details are stored in a credentials file, which is assumed by default to
be~/.santander. The content of a credentials file is of the
following form, which is Python code:customer_number="XXXXXXXX"customer_PIN="XXXXX"security_question_answer="XXXXXXXX"A DataFrame of recent transactions is returned by the functionSantander.transactions_DataFrame. The scriptloop_save_Santander_to_CSV.pysaves transactions to CSV in a
continuous loop. The functionSantander.payment_in_transactions_CSVcan search in transactions recorded in CSV for a specified transaction
reference together with a specified value and returns a boolean to
indicate whether the transaction was detected.arbitragedenarius.arbitrageThe scriptdenarius_loop_append_arbitrage_DataFrames_to_CSV.pyrecords data for arbitrage between Kraken and LocalBitcoins UK. The
scriptdenarius_display_arbitrage.pydisplays recorded data and
current prices for arbitrage between Kraken and LocalBitcoins UK.The old scriptloop_save_arbitrage_data_Kraken_LocalBitcoins_UK.pyrecords data for arbitrage between Kraken and LocalBitcoins UK. The old
scriptloop_display_arbitrage_data.pydisplays recorded data and
current prices for arbitrage between Kraken and LocalBitcoins UK.paper wallets for Bitcoin, QR codes of keysThe scriptcreate_QR_codes_of_public_and_private_keys.pycreates a
QR code for a specified public key and private key and enables optional
specification of the size of the resulting PNG images. It loads the keys
from a Python file (keys.pyby default) which defines the string
variableskey_publicandkey_private.The scriptcreate_paper_wallet.pycreates a QR code for a specified
public key and private key. It then creates an image of a Bitcoin paper
wallet. It loads the keys from a Python file (keys.pyby default)
which defines the string variableskey_publicandkey_private.Faster Payments Service2018-01-14
participantsBarclaysCitiClear BankClydesdale BankThe Co-operative BankHSBCLloyds BankMetro BankMonzoNationwideNatWestNorthern BankRaphaels BankRoyal Bank of ScotlandSantanderStarling BankTurkish Bank UKSEPA Instant2018-01-14
participantsAustriaBelgiumBulgariaEstoniaFranceGermanyItalyLatviaLithuaniaMaltaNetherlandsSpain