All Projects → h4kuna → Exchange

h4kuna / Exchange

Php script works with currenries.

Projects that are alternatives of or similar to Exchange

Currency
Handles currency calculations, storage etc
Stars: ✭ 109 (+419.05%)
Mutual labels:  currencies, exchange
django-prices-openexchangerates
openexchangerates.org support for django-prices
Stars: ✭ 33 (+57.14%)
Mutual labels:  exchange, currencies
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (+700%)
Mutual labels:  currencies, exchange
cotizacion
Portal to find current exchange rates in Paraguay
Stars: ✭ 11 (-47.62%)
Mutual labels:  exchange, currencies
stockholm
💵 Modern Python library for working with money and monetary amounts. Human friendly and flexible approach for development. 100% test coverage + built-in support for GraphQL and Protocol Buffers transports using current best-practices.
Stars: ✭ 26 (+23.81%)
Mutual labels:  exchange, currencies
currency-converter
💰 Easily convert between 32 currencies
Stars: ✭ 16 (-23.81%)
Mutual labels:  exchange, currencies
Mfcmapi
MFCMAPI
Stars: ✭ 501 (+2285.71%)
Mutual labels:  exchange
Urql
The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
Stars: ✭ 6,604 (+31347.62%)
Mutual labels:  exchange
Atomicswap
On-chain atomic swaps for Decred and other cryptocurrencies.
Stars: ✭ 485 (+2209.52%)
Mutual labels:  exchange
Bitex
Crypto-currency Exchange API Framework
Stars: ✭ 455 (+2066.67%)
Mutual labels:  exchange
Livecoin Api
LiveCoin RESTful API wrapper for Node.js
Stars: ✭ 12 (-42.86%)
Mutual labels:  currencies
Exchange Core
Ultra-fast matching engine written in Java based on LMAX Disruptor, Eclipse Collections, Real Logic Agrona, OpenHFT, LZ4 Java, and Adaptive Radix Trees.
Stars: ✭ 801 (+3714.29%)
Mutual labels:  exchange
Cryptofeed
Cryptocurrency Exchange Websocket Data Feed Handler
Stars: ✭ 643 (+2961.9%)
Mutual labels:  exchange
Qtbitcointrader
Secure multi crypto exchange trading client
Stars: ✭ 520 (+2376.19%)
Mutual labels:  exchange
Kline
一个 javascript K线插件. A K line library written in javascript.
Stars: ✭ 702 (+3242.86%)
Mutual labels:  exchange
Exchangesharp
ExchangeSharp is a powerful, fast and easy to use .NET/C# API for interfacing with many crypto currency exchanges. REST and web sockets are supported.
Stars: ✭ 489 (+2228.57%)
Mutual labels:  exchange
Gocurrency
Simple currency converter. Insert an amount, what currency to convert from and what currency to convert to.
Stars: ✭ 26 (+23.81%)
Mutual labels:  currencies
Parity
Open source software platform for trading venues
Stars: ✭ 468 (+2128.57%)
Mutual labels:  exchange
Awesome Blockchain
Curated list of blockchain services and exchanges 🔥🏦🔥🏦🔥🏦🔥
Stars: ✭ 604 (+2776.19%)
Mutual labels:  exchange
Exchangelib
Python client for Microsoft Exchange Web Services (EWS)
Stars: ✭ 787 (+3647.62%)
Mutual labels:  exchange

Exchange

Build Status Latest stable Downloads this Month Scrutinizer Code Quality Coverage Status

Exchange is PHP script works with currencies. You can convert price, format add VAT or only render exchange rates.

Here is changelog.

Extension for framework

Installation via composer

$ composer require h4kuna/exchange

How to use

Init object Exchange and Cache. Default Driver for read is Cnb, here are others.

For example define own exchange rates:

  • 25 CZK = 1 EUR
  • 20 CZK = 1 USD
use h4kuna\Exchange;

$cache = new Caching\Cache('/temp/dir');
$exchange = new Exchange\Exchange($cache);

$exchange->setDefault('eur');
$exchange->setOutput('usd');

echo $exchange->change(100); // EUR -> USD = 125.0
echo $exchange->change(100, 'czk'); // CZK -> USD = 5.0
echo $exchange->change(100, NULL, 'czk'); // EUR -> CZK = 2500.0
echo $exchange->change(100, 'usd', 'czk'); // USD -> CZK = 2000.0

Change driver and date

Download history exchange rates.

$exchange->setDriver(new Exchange\Driver\Cnb\Day, new \Datetime('2000-12-30'));

If we need read data from database, it is not problem write own Driver.

class MyDatabaseDriver extend \h4kuna\Exchange\Driver\ADriver 
{
    /**
     * Load data for iterator.
     * @param DateTime|NULL $date
     * @return array
     */
    protected function loadFromSource(DateTime $date = NULL)
    {
        // your implementation
        $this->setDate('Y-m-d', (string) $database->selectDate());
        return $database->fetchMyCurrencies();
    }

    /**
     * Modify data before save to cache.
     * @return Exchange\Currency\Property|NULL
     */
    protected function createProperty($row) 
    {
        return new \h4kuna\Exchange\Currency\Property([
            'code' => $row['currency'],
            'home' => $row['rate'],
            'foreign' => 1
        ]);
    }
}

$exchange->setDriver(new \MyDatabaseDriver);

Format output

Define output formats, for more information read this documentation h4kuna/number-format.

$formats = new Exchange\Currency\Formats(new \h4kuna\Number\NumberFormatFactory());

$formats->addFormat('EUR', ['decimalPoint' => '.', 'unit' => '€']);

Create Filters for format API.

$filters = new Exchange\Filters($exchange, $formats);

You can define VAT

// VAT 21%
$filters->setVat(new \h4kuna\Number\Tax(21));

Output

// format 100 EUR like default to USD is set above
$filters->format(100); // '125,00 USD'

// count with VAT
$filters->formatVat(100, 'usd', 'eur'); // '96.80 €'
$filters->formatVatTo(100); // '151,25 USD'
$filters->formatTo(100, 'CZK'); // '2 000,00 CZK'

// Other options
$filters->change(100, 'usd', 'eur'); // 80.0
$filters->changeTo(100, 'usd'); // 125.0
$filters->vat(100); // 121.0

Temporary rate

$exchange->addRate('usd', 23.0);
$exchange->change(1, 'usd', 'czk'); // 23.0

$exchange->removeRate('usd');
$exchange->change(1, 'usd', 'czk'); // 20.0

Access and iterator

/* @var $property Exchange\Currenry\Property */
$property = $exchange['eur'];
var_dump($property);


foreach ($exchange as $code => $property) {
    /* @var $property Exchange\Currenry\Property */
    var_dump($property);
}

Limit for currencies

$cache = new Caching\Cache('/temp/dir');
$cache->setAllowedCurrencies(['CZK', 'USD', 'EUR']);
$exchange = new Exchange\Exchange($cache);

// in cache are only this three currencies
foreach ($exchange as $code => $property) {
    /* @var $property Exchange\Currenry\Property */
    var_dump($property);
}

Save state to cookie

Here is prepared object whose keep selected currency.

Run on startup of you project.

$cookieManager = Exchange\Http\CookieManager($exchange);

Set new option

$cookieManager->setCurrency($_GET['currency']);

Cache

Default Cache save data on filesystem you can implement ICache interface and change it.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].