Bitcoin Forum

Other => Beginners & Help => Topic started by: rier on August 08, 2011, 12:03:05 PM



Title: How do I store ticker data?
Post by: rier on August 08, 2011, 12:03:05 PM
I'm writing a bot, I was thinking about querying Mt. Gox's api every 2 seconds and store the ticker data in a MySQL database.

Is this the best way to do this? I need to run some algorithms to determine enter an exit signals for the automated bot.

Or should I use the websocket feed?


Title: Re: How do I store ticker data?
Post by: cubemonkey on August 08, 2011, 05:29:41 PM
You could try:

Code:
nohup  nc bitcoincharts.com 27007 |awk '/mtgoxUSD/ {gsub(/,/,"");p = $4+0;v = $6+0;print $2" "p" "v}' >>/tmp/stream.out &

Output in stream.out will look like:

Code:
1312824328 7.67 0.64291525
1312824328 7.667 3.5
1312824328 7.66051 7
1312824328 7.66 41.65206919
1312824328 7.65766 10.03
1312824329 7.65755 0.08
1312824329 7.65 20
1312824329 7.65 5
1312824329 7.65 2
1312824329 7.65 16.3761626

(trade time in epoch, value in USD, and volume)

Then something like (pardon my rusty mysql, but just showing the general idea... )

Code:
while true
do
   # take a snapshot
   tail -1 stream.out > /tmp/stream.out.tmp
   TIME=$(cat /tmp/stream.out.tmp |awk '{print $1}')
   TRADE=$(cat /tmp/stream.out.tmp |awk '{print $2}')
   QTY=$(cat /tmp/stream.out.tmp |awk '{print $3}'  
   mysqlupdate=`(mysql -u user -p password -e "INSERT INTO blah.blah VALUES ($TIME,$TRADE,$QTY)") 2>&1`
   sleep 2
done










Title: Re: How do I store ticker data?
Post by: kseistrup on August 08, 2011, 06:41:43 PM

Or should I use the websocket feed?

You would save both your own and mtgox' resources by using the websocket feed.

Cheers,


Title: Re: How do I store ticker data?
Post by: Cellcote on August 08, 2011, 09:42:42 PM
every 2 seconds

As I recall correctly, MT Gox only allow you to acces their API once per 15 minutes.


Title: Re: How do I store ticker data?
Post by: cubemonkey on August 09, 2011, 02:46:44 AM
every 2 seconds

As I recall correctly, MT Gox only allow you to acces their API once per 15 minutes.

bitcoincharts streams it..  you save the stream to your local machine, then access that every 2 seconds.


Title: Re: How do I store ticker data?
Post by: jboss on August 09, 2011, 04:18:21 AM
The volume on mt gox is small compared to say nyse, you probalby don't even need to query every 2 minutes...

I wrote a small perl backend to show these charts. (I couldn't find a chart site that let me view by date).

http://bitcoin.coprimeinc.com/

I'm still experimenting with it. The perl backend took me about 10 minutes to write - which grabs the trade data off mt gox and dumps it into mysql.

PM me if you want more details.


Title: Re: How do I store ticker data?
Post by: kseistrup on August 09, 2011, 05:41:58 AM

bitcoincharts streams it..  you save the stream to your local machine, then access that every 2 seconds.

The data from bitcoincharts are up to a couple of minutes delayed, whereas those from the Mt Gox websocket stream are generally only a couple of seconds old.  There is no point in using the telnet stream from bitcoincharts unless one wants data from other exchanges than from Mt Gox, and even in that case it'll make more sense to use the websocket stream to obtain data from Mt Gox.

By saying that he wants to poll Mt Gox every 2 seconds, the OP has implicitly said that he wants the data as soon as possible.  The websocket API, by pushing data as soon as they're available, obsoletes expensive polling.

Cheers,