Script to show latest trades across all markets

Hi all. I made a quick script to show the latest trades. Figured I’d share. It works on linux, with php installed.

Here is sample output:

Every 2.0s: ./print_trades_times.php | head                                                       Sat Aug  6 02:10:15 2016

Sat, 06 Aug 2016 01:57:39 +0000 : GBP 236.16@472.31     --> 0.50000000 BTC
Fri, 05 Aug 2016 22:41:40 +0000 : USD 69.75@581.28      --> 0.12000000 BTC
Fri, 05 Aug 2016 11:22:31 +0000 : EUR 207.49@518.73     --> 0.40000000 BTC
Fri, 05 Aug 2016 10:39:49 +0000 : EUR 259.93@519.86     --> 0.50000000 BTC
Fri, 05 Aug 2016 10:33:28 +0000 : EUR 51.98@519.75      --> 0.10000000 BTC
Fri, 05 Aug 2016 09:42:25 +0000 : XMR 64.74@323.72      --> 0.20000000 BTC
Fri, 05 Aug 2016 08:55:20 +0000 : EUR 51.89@518.90      --> 0.10000000 BTC
Fri, 05 Aug 2016 07:40:09 +0000 : EUR 104.19@520.96     --> 0.20000000 BTC
Thu, 04 Aug 2016 22:40:15 +0000 : EUR 404.06@538.75     --> 0.75000000 BTC
Thu, 04 Aug 2016 17:43:28 +0000 : ETC 24.99@227.22      --> 0.11000000 BTC

Actually, the script by itself prints out all trades, but I run it in watch like so, and it refreshes every 2 seconds:

watch "./print_trades_times.php | head"

Edit: For this to work you need to start the bitsquare app with --dumpStatistics true

Here is the script, just save as print_trade_times.php.

#!/usr/bin/env php
<?php
$file = $_SERVER['HOME'] . '/.local/share/Bitsquare/mainnet/db/trade_statistics.json';
$json = json_decode( file_get_contents( $file ), true ) ;

foreach( $json as $t ) {
        echo sprintf( "%s : %s %s@%s\t--> %s BTC \n",
                        gmdate('r', $t['tradeDate']/1000),
                        $t['currency'],
                        number_format( ($t['tradePrice'] * $t['tradeAmount']) / (100000000*10000), 2 ),
                        number_format( $t['tradePrice'] / 10000, 2 ),
                        number_format( $t['tradeAmount'] / 100000000, 8 ) );
}
2 Likes

Cool! Thanks for sharing!