Skip to content

Commit

Permalink
Refactor CurrencyPair constant method (more realistic)
Browse files Browse the repository at this point in the history
  • Loading branch information
dve committed Aug 19, 2017
1 parent 39b1210 commit 56e5e0a
Showing 1 changed file with 176 additions and 68 deletions.
244 changes: 176 additions & 68 deletions src/Constant/CurrencyPair.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,188 @@

class CurrencyPair
{
const BCHEUR = 'BCH/EUR';
const DASHEUR = 'DASH/EUR';
const DASHUSD = 'DASH/USD';
const DASHXBT = 'DASH/XBT';
const EOSETH = 'EOS/ETH';
const EOSEUR = 'EOS/EUR';
const EOSUSD = 'EOS/USD';
const EOSXBT = 'EOS/XBT';
const GNOETH = 'GNO/ETH';
const GNOEUR = 'GNO/EUR';
const GNOUSD = 'GNO/USD';
const GNOXBT = 'GNO/XBT';
const USDTZUSD = 'USDT/ZUSD';
const XETCXETH = 'XETC/XETH';
const XETCXXBT = 'XETC/XXBT';
const XETCZEUR = 'XETC/ZEUR';
const XETCXUSD = 'XETC/XUSD';
const XETHXXBT = 'XETH/XXBT';
const XETHZCAD = 'XETH/ZCAD';
const XETHZEUR = 'XETH/ZEUR';
const XETHZGBP = 'XETH/ZGBP';
const XETHZJPY = 'XETH/ZJPY';
const XETHZUSD = 'XETH/ZUSD';
const XICNXETH = 'XICN/XETH';
const XICNXXBT = 'XICN/XXBT';
const XLTCXXBT = 'XLTC/XXBT';
const XLTCZEUR = 'XLTC/ZEUR';
const XLTCZUSD = 'XLTC/ZUSD';
const XMLNXETH = 'XMLN/XETH';
const XMLNXXBT = 'XMLN/XXBT';
const XREPXETH = 'XREP/XETH';
const XREPXXBT = 'XREP/XXBT';
const XREPZEUR = 'XREP/ZEUR';
const XREPZUSD = 'XREP/ZUSD';
const XXBTZCAD = 'XXBT/ZCAD';
const XXBTZEUR = 'XXBT/ZEUR';
const XXBTZGBP = 'XXBT/ZGBP';
const XXBTZJPY = 'XXBT/ZJPY';
const XXBTZUSD = 'XXBT/ZUSD';
const XXDGXXBT = 'XXDG/XXBT';
const XXLMXXBT = 'XXLM/XXBT';
const XXLMZEUR = 'XXLM/ZEUR';
const XXLMZUSD = 'XXLM/ZUSD';
const XXMRXXBT = 'XXMR/XXBT';
const XXMRZEUR = 'XXMR/ZEUR';
const XXMRZUSD = 'XXMR/ZUSD';
const XXRPXXBT = 'XXRP/XXBT';
const XXRPZCAD = 'XXRP/ZCAD';
const XXRPZEUR = 'XXRP/ZEUR';
const XXRPZJPY = 'XXRP/ZJPY';
const XXRPZUSD = 'XXRP/ZUSD';
const XZECXXBT = 'XZEC/XXBT';
const XZECZEUR = 'XZEC/ZEUR';
const XZECZUSD = 'XZEC/ZUSD';
const BCHEUR = 'BCHEUR';
const DASHEUR = 'DASHEUR';
const DASHUSD = 'DASHUSD';
const DASHXBT = 'DASHXBT';
const EOSETH = 'EOSETH';
const EOSEUR = 'EOSEUR';
const EOSUSD = 'EOSUSD';
const EOSXBT = 'EOSXBT';
const GNOETH = 'GNOETH';
const GNOEUR = 'GNOEUR';
const GNOUSD = 'GNOUSD';
const GNOXBT = 'GNOXBT';
const USDTZUSD = 'USDTZUSD';
const XETCXETH = 'XETCXETH';
const XETCXXBT = 'XETCXXBT';
const XETCZEUR = 'XETCZEUR';
const XETCXUSD = 'XETCXUSD';
const XETHXXBT = 'XETHXXBT';
const XETHZCAD = 'XETHZCAD';
const XETHZEUR = 'XETHZEUR';
const XETHZGBP = 'XETHZGBP';
const XETHZJPY = 'XETHZJPY';
const XETHZUSD = 'XETHZUSD';
const XICNXETH = 'XICNXETH';
const XICNXXBT = 'XICNXXBT';
const XLTCXXBT = 'XLTCXXBT';
const XLTCZEUR = 'XLTCZEUR';
const XLTCZUSD = 'XLTCZUSD';
const XMLNXETH = 'XMLNXETH';
const XMLNXXBT = 'XMLNXXBT';
const XREPXETH = 'XREPXETH';
const XREPXXBT = 'XREPXXBT';
const XREPZEUR = 'XREPZEUR';
const XREPZUSD = 'XREPZUSD';
const XXBTZCAD = 'XXBTZCAD';
const XXBTZEUR = 'XXBTZEUR';
const XXBTZGBP = 'XXBTZGBP';
const XXBTZJPY = 'XXBTZJPY';
const XXBTZUSD = 'XXBTZUSD';
const XXDGXXBT = 'XXDGXXBT';
const XXLMXXBT = 'XXLMXXBT';
const XXLMZEUR = 'XXLMZEUR';
const XXLMZUSD = 'XXLMZUSD';
const XXMRXXBT = 'XXMRXXBT';
const XXMRZEUR = 'XXMRZEUR';
const XXMRZUSD = 'XXMRZUSD';
const XXRPXXBT = 'XXRPXXBT';
const XXRPZCAD = 'XXRPZCAD';
const XXRPZEUR = 'XXRPZEUR';
const XXRPZJPY = 'XXRPZJPY';
const XXRPZUSD = 'XXRPZUSD';
const XZECXXBT = 'XZECXXBT';
const XZECZEUR = 'XZECZEUR';
const XZECZUSD = 'XZECZUSD';

public static function getCurrencyPair($currencyPair)
{
return str_replace('/', '', $currencyPair);
}
private static $quoteCurrenciesByPair = [
self::BCHEUR => 'EUR',
self::DASHEUR => 'EUR',
self::DASHUSD => 'USD',
self::DASHXBT => 'XBT',
self::EOSETH => 'ETH',
self::EOSEUR => 'EUR',
self::EOSUSD => 'USD',
self::EOSXBT => 'XBT',
self::GNOETH => 'ETH',
self::GNOEUR => 'EUR',
self::GNOUSD => 'USD',
self::GNOXBT => 'XBT',
self::USDTZUSD => 'ZUSD',
self::XETCXETH => 'XETH',
self::XETCXXBT => 'XXBT',
self::XETCZEUR => 'ZEUR',
self::XETCXUSD => 'XUSD',
self::XETHXXBT => 'XXBT',
self::XETHZCAD => 'ZCAD',
self::XETHZEUR => 'ZEUR',
self::XETHZGBP => 'ZGBP',
self::XETHZJPY => 'ZJPY',
self::XETHZUSD => 'ZUSD',
self::XICNXETH => 'XETH',
self::XICNXXBT => 'XXBT',
self::XLTCXXBT => 'XXBT',
self::XLTCZEUR => 'ZEUR',
self::XLTCZUSD => 'ZUSD',
self::XMLNXETH => 'XETH',
self::XMLNXXBT => 'XXBT',
self::XREPXETH => 'XETH',
self::XREPXXBT => 'XXBT',
self::XREPZEUR => 'ZEUR',
self::XREPZUSD => 'ZUSD',
self::XXBTZCAD => 'ZCAD',
self::XXBTZEUR => 'ZEUR',
self::XXBTZGBP => 'ZGBP',
self::XXBTZJPY => 'ZJPY',
self::XXBTZUSD => 'ZUSD',
self::XXDGXXBT => 'XXBT',
self::XXLMXXBT => 'XXBT',
self::XXLMZEUR => 'ZEUR',
self::XXLMZUSD => 'ZUSD',
self::XXMRXXBT => 'XXBT',
self::XXMRZEUR => 'ZEUR',
self::XXMRZUSD => 'ZUSD',
self::XXRPXXBT => 'XXBT',
self::XXRPZCAD => 'ZCAD',
self::XXRPZEUR => 'ZEUR',
self::XXRPZJPY => 'ZJPY',
self::XXRPZUSD => 'ZUSD',
self::XZECXXBT => 'XXBT',
self::XZECZEUR => 'ZEUR',
self::XZECZUSD => 'ZUSD'
];

public static function getPriceCurrency($currencyPair)
{
return substr($currencyPair, strlen($currencyPair)-4, 3);
}
private static $baseCurrenciesByPair = [
self::BCHEUR => 'BCH',
self::DASHEUR => 'DASH',
self::DASHUSD => 'DASH',
self::DASHXBT => 'DASH',
self::EOSETH => 'EOS',
self::EOSEUR => 'EOS',
self::EOSUSD => 'EOS',
self::EOSXBT => 'EOS',
self::GNOETH => 'GNO',
self::GNOEUR => 'GNO',
self::GNOUSD => 'GNO',
self::GNOXBT => 'GNO',
self::USDTZUSD => 'USDT',
self::XETCXETH => 'XETC',
self::XETCXXBT => 'XETC',
self::XETCZEUR => 'XETC',
self::XETCXUSD => 'XETC',
self::XETHXXBT => 'XETH',
self::XETHZCAD => 'XETH',
self::XETHZEUR => 'XETH',
self::XETHZGBP => 'XETH',
self::XETHZJPY => 'XETH',
self::XETHZUSD => 'XETH',
self::XICNXETH => 'XICN',
self::XICNXXBT => 'XICN',
self::XLTCXXBT => 'XLTC',
self::XLTCZEUR => 'XLTC',
self::XLTCZUSD => 'XLTC',
self::XMLNXETH => 'XMLN',
self::XMLNXXBT => 'XMLN',
self::XREPXETH => 'XREP',
self::XREPXXBT => 'XREP',
self::XREPZEUR => 'XREP',
self::XREPZUSD => 'XREP',
self::XXBTZCAD => 'XXBT',
self::XXBTZEUR => 'XXBT',
self::XXBTZGBP => 'XXBT',
self::XXBTZJPY => 'XXBT',
self::XXBTZUSD => 'XXBT',
self::XXDGXXBT => 'XXDG',
self::XXLMXXBT => 'XXLM',
self::XXLMZEUR => 'XXLM',
self::XXLMZUSD => 'XXLM',
self::XXMRXXBT => 'XXMR',
self::XXMRZEUR => 'XXMR',
self::XXMRZUSD => 'XXMR',
self::XXRPXXBT => 'XXRP',
self::XXRPZCAD => 'XXRP',
self::XXRPZEUR => 'XXRP',
self::XXRPZJPY => 'XXRP',
self::XXRPZUSD => 'XXRP',
self::XZECXXBT => 'XZEC',
self::XZECZEUR => 'XZEC',
self::XZECZUSD => 'XZEC'
];

public static function getCurrency1($currencyPair)
public static function getBaseCurrency($pair)
{
$array = explode('/', $currencyPair);
return count($array) > 0 ? $currencyPair[0] : '';
if(array_key_exists($pair, self::$baseCurrenciesByPair)) {
return self::$baseCurrenciesByPair[$pair];
}
throw new \InvalidArgumentException('Pair "' . $pair . '" is not supported');
}

public static function getCurrency2($currencyPair)
public static function getQuoteCurrency($pair)
{
$array = explode('/', $currencyPair);
return count($array) > 1 ? $currencyPair[1] : '';
if(array_key_exists($pair, self::$quoteCurrenciesByPair)) {
return self::$quoteCurrenciesByPair[$pair];
}
throw new \InvalidArgumentException('Pair "' . $pair . '" is not supported');
}
}

0 comments on commit 56e5e0a

Please sign in to comment.