def connect_bitex(self): ws = BitExThreadedClient('wss://%s:%s/trade' % (self.config.om_host, self.config.om_port)) ws.signal_recv.connect(self.on_message) ws.connect() ws.login(self.config.om_user, self.config.om_pwd) return ws
def create_websocket(self): self.ws = BitExThreadedClient(self.blinktrade_ws_url) self.ws.signal_connection_open.connect(self.on_ws_open) self.ws.signal_connection_closed.connect(self.on_ws_closed) self.ws.signal_heartbeat.connect(self.on_blinktrade_heartbeat) self.ws.signal_logged.connect(self.on_blinktrade_connected) self.ws.signal_balance.connect(self.on_blinktrade_balance) self.ws.signal_execution_report.connect( self.on_blinktrade_execution_report) self.ws.signal_send.connect(self.on_blinktrade_send) self.ws.signal_recv.connect(self.on_blinktrade_recv)
def __init__(self, bitex_username, bitex_password, bitex_ws_url): self.ws = BitExThreadedClient(bitex_ws_url) self.bitex_username = bitex_username self.bitex_password = bitex_password self.usd_balance = 0 self.btc_balance = 0 self.bitex_broker = None self.bitex_profile = None self.last_bid = None self.last_ask = None self.best_bid = [] self.best_ask = []
def main(): while True: try: ws = BitExThreadedClient('wss://test.bitex.com.br:8449/trade') def on_login(sender, msg): ws.sendMsg({'MsgType': 'S0', 'EmailReqID': '0'}) def on_message(sender, msg): if msg['MsgType'] == 'C': try: sender = u'BitEx Suporte <*****@*****.**>' send_email(sender, msg['To'], msg['Subject'], msg['Body']) except Exception as ex: print "Error: unable to send email to " + str( msg['To']) + ' - ' + str(ex) else: print 'received ', msg print '' ws.signal_logged.connect(on_login) ws.signal_recv.connect(on_message) ws.connect() # TODO: get the user and password from a configuration file ws.login('mailer', 'abc123$%') ws.run_forever() except KeyboardInterrupt: print 'Exiting' ws.close() break except Exception, e: print 'Error ', e print 'reconnecting in 1 sec' time.sleep(1)
def main(): candidates = ['verification.ini', 'blockscore.ini'] if len(sys.argv) > 1: candidates.append(sys.argv[1]) config = ConfigParser.SafeConfigParser({ 'websocket_url': 'wss://127.0.0.1/trade/', 'username': '', 'password': '', 'api_key': '', }) config.read(candidates) websocket_url = config.get('blockscore', 'websocket_url') username = config.get('blockscore', 'username') password = config.get('blockscore', 'password') api_key = config.get('blockscore', 'api_key') blockscore_client = blockscore.Client({'api_key': api_key}) def on_verify_customer(sender, msg): print msg verification = blockscore_client.verification.create( date_of_birth=msg.get('VerificationData')['date_of_birth'], identification={'ssn': msg.get('VerificationData')['ssn']}, name={ 'first': msg.get('VerificationData')['name']['first'], 'middle': msg.get('VerificationData')['name']['middle'], 'last': msg.get('VerificationData')['name']['last'], }, address={ 'street1': msg.get('VerificationData')['address']['street1'], 'street2': msg.get('VerificationData')['address']['street2'], 'city': msg.get('VerificationData')['address']['city'], 'state': msg.get('VerificationData')['address']['state'], 'postal_code': msg.get('VerificationData')['address']['postal_code'], 'country_code': msg.get('VerificationData')['address']['country_code'], }) verification = verification.body print verification ws = BitExThreadedClient(websocket_url) ws.signal_verify_customer_update.connect(on_verify_customer) ws.connect() ws.login(username, password) while True: try: sleep(30) if ws.is_connected: ws.testRequest() else: try: ws.close() except HandshakeError, e: del ws ws = BitExThreadedClient(websocket_url) ws.signal_verify_customer_update.connect( on_verify_customer) ws.connect() ws.login(username, password) except KeyboardInterrupt: ws.close() break