<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="https://sandfox.me/assets/xml/atom.xsl" type="text/xsl media="all"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom">
  <title>Sand Fox (Posts about currency conversion)</title>
  <id>https://sandfox.me/tags/currency-conversion.xml</id>
  <updated>2026-01-05T10:06:09Z</updated>
  <author>
    <name>Anton Smirnov</name>
  </author>
  <link rel="self" type="application/atom+xml" href="https://sandfox.me/tags/currency-conversion.xml"/>
  <link rel="alternate" type="text/html" href="https://sandfox.me/tags/currency-conversion.html"/>
  <generator uri="https://getnikola.com/">Nikola</generator>
  <entry>
    <title>Peso Framework</title>
    <id>https://sandfox.me/php/peso.html</id>
    <updated>2025-07-11T06:42:00+03:00</updated>
    <published>2025-07-11T06:42:00+03:00</published>
    <author>
      <name>Anton Smirnov</name>
    </author>
    <link rel="alternate" type="text/html" href="https://sandfox.me/php/peso.html"/>
    <summary type="html">&lt;p&gt;Another thing I've been secretly building is the &lt;a class="reference external" href="https://phpeso.org"&gt;Peso Framework&lt;/a&gt;, a tool to query currency conversion rates.&lt;/p&gt;
&lt;p&gt;It started when I was pissed that &lt;code class="docutils literal"&gt;florianv/exchanger&lt;/code&gt;, a tool I was perfectly happy with previously,
got a broken release (2.8.2) got abandoned for almost a year now, and still isn't fixed as of this post.&lt;/p&gt;
&lt;p&gt;Peso consists of 3 components:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;A service (data source)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An integration (data consumer)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A glue library (&lt;code class="docutils literal"&gt;peso/core&lt;/code&gt;) that contains the Service contract,
standard request/response objects, and useful tools to develop services and integrations&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A simple example:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code bash"&gt;&lt;a id="rest_code_e87af1df86794908b9c38661569fb51b-1" name="rest_code_e87af1df86794908b9c38661569fb51b-1" href="https://sandfox.me/php/peso.html#rest_code_e87af1df86794908b9c38661569fb51b-1"&gt;&lt;/a&gt;composer&lt;span class="w"&gt; &lt;/span&gt;require&lt;span class="w"&gt; &lt;/span&gt;peso/peso&lt;span class="w"&gt; &lt;/span&gt;peso/ecb-service&lt;span class="w"&gt; &lt;/span&gt;php-http/discovery&lt;span class="w"&gt; &lt;/span&gt;guzzlehttp/guzzle
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="code"&gt;&lt;pre class="code php"&gt;&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-1" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-1" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-1"&gt;&lt;/a&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-2" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-2" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-2"&gt;&lt;/a&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-3" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-3" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-3"&gt;&lt;/a&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;Peso\Peso\CurrencyConverter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-4" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-4" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-4"&gt;&lt;/a&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nx"&gt;Peso\Services\EuropeanCentralBankService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-5" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-5" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-5"&gt;&lt;/a&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-6" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-6" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-6"&gt;&lt;/a&gt;&lt;span class="k"&gt;require&lt;/span&gt; &lt;span class="no"&gt;__DIR__&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-7" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-7" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-7"&gt;&lt;/a&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-8" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-8" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-8"&gt;&lt;/a&gt;&lt;span class="c1"&gt;// caching omitted for simplicity&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-9" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-9" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-9"&gt;&lt;/a&gt;&lt;span class="nv"&gt;$peso&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;CurrencyConverter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;EuropeanCentralBankService&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-10" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-10" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-10"&gt;&lt;/a&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-11" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-11" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-11"&gt;&lt;/a&gt;&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$peso&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;getHistoricalExchangeRate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-12" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-12" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-12"&gt;&lt;/a&gt;    &lt;span class="s1"&gt;'EUR'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// base&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-13" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-13" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-13"&gt;&lt;/a&gt;    &lt;span class="s1"&gt;'PHP'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// quote&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-14" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-14" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-14"&gt;&lt;/a&gt;    &lt;span class="s1"&gt;'2025-06-13'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// date (Y-m-d string or DateTime or arokettu/date Date)&lt;/span&gt;
&lt;a id="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-15" name="rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-15" href="https://sandfox.me/php/peso.html#rest_code_74e3d2110e3b4c1e9ccc7acc5cefc66f-15"&gt;&lt;/a&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;PHP_EOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// '64.706'&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Advantages over the Exchanger:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Caching moved to the Service side making it more effective&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No way for a service to mistake a historical exchange rate request with a current exchange rate request&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also currency conversion requests for services that support them&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ability to add new request types without breaking the backward compatibility&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Services reside in their own separate packages
so the main package is not a huge garbage dump of dead or unsupported services like Cryptonator&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;</summary>
    <category term="currency-conversion" label="currency conversion"/>
    <category term="peso" label="peso"/>
  </entry>
</feed>
