def __init__(self, *args, **kwargs): self.key = "de504dc5763aeef9ff52" self.channels = {} self.messages = { "live_trades": ["trade"], "order_book": ["data"], "diff_order_book": ["data"], "live_orders": ["order_created", "order_changed", "order_deleted"] } for channel in self.messages.keys(): self.channels[channel] = [] for pair in [ "btceur", "btcusd", "eurusd", "ltcusd", "ltceur", "ltcbtc", "xrpusd", "xrpeur", "xrpbtc", "ethusd", "etheur", "ethbtc" ]: self.channels[channel + "_" + pair] = [] self.orderbook = { "btc": { "eur": None, "usd": None }, "eur": { "usd": None }, "ltc": { "eur": None, "usd": None, "btc": None }, "xrp": { "eur": None, "usd": None, "btc": None }, "eth": { "eur": None, "usd": None, "btc": None } } self.lastprice = self.orderbook self.openorders = self.orderbook for base in self.openorders.keys(): for quote in self.openorders[base].keys(): self.openorders[base][quote] = {"price": {}, "id": {}} self.pusher = pusherclient.Pusher(self.key) self.pusher.connect()
def __init__(self, *args, **kwargs): self.key = 'de504dc5763aeef9ff52' # Bitstamp pusher key. self.channels = {} self.messages = {'live_trades': ['trade'], 'order_book': ['data'], 'diff_order_book': ['data'], 'live_orders': ['order_created', 'order_changed', 'order_deleted']} self.lock = Lock() for channel in self.messages.keys(): self.channels[channel] = [] for pair in PAIRS: self.channels[channel + '_' + pair] = [] self.lastprice_btcusd = generate_response_template() self.lastprice_btceur = generate_response_template() self.lastprice_eurusd = generate_response_template() self.lastprice_xrpusd = generate_response_template() self.lastprice_xrpeur = generate_response_template() self.lastprice_xrpbtc = generate_response_template() self.lastprice_ltcusd = generate_response_template() self.lastprice_ltceur = generate_response_template() self.lastprice_ltcbtc = generate_response_template() self.lastprice_ethusd = generate_response_template() self.lastprice_etheur = generate_response_template() self.lastprice_ethbtc = generate_response_template() self.lastprice_bchusd = generate_response_template() self.lastprice_bcheur = generate_response_template() self.lastprice_bchbtc = generate_response_template() self.orderbook_btceur = generate_response_template() self.orderbook_btcusd = generate_response_template() self.openorders = generate_response_template() for base in self.openorders.keys(): for quote in self.openorders[base].keys(): self.openorders[base][quote] = {'price': {}, 'id': {}} self.pusher = pusherclient.Pusher(self.key) self.pusher.connect()
def channel_callback(data): print("Channel Callback: %s" % data) def connect_handler(data): channel = pusher.subscribe("presence-channel") channel.bind('my_event', channel_callback) if __name__ == '__main__': if len(sys.argv) != 4: print_usage(sys.argv[0]) sys.exit(1) appkey = sys.argv[1] secret = sys.argv[2] userid = sys.argv[3] pusher = pusherclientb.Pusher(appkey, secret=secret, user_data={'user_id': userid}) pusher.connection.bind('pusher:connection_established', connect_handler) pusher.connect() while True: time.sleep(1)
def print_usage(filename): print("Usage: python %s <appkey>" % filename) def channel_callback(data): print("Channel Callback: %s" % data) def connect_handler(data): channel = pusher.subscribe("test_channel") channel.bind('my_event', channel_callback) if __name__ == '__main__': if len(sys.argv) != 2: print_usage(sys.argv[0]) sys.exit(1) appkey = sys.argv[1] pusher = pusherclientb.Pusher(appkey) pusher.connection.bind('pusher:connection_established', connect_handler) pusher.connect() while True: time.sleep(1)
def print_usage(filename): print("Usage: python %s <appkey> <secret>" % filename) def channel_callback(data): print("Channel Callback: %s" % data) def connect_handler(data): channel = pusher.subscribe("private-channel") channel.bind('my_event', channel_callback) if __name__ == '__main__': if len(sys.argv) != 3: print_usage(sys.argv[0]) sys.exit(1) appkey = sys.argv[1] secret = sys.argv[2] pusher = pusherclientb.Pusher(appkey, secret=secret) pusher.connection.bind('pusher:connection_established', connect_handler) pusher.connect() while True: time.sleep(1)