Hi,
I have a comment on
https://bitcointalk.org/index.php?topic=201062.0 (Qt Bitcoin Trader [Open Source secure trading client for Mac/Windows/Linux])
Please, somebody who has privileges, post this to IGHOR, the author of the program below the line. It'd mean lots of help in his development process.
-------------------------------------
Hi IGHOR,
You've mention this in the TODO list:
Next TODO:
5 ) Develop server to collect all ticker and depth data to provide single websocket connection for realtime data updates
But maybe you don't know, that
Bitstamp has a Pusher websocket interface, which is operating smoothly. (Pusher protocol is described here:
http://pusher.com/docs/pusher_protocol)
You need't implement a server, just use the code which is already on their homepage. From their Javascript:
var pusher = new Pusher('de504dc5763aeef9ff52');
var trades_channel = pusher.subscribe('live_trades');
trades_channel.bind('trade', update_index_live_trades);
var order_book_channel = pusher.subscribe('order_book');
order_book_channel.bind('data', update_index_order_book);
//var orders_channel = pusher.subscribe('live_orders');
//orders_channel.bind('order_deleted', add_to_ws_queue);
//orders_channel.bind('order_created', add_to_ws_queue);
//orders_channel.bind('order_changed', add_to_ws_queue);
You just have to subscribe to their Pusher channels with that de504dc5763aeef9ff52 ID, and you get the transaction stream live!
I've downloaded a Python Pusher Client, subscribed to their channels, and got the same feed as seen on their website, all data which is public but undocumented on their API doc page.
Test python code, just to see how easy it is:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import pusherclient #live stream client: https://github.com/ekulyk/PythonPusherClient
import logging
import time
def trade_callback(data): #some callbacs to do something when the event occours
print "trade", data
def order_deleted_callback(data):
print "delete", data
def order_created_callback(data):
print "create", data
def order_changed_callback(data):
print "changes", data
def order_book_callback(data):
print "book", data
def connect_handler(data): #this gets called when the Pusher connection is established
trades_channel = pusher.subscribe("live_trades")
trades_channel.bind('trade', trade_callback)
order_book_channel = pusher.subscribe('order_book');
order_book_channel.bind('data', order_book_callback)
orders_channel = pusher.subscribe("live_orders")
orders_channel.bind('order_deleted', order_deleted_callback)
orders_channel.bind('order_created', order_created_callback)
orders_channel.bind('order_changed', order_changed_callback)
if __name__ == '__main__': #this is the main() function
pusher = pusherclient.Pusher("de504dc5763aeef9ff52")
pusher.connection.logger.setLevel(logging.WARNING) #no need for this line if you want everything printed out by the logger
pusher.connection.bind('pusher:connection_established', connect_handler)
pusher.connect()
while True: #run until ctrl+c interrupts
time.sleep(1)
And that's all! Very easy in python, I think it can be done also in you program quickly
It'd be a very very big improvement
Sample outputs of the previous program, all is well formed JSON that is in the data variabes printed out:
create {"price": "725.11", "amount": "48.65000000", "datetime": "1388100046", "id": 11927177, "order_type": 0}
delete {"price": "751.00", "amount": "0.49533954", "datetime": "1388099770", "id": 11926902, "order_type": 0}
delete {"price": "736.06", "amount": "6.95000000", "datetime": "1388100034", "id": 11927172, "order_type": 0}
delete {"price": "736.06", "amount": "48.65000000", "datetime": "1388100018", "id": 11927153, "order_type": 0}
create {"price": "736.07", "amount": "20.85000000", "datetime": "1388100053", "id": 11927178, "order_type": 0}
delete {"price": "774.99", "amount": "5.16121000", "datetime": "1388099872", "id": 11926993, "order_type": 1}
create {"price": "736.76", "amount": "27.67767160", "datetime": "1388100053", "id": 11927179, "order_type": 0}
book {"bids": [["758.08", "0.09000000"], ["757.71", "3.13735421"], ["757.70", "6.23629196"], ["757.46", "0.04700000
"], ["756.98", "0.00138704"], ["756.90", "1.00000000"], ["756.47", "0.05000000"]], "asks": [["760.78", "0.04800000"
], ["761.00", "1.47339631"], ["761.65", "0.14020557"], ["761.66", "1.67295194"], ["761.81", "0.04900000"], ["762.00
", "1.82159420"], ["762.85", "0.04900000"]]}
create {"price": "751.80", "amount": "6.95000000", "datetime": "1388100054", "id": 11927180, "order_type": 0}
create {"price": "690.00", "amount": "2.35905797", "datetime": "1388100055", "id": 11927181, "order_type": 0}
create {"price": "758.08", "amount": "0.04143494", "datetime": "1388100056", "id": 11927182, "order_type": 1}
changes {"price": "758.08", "amount": "0.04856506", "datetime": "1388100018", "id": 11927152, "order_type": 0}
delete {"price": "758.08", "amount": "0.00000000", "datetime": "1388100056", "id": 11927182, "order_type": 1}
trade {"price": 758.08000000000004, "amount": 0.041434940000000003, "id": 2760844}
create {"price": "771.65", "amount": "5.16121000", "datetime": "1388100058", "id": 11927183, "order_type": 1}
create {"price": "753.00", "amount": "0.49402390", "datetime": "1388100059", "id": 11927184, "order_type": 0}
You can even miss out the create/delete/change data, because the order_book contains the top 5 asks and bids, like on their website.
I hope this live trade watching feature gets implemented very guickly (I need it also:P), so I wish good luck for you and Merry Christmas of course