docker-finance | modern accounting for the power-user

Dedicated to Michael Morgan: a beautiful, beautiful soul.

---

Internal signing keys:

  Aaron Fiore (sole author)

    - 518A22F85BEFD32BCC99C48603F90C4F35E0213E
    - 31ECA5C347A0CC0815EDE730A3EACCFCDA7E685E
    - C8187C585CB07A4DA81CC0F37318B50EBE9C0DA8

Internal repositories (rebased from):

  Staging:

    $ git log -n1 --pretty=format:"%H"
    c8e0cd66f6c89fa7b3c62f72fb524a4cc454b7b6

    $ git rev-list --max-parents=0 HEAD
    ac3863b8c234755855f1aea3a07a853122decdf2

  Private:

    $ git log -n1 --pretty=format:"%H"
    69bb3591eaa2990a9637832bb484690e00c4f926

    $ git rev-list --max-parents=0 HEAD
    a5c1cc9fb593c4cf09bc0adfef6cb6d2964511ae
This commit is contained in:
2024-03-04 03:12:40 -08:00
commit b621e87df2
505 changed files with 37687 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
<?php
// docker-finance | modern accounting for the power-user
//
// Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/**
* @file
* @author Aaron Fiore (Founder, Evergreen Crypto LLC)
* @since docker-finance 1.0.0
*/
//! @since docker-finance 1.0.0
namespace docker_finance
{
require_once('blockchains/fetch.php');
require_once('exchanges/fetch.php');
require_once('prices/fetch.php');
require_once('utils/utils.php');
/**
* @brief API executor
* @details
* - One-and-only callee for external caller
* - Sets internal environment from external shell environment and $argv
* - Instantiates and executes fetching process
*
* @param int $argc Argument count
* @param array<string> $argv Argument list
*
* @ingroup php_API
* @since docker-finance 1.0.0
*/
function main(int $argc, array $argv): void
{
if (!$argc || empty($argv[1]) || empty($argv[2])) {
utils\CLI::throw_fatal('valid argument needed for interal API');
}
//
// Set environment "map"
//
$env = new utils\Env();
// Fetch (API)
$env->set_env('API_FETCH_TYPE', strtolower($argv[1])); // API type
$env->set_env('API_FETCH_SUBTYPE', strtolower($argv[2])); // API subtype
$env->set_env('API_FETCH_YEAR', getenv('API_FETCH_YEAR')); // API year (to fetch)
$env->set_env('API_OUT_DIR', getenv('API_OUT_DIR') . '/'); // API output path (account's 1-in dir)
// Prices
$env->set_env('API_PRICES_PATH', getenv('API_PRICES_PATH')); // Master file
$env->set_env('API_PRICES_SYMBOLS', getenv('API_PRICES_SYMBOLS')); // User-provided symbols
// Exchanges
$env->set_env('API_KEY', getenv('API_KEY')); // Exchange or blockchain scanner API key
$env->set_env('API_PASSPHRASE', getenv('API_PASSPHRASE')); // Exchange passphrase
$env->set_env('API_SECRET', getenv('API_SECRET')); // Exchange secret
// Exchanges/Blockchains
$env->set_env('API_SUBACCOUNT', getenv('API_SUBACCOUNT')); // Subaccount(s)
//
// Create fetch object
//
$type = $env->get_env('API_FETCH_TYPE');
$subtype = $env->get_env('API_FETCH_SUBTYPE');
switch ($type) {
case 'account':
switch ($subtype) {
case 'bittrex':
case 'celsius':
case 'coinbase':
case 'coinbase-pro':
case 'gemini':
$api = new exchanges\Fetch($env);
break;
case 'coinbase-wallet':
case 'coinomi':
case 'ledger':
case 'metamask':
case 'pera-wallet':
$api = new blockchains\Fetch($env);
break;
default:
utils\CLI::throw_fatal("unsupported subtype '$subtype' for interal API");
break;
}
break;
case 'prices':
switch ($env->get_env('API_FETCH_SUBTYPE')) {
case 'crypto':
$api = new prices\Fetch($env);
break;
// TODO: stocks and bonds and ETFs, oh my!
default:
utils\CLI::throw_fatal("unsupported subtype '$subtype' for interal API");
break;
}
break;
default:
utils\CLI::throw_fatal("unsupported type '$type' for interal API");
break;
}
//
// Execute
//
assert(isset($api));
$api->fetch();
}
} // namespace docker_finance
namespace
{
try {
docker_finance\main($argc, $argv);
} catch (Throwable $e) {
docker_finance\utils\CLI::print_fatal(
"\n\t" . $e->getMessage() . "\n\t" .
$e->getFile() . ':' . $e->getLine()
);
exit(1);
}
} // namespace
# vim: sw=4 sts=4 si ai et