+ <a href="https://people.skolelinux.org/pere/blog/Updated_Valutakrambod__now_also_with_information_from_NBX.html">Updated Valutakrambod, now also with information from NBX</a>
+ </div>
+ <div class="date">
+ 27th February 2021
+ </div>
+ <div class="body">
+ <p>I have neglected the Valutakrambod library for a while, but decided
+this weekend to give it a face lift. I fixed a few minor glitches in
+several of the service drivers, where the API had changed since I last
+looked at the code. I also added support for fetching the order book
+from the newcomer Norwegian Bitcoin Exchange.</p>
+
+<p>I also decided to migrate the project from github to gitlab in the
+process. If you want a python library for talking to various currency
+exchanges, check out
+<a href="https://gitlab.com/petterreinholdtsen/valutakrambod">code for
+valutakrambod</a>.</p>
+
+<p>This is what the output from '<tt>bin/btc-rates-curses -c</tt>'
+looked like a few minutes ago:</p>
+
+<p><blockquote><pre>
+ Name Pair Bid Ask Spread Ftcd Age Freq
+ Bitfinex BTCEUR 39229.0000 39246.0000 0.0% 44 44 nan
+ Bitmynt BTCEUR 39071.0000 41048.9000 4.8% 43 74 nan
+ Bitpay BTCEUR 39326.7000 nan nan% 39 nan nan
+ Bitstamp BTCEUR 39398.7900 39417.3200 0.0% 0 0 1
+ Bl3p BTCEUR 39158.7800 39581.9000 1.1% 0 nan 3
+ Coinbase BTCEUR 39197.3100 39621.9300 1.1% 38 nan nan
+ Kraken+BTCEUR 39432.9000 39433.0000 0.0% 0 0 0
+ Paymium BTCEUR 39437.2100 39499.9300 0.2% 0 2264 nan
+ Bitmynt BTCNOK 409750.9600 420516.8500 2.6% 43 74 nan
+ Bitpay BTCNOK 410332.4000 nan nan% 39 nan nan
+ Coinbase BTCNOK 408675.7300 412813.7900 1.0% 38 nan nan
+ MiraiEx BTCNOK 412174.1800 418396.1500 1.5% 34 nan nan
+ NBX BTCNOK 405835.9000 408921.4300 0.8% 33 nan nan
+ Bitfinex BTCUSD 47341.0000 47355.0000 0.0% 44 53 nan
+ Bitpay BTCUSD 47388.5100 nan nan% 39 nan nan
+ Coinbase BTCUSD 47153.6500 47651.3700 1.0% 37 nan nan
+ Gemini BTCUSD 47416.0900 47439.0500 0.0% 36 336 nan
+ Hitbtc BTCUSD 47429.9900 47386.7400 -0.1% 0 0 0
+ Kraken+BTCUSD 47401.7000 47401.8000 0.0% 0 0 0
+ Exchangerates EURNOK 10.4012 10.4012 0.0% 38 76236 nan
+ Norgesbank EURNOK 10.4012 10.4012 0.0% 31 76236 nan
+ Bitstamp EURUSD 1.2030 1.2045 0.1% 2 2 1
+ Exchangerates EURUSD 1.2121 1.2121 0.0% 38 76236 nan
+ Norgesbank USDNOK 8.5811 8.5811 0.0% 31 76236 nan
+</pre></blockquote></p>
+
+<p>Yes, I notice the negative spread on Hitbtc. Either I fail to
+understand their Websocket API or they are sending bogus data. I've
+seen the same with Kraken, and suspect there is something wrong with
+the data they send.</p>
+
+<p>As usual, if you use Bitcoin and want to show your support of my
+activities, please send Bitcoin donations to my address
+<b><a href="bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b</a></b>.</p>
+
+ </div>
+ <div class="tags">
+
+
+ Tags: <a href="https://people.skolelinux.org/pere/blog/tags/bitcoin">bitcoin</a>, <a href="https://people.skolelinux.org/pere/blog/tags/english">english</a>.
+
+
+ </div>
+ </div>
+ <div class="padding"></div>
+
+ <div class="entry">
+ <div class="title">
+ <a href="https://people.skolelinux.org/pere/blog/Websocket_from_Kraken_in_Valutakrambod.html">Websocket from Kraken in Valutakrambod</a>
+ </div>
+ <div class="date">
+ 1st February 2019
+ </div>
+ <div class="body">
+ <p>Yesterday, the Kraken virtual currency exchange announced
+<a href="https://blog.kraken.com/post/2019/websockets-public-api-launching-soon/">their
+Websocket service</a>, providing a stream of exchange updates to its
+clients. Getting updated rates quickly is a good idea, so I used
+their <a href="https://www.kraken.com/en-us/help/websocket-api">API
+documentation</a> and added Websocket support to the Kraken service in
+Valutakrambod today. The python library can now get updates
+from Kraken several times per second, instead of every time the
+information is polled from the REST API.</p>
+
+<p>If this sound interesting to you, the code for valutakrambod is
+available from
+<a href="http://github.com/petterreinholdtsen/valutakrambod">github</a>.
+Here is example output from the example client displaying rates in a
+curses view:</p>
+
+<p><blockquote><pre>
+ Name Pair Bid Ask Spr Ftcd Age
+ BitcoinsNorway BTCEUR 2959.2800 3021.0500 2.0% 36 nan nan
+ Bitfinex BTCEUR 3087.9000 3088.0000 0.0% 36 37 nan
+ Bitmynt BTCEUR 3001.8700 3135.4600 4.3% 36 52 nan
+ Bitpay BTCEUR 3003.8659 nan nan% 35 nan nan
+ Bitstamp BTCEUR 3008.0000 3010.2300 0.1% 0 1 1
+ Bl3p BTCEUR 3000.6700 3010.9300 0.3% 1 nan nan
+ Coinbase BTCEUR 2992.1800 3023.2500 1.0% 34 nan nan
+ Kraken+BTCEUR 3005.7000 3006.6000 0.0% 0 1 0
+ Paymium BTCEUR 2940.0100 2993.4400 1.8% 0 2688 nan
+ BitcoinsNorway BTCNOK 29000.0000 29360.7400 1.2% 36 nan nan
+ Bitmynt BTCNOK 29115.6400 29720.7500 2.0% 36 52 nan
+ Bitpay BTCNOK 29029.2512 nan nan% 36 nan nan
+ Coinbase BTCNOK 28927.6000 29218.5900 1.0% 35 nan nan
+ MiraiEx BTCNOK 29097.7000 29741.4200 2.2% 36 nan nan
+ BitcoinsNorway BTCUSD 3385.4200 3456.0900 2.0% 36 nan nan
+ Bitfinex BTCUSD 3538.5000 3538.6000 0.0% 36 45 nan
+ Bitpay BTCUSD 3443.4600 nan nan% 34 nan nan
+ Bitstamp BTCUSD 3443.0100 3445.0500 0.1% 0 2 1
+ Coinbase BTCUSD 3428.1600 3462.6300 1.0% 33 nan nan
+ Gemini BTCUSD 3445.8800 3445.8900 0.0% 36 326 nan
+ Hitbtc BTCUSD 3473.4700 3473.0700 -0.0% 0 0 0
+ Kraken+BTCUSD 3444.4000 3445.6000 0.0% 0 1 0
+ Exchangerates EURNOK 9.6685 9.6685 0.0% 36 22226 nan
+ Norgesbank EURNOK 9.6685 9.6685 0.0% 36 22226 nan
+ Bitstamp EURUSD 1.1440 1.1462 0.2% 0 1 2
+ Exchangerates EURUSD 1.1471 1.1471 0.0% 36 22226 nan
+ BitcoinsNorway LTCEUR 1.0009 22.6538 95.6% 35 nan nan
+ BitcoinsNorway LTCNOK 259.0900 264.9300 2.2% 35 nan nan
+ BitcoinsNorway LTCUSD 0.0000 29.0000 100.0% 35 nan nan
+ Norgesbank USDNOK 8.4286 8.4286 0.0% 36 22226 nan
+</pre></blockquote></p>
+
+<p>Yes, I notice the strange negative spread on Hitbtc. I've seen the
+same on Kraken. Another strange observation is that Kraken some times
+announce trade orders a fraction of a second in the future. I really
+wonder what is going on there.</p>
+
+<p>As usual, if you use Bitcoin and want to show your support of my
+activities, please send Bitcoin donations to my address
+<b><a href="bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b</a></b>.</p>
+
+ </div>
+ <div class="tags">
+
+
+ Tags: <a href="https://people.skolelinux.org/pere/blog/tags/bitcoin">bitcoin</a>, <a href="https://people.skolelinux.org/pere/blog/tags/english">english</a>.
+
+
+ </div>
+ </div>
+ <div class="padding"></div>
+
+ <div class="entry">
+ <div class="title">
+ <a href="https://people.skolelinux.org/pere/blog/Valutakrambod___A_python_and_bitcoin_love_story.html">Valutakrambod - A python and bitcoin love story</a>
+ </div>
+ <div class="date">
+ 29th September 2018
+ </div>
+ <div class="body">
+ <p>It would come as no surprise to anyone that I am interested in
+bitcoins and virtual currencies. I've been keeping an eye on virtual
+currencies for many years, and it is part of the reason a few months
+ago, I started writing a python library for collecting currency
+exchange rates and trade on virtual currency exchanges. I decided to
+name the end result valutakrambod, which perhaps can be translated to
+small currency shop.</p>
+
+<p>The library uses the tornado python library to handle HTTP and
+websocket connections, and provide a asynchronous system for
+connecting to and tracking several services. The code is available
+from
+<a href="http://github.com/petterreinholdtsen/valutakrambod">github</a>.</p>
+
+</p>There are two example clients of the library. One is very simple and
+list every updated buy/sell price received from the various services.
+This code is started by running bin/btc-rates and call the client code
+in valutakrambod/client.py. The simple client look like this:</p>
+
+<p><blockquote><pre>
+import functools
+import tornado.ioloop
+import valutakrambod
+class SimpleClient(object):
+ def __init__(self):
+ self.services = []
+ self.streams = []
+ pass
+ def newdata(self, service, pair, changed):
+ print("%-15s %s-%s: %8.3f %8.3f" % (
+ service.servicename(),
+ pair[0],
+ pair[1],
+ service.rates[pair]['ask'],
+ service.rates[pair]['bid'])
+ )
+ async def refresh(self, service):
+ await service.fetchRates(service.wantedpairs)
+ def run(self):
+ self.ioloop = tornado.ioloop.IOLoop.current()
+ self.services = valutakrambod.service.knownServices()
+ for e in self.services:
+ service = e()
+ service.subscribe(self.newdata)
+ stream = service.websocket()
+ if stream:
+ self.streams.append(stream)
+ else:
+ # Fetch information from non-streaming services immediately
+ self.ioloop.call_later(len(self.services),
+ functools.partial(self.refresh, service))
+ # as well as regularly
+ service.periodicUpdate(60)
+ for stream in self.streams:
+ stream.connect()
+ try:
+ self.ioloop.start()
+ except KeyboardInterrupt:
+ print("Interrupted by keyboard, closing all connections.")
+ pass
+ for stream in self.streams:
+ stream.close()
+</pre></blockquote></p>
+
+<p>The library client loops over all known "public" services,
+initialises it, subscribes to any updates from the service, checks and
+activates websocket streaming if the service provide it, and if no
+streaming is supported, fetches information from the service and sets
+up a periodic update every 60 seconds. The output from this client
+can look like this:</p>
+
+<p><blockquote><pre>
+Bl3p BTC-EUR: 5687.110 5653.690
+Bl3p BTC-EUR: 5687.110 5653.690
+Bl3p BTC-EUR: 5687.110 5653.690
+Hitbtc BTC-USD: 6594.560 6593.690
+Hitbtc BTC-USD: 6594.560 6593.690
+Bl3p BTC-EUR: 5687.110 5653.690
+Hitbtc BTC-USD: 6594.570 6593.690
+Bitstamp EUR-USD: 1.159 1.154
+Hitbtc BTC-USD: 6594.570 6593.690
+Hitbtc BTC-USD: 6594.580 6593.690
+Hitbtc BTC-USD: 6594.580 6593.690
+Hitbtc BTC-USD: 6594.580 6593.690
+Bl3p BTC-EUR: 5687.110 5653.690
+Paymium BTC-EUR: 5680.000 5620.240
+</pre></blockquote></p>
+
+<p>The exchange order book is tracked in addition to the best buy/sell
+price, for those that need to know the details.</p>
+
+<p>The other example client is focusing on providing a curses view
+with updated buy/sell prices as soon as they are received from the
+services. This code is located in bin/btc-rates-curses and activated
+by using the '-c' argument. Without the argument the "curses" output
+is printed without using curses, which is useful for debugging. The
+curses view look like this:</p>
+
+<p><blockquote><pre>
+ Name Pair Bid Ask Spr Ftcd Age
+ BitcoinsNorway BTCEUR 5591.8400 5711.0800 2.1% 16 nan 60
+ Bitfinex BTCEUR 5671.0000 5671.2000 0.0% 16 22 59
+ Bitmynt BTCEUR 5580.8000 5807.5200 3.9% 16 41 60
+ Bitpay BTCEUR 5663.2700 nan nan% 15 nan 60
+ Bitstamp BTCEUR 5664.8400 5676.5300 0.2% 0 1 1
+ Bl3p BTCEUR 5653.6900 5684.9400 0.5% 0 nan 19
+ Coinbase BTCEUR 5600.8200 5714.9000 2.0% 15 nan nan
+ Kraken BTCEUR 5670.1000 5670.2000 0.0% 14 17 60
+ Paymium BTCEUR 5620.0600 5680.0000 1.1% 1 7515 nan
+ BitcoinsNorway BTCNOK 52898.9700 54034.6100 2.1% 16 nan 60
+ Bitmynt BTCNOK 52960.3200 54031.1900 2.0% 16 41 60
+ Bitpay BTCNOK 53477.7833 nan nan% 16 nan 60
+ Coinbase BTCNOK 52990.3500 54063.0600 2.0% 15 nan nan
+ MiraiEx BTCNOK 52856.5300 54100.6000 2.3% 16 nan nan
+ BitcoinsNorway BTCUSD 6495.5300 6631.5400 2.1% 16 nan 60
+ Bitfinex BTCUSD 6590.6000 6590.7000 0.0% 16 23 57
+ Bitpay BTCUSD 6564.1300 nan nan% 15 nan 60
+ Bitstamp BTCUSD 6561.1400 6565.6200 0.1% 0 2 1
+ Coinbase BTCUSD 6504.0600 6635.9700 2.0% 14 nan 117
+ Gemini BTCUSD 6567.1300 6573.0700 0.1% 16 89 nan
+ Hitbtc+BTCUSD 6592.6200 6594.2100 0.0% 0 0 0
+ Kraken BTCUSD 6565.2000 6570.9000 0.1% 15 17 58
+ Exchangerates EURNOK 9.4665 9.4665 0.0% 16 107789 nan
+ Norgesbank EURNOK 9.4665 9.4665 0.0% 16 107789 nan
+ Bitstamp EURUSD 1.1537 1.1593 0.5% 4 5 1
+ Exchangerates EURUSD 1.1576 1.1576 0.0% 16 107789 nan
+ BitcoinsNorway LTCEUR 1.0000 49.0000 98.0% 16 nan nan
+ BitcoinsNorway LTCNOK 492.4800 503.7500 2.2% 16 nan 60
+ BitcoinsNorway LTCUSD 1.0221 49.0000 97.9% 15 nan nan
+ Norgesbank USDNOK 8.1777 8.1777 0.0% 16 107789 nan
+</pre></blockquote></p>
+
+<p>The code for this client is too complex for a simple blog post, so
+you will have to check out the git repository to figure out how it
+work. What I can tell is how the three last numbers on each line
+should be interpreted. The first is how many seconds ago information
+was received from the service. The second is how long ago, according
+to the service, the provided information was updated. The last is an
+estimate on how often the buy/sell values change.</p>
+
+<p>If you find this library useful, or would like to improve it, I
+would love to hear from you. Note that for some of the services I've
+implemented a trading API. It might be the topic of a future blog
+post.</p>
+
+<p>As usual, if you use Bitcoin and want to show your support of my
+activities, please send Bitcoin donations to my address
+<b><a href="bitcoin:15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b">15oWEoG9dUPovwmUL9KWAnYRtNJEkP1u1b</a></b>.</p>
+
+ </div>
+ <div class="tags">
+
+
+ Tags: <a href="https://people.skolelinux.org/pere/blog/tags/bitcoin">bitcoin</a>, <a href="https://people.skolelinux.org/pere/blog/tags/english">english</a>.
+
+
+ </div>
+ </div>
+ <div class="padding"></div>
+
+ <div class="entry">
+ <div class="title">
+ <a href="https://people.skolelinux.org/pere/blog/EU_domstolen_konkluderer_motsatt_av_Skatteetaten_n_r_det_gjelder_Bitcoin.html">EU-domstolen konkluderer motsatt av Skatteetaten når det gjelder Bitcoin</a>