def __init__(self, broker_id, username, password, websocket_url, bid_fee=0., ask_fee=0., api_key=None, api_secret=None, dest_market='BTCUSD'): self.api_key = api_key self.api_secret = api_secret self.bid_fee = bid_fee self.ask_fee = ask_fee self.broker_id = broker_id self.username = username self.password = password self.websocket_url = websocket_url self.pusher = pusherclient.Pusher(key='de504dc5763aeef9ff52', log_level=logging.ERROR) self.pusher.connection.bind('pusher:connection_established', self.on_bitstamp_connect_handler) self.pusher.connection.bind('pusher:connection_failed', self.on_bitstamp_connect_failed_handler) self.arbitrator = BlinkTradeArbitrator(self.broker_id, self.username, self.password, self.websocket_url, dest_market) self.arbitrator.signal_order.connect(self.on_send_order_to_bitstamp) self.arbitrator.signal_logged.connect(self.on_blinktrade_logged) self.arbitrator.signal_disconnected.connect( self.on_blinktrade_discconnected) self.arbitrator.signal_connected.connect(self.on_blinktrade_connected)
def main(): candidates = ['arbitrage.ini', 'mb.ini' ] if len(sys.argv) > 1: candidates.append(sys.argv[1]) config = ConfigParser.SafeConfigParser({ 'websocket_url': 'wss://127.0.0.1/trade/', 'username': '', 'password': '', 'buy_fee': 0, 'sell_fee': 0, 'api_key': 'KEY', 'api_secret': 'SECRET' }) config.read( candidates ) websocket_url = config.get('mb', 'websocket_url') username = config.get('mb', 'username') password = config.get('mb', 'password') buy_fee = int(config.get('mb', 'buy_fee')) sell_fee = int(config.get('mb', 'sell_fee')) api_key = config.get('mb', 'api_key') api_secret = config.get('mb', 'api_secret') print 'websocket_url:', websocket_url print 'username:'******'buy_fee:', buy_fee print 'sell_fee:', sell_fee arbitrator = BlinkTradeArbitrator(username,password,websocket_url, 'BTCUSD' ) #'BTCBRL') arbitrator.connect() arbitrator.signal_order.connect(send_order_to_MB) while True: try: sleep(5) if arbitrator.is_connected(): arbitrator.send_testRequest() else: try: arbitrator.reconnect() except HandshakeError,e: continue try: raw_data = urllib2.urlopen('https://www.mercadobitcoin.com.br/api/orderbook/').read() except Exception: print 'ERROR RETRIEVING ORDER BOOK' continue bids_asks = [] try: bids_asks = json.loads(raw_data) except Exception : pass if bids_asks: ask_list = [ [ int(float(o[0]) * 1e8 * (1. + sell_fee) ) , int(o[1] * 1e8) ] for o in bids_asks['asks'] ] bid_list = [ [ int(float(o[0]) * 1e8 * (1. + buy_fee) ) , int(o[1] * 1e8) ] for o in bids_asks['bids'] ] arbitrator.process_ask_list(ask_list) arbitrator.process_bid_list(bid_list) except urllib2.URLError as e: print datetime.datetime.now(), e
def main(): candidates = ['arbitrage.ini', 'b2u.ini'] if len(sys.argv) > 1: candidates.append(sys.argv[1]) config = ConfigParser.SafeConfigParser({ 'websocket_url': 'wss://127.0.0.1/trade/', 'username': '', 'password': '', 'broker_id': 5, 'buy_fee': 0, 'sell_fee': 0, 'api_key': 'KEY', 'api_secret': 'SECRET' }) config.read(candidates) websocket_url = config.get('b2u', 'websocket_url') username = config.get('b2u', 'username') password = config.get('b2u', 'password') buy_fee = int(config.get('b2u', 'buy_fee')) sell_fee = int(config.get('b2u', 'sell_fee')) api_key = config.get('b2u', 'api_key') api_secret = config.get('b2u', 'api_secret') broker_id = config.getint('b2u', 'broker_id') dest_market = config.get('b2u', 'dest_market') print 'websocket_url:', websocket_url print 'username:'******'buy_fee:', buy_fee print 'sell_fee:', sell_fee arbitrator = BlinkTradeArbitrator(broker_id, username, password, websocket_url, dest_market) arbitrator.connect() #arbitrator.signal_order.connect(send_order_to_b2u) while True: try: sleep(10) if arbitrator.is_connected(): arbitrator.send_testRequest() else: try: arbitrator.reconnect() except HandshakeError, e: continue try: raw_data = urllib2.urlopen( 'https://www.bitcointoyou.com/API/orderbook.aspx').read() except Exception as e: print 'ERROR RETRIEVING ORDER BOOK: ' + str(e) continue bids_asks = [] try: bids_asks = json.loads(raw_data) except Exception: try: bids_asks = json.loads(raw_data.replace( '][', '],[')) # bug with b2u api except Exception: pass pass if bids_asks: ask_list = [[ int(float(fiat) * 1e8 * (1. + sell_fee)), int(float(btc) * 1e8) ] for fiat, btc in bids_asks['asks']] bid_list = [[ int(float(fiat) * 1e8 * (1. - buy_fee)), int(float(btc) * 1e8) ] for fiat, btc in bids_asks['bids']] number_of_asks_to_remove_due_a_weird_bug = 0 for ask_price, ask_size in ask_list: if ask_price < bid_list[0][0]: number_of_asks_to_remove_due_a_weird_bug += 1 else: break if number_of_asks_to_remove_due_a_weird_bug: print datetime.datetime.now( ), 'Those sell orders are weird => ', [ 'BTC {:,.8f}'.format(s / 1e8) + ' @ R$ {:,.2f}'.format(p / 1e8) for p, s in ask_list[:number_of_asks_to_remove_due_a_weird_bug] ] ask_list = ask_list[number_of_asks_to_remove_due_a_weird_bug:] arbitrator.process_ask_list(ask_list) arbitrator.process_bid_list(bid_list) except urllib2.URLError as e: print datetime.datetime.now(), e
def main(): candidates = ['arbitrage.ini', 'itbit.ini'] if len(sys.argv) > 1: candidates.append(sys.argv[1]) config = ConfigParser.SafeConfigParser({ 'websocket_url': 'wss://127.0.0.1/trade/', 'username': '', 'password': '', 'buy_fee': 0, 'sell_fee': 0, 'api_key': 'KEY', 'api_secret': 'SECRET' }) config.read(candidates) websocket_url = config.get('itbit', 'websocket_url') username = config.get('itbit', 'username') password = config.get('itbit', 'password') buy_fee = float(config.get('itbit', 'buy_fee')) sell_fee = float(config.get('itbit', 'sell_fee')) api_key = config.get('itbit', 'api_key') api_secret = config.get('itbit', 'api_secret') broker_id = config.getint('itbit', 'broker_id') dest_market = config.get('itbit', 'dest_market') arbitrator = BlinkTradeArbitrator(broker_id, username, password, websocket_url, dest_market) arbitrator.connect() arbitrator.signal_order.connect(send_order) while True: try: sleep(1) if arbitrator.is_connected(): arbitrator.send_testRequest() else: try: arbitrator.reconnect() except HandshakeError, e: continue try: raw_data = urllib2.urlopen( 'https://www.itbit.com/api/v2/markets/XBTUSD/orders').read( ) except Exception: print 'ERROR RETRIEVING ORDER BOOK' continue bids_asks = [] try: bids_asks = json.loads(raw_data) except Exception: pass if bids_asks: bid_list = [[ int(float(o[0]) * 1e8 * (1. + buy_fee)), int(float(o[1]) * 1e8) ] for o in bids_asks['bids']] ask_list = [[ int(float(o[0]) * 1e8 * (1. + sell_fee)), int(float(o[1]) * 1e8) ] for o in bids_asks['asks']] arbitrator.process_ask_list(ask_list) arbitrator.process_bid_list(bid_list) except urllib2.URLError as e: print datetime.datetime.now(), e
def main(): candidates = ['arbitrage.ini', 'basebit.ini' ] if len(sys.argv) > 1: candidates.append(sys.argv[1]) config = ConfigParser.SafeConfigParser({ 'websocket_url': 'wss://127.0.0.1/trade/', 'username': '', 'password': '', 'buy_fee': 0, 'sell_fee': 0, 'api_key': 'KEY', 'api_secret': 'SECRET', 'subscription_api_key':'api_key' }) config.read( candidates ) websocket_url = config.get('bitinvest', 'websocket_url') username = config.get('bitinvest', 'username') password = config.get('bitinvest', 'password') buy_fee = int(config.get('bitinvest', 'buy_fee')) sell_fee = int(config.get('bitinvest', 'sell_fee')) api_key = config.get('bitinvest', 'api_key') api_secret = config.get('bitinvest', 'api_secret') subscription_api_key = config.get('bitinvest', 'subscription_api_key') broker_id = config.getint('bitinvest', 'broker_id') dest_market = config.get('bitinvest', 'dest_market') arbitrator = BlinkTradeArbitrator(broker_id, username,password,websocket_url, dest_market) arbitrator.connect() arbitrator.signal_order.connect(send_order_to_BINVEST) while True: try: sleep(15) if arbitrator.is_connected(): arbitrator.send_testRequest() else: try: arbitrator.reconnect() except HandshakeError,e: continue try: # something wrong with urllib2 or bitinvest servers. #raw_data = urllib2.urlopen('https://api.bitinvest.com.br/exchange/orderbook?subscription-key=' + subscription_api_key).read() # curl works. I know, this is ugly, but it works api_url = 'https://api.bitinvest.com.br/exchange/orderbook?subscription-key=' + subscription_api_key raw_data = subprocess.check_output( ['curl', api_url ] ) except Exception: print 'ERROR RETRIEVING ORDER BOOK' continue bids_asks = [] try: bids_asks = json.loads(raw_data) except Exception : pass if bids_asks: ask_list = [ [ int(float(o[0]) * 1e8 * (1. + sell_fee) ) , int(o[1] * 1e8) ] for o in bids_asks['asks'] ] bid_list = [ [ int(float(o[0]) * 1e8 * (1. + buy_fee) ) , int(o[1] * 1e8) ] for o in bids_asks['bids'] ] arbitrator.process_ask_list(ask_list) arbitrator.process_bid_list(bid_list) except urllib2.URLError as e: print datetime.datetime.now(), e