Exemple #1
0
    def get_tickers(self):
        logger.info('Ready to fetch tickers tasks....\n' +
                    date_utils.current(Y_M_D_H_M_S))
        exchanges = [
            ccxt.bitfinex2({'userAgent': USER_AGENT}),
            ccxt.bittrex({'userAgent': USER_AGENT}),
            ccxt.poloniex({'userAgent': USER_AGENT}),
            ccxt.hitbtc2({'userAgent': USER_AGENT}),
            ccxt.cryptopia({'userAgent': USER_AGENT}),
            ccxt.livecoin({'userAgent': USER_AGENT}),
            ccxt.kucoin({'userAgent': USER_AGENT}),
            ccxt.okex({'userAgent': USER_AGENT}),
            ccxt.coinexchange({'userAgent': USER_AGENT}),
            ccxt.binance({'userAgent': USER_AGENT}),
            ccxt.bithumb({'userAgent': USER_AGENT}),
            ccxt.kraken({'userAgent': USER_AGENT})
        ]
        tasks = []
        for i in range(len(exchanges)):
            task = self.fetch_tickers_task(exchanges[i])
            tasks.append(asyncio.ensure_future(task))

        loop = asyncio.get_event_loop()
        loop.run_until_complete(asyncio.wait(tasks))
        loop.close()
        self.spider_repository.close()
Exemple #2
0
    def background_job(self):

        self.ob_constant = OD_TICK_TIMER
        self.bl_constant = BALANCE_TICK_TIMER
        self.trade_constant = TRADE_TICK_TIMER

        self.stop_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=TICK_TIMER)
        self.orderbook_tick_time = datetime.datetime.now(
        ) + datetime.timedelta(seconds=self.ob_constant)
        self.balance_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=self.bl_constant)
        self.trade_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=self.trade_constant)
        self.info_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=INFO_TIMER)

        self.ccxt_in_queue = self.config['in_queue']
        self.ccxt_out_queue = self.config['out_queue']

        auth = {}
        if 'auth' in self.config.keys():
            auth = self.config['auth']
            self.is_auth = True
            self.name = '[ccxt %s %s*]' % (self.exhange, auth['apiKey'][:4])

        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        if self.exhange == 'hitbtc':
            loop.create_task(self.run_loop(ccxt.hitbtc(auth)))
        elif self.exhange == 'coinmarketcap':
            loop.create_task(self.run_loop(ccxt.coinmarketcap()))
        elif self.exhange == 'binance':
            loop.create_task(self.run_loop(ccxt.binance(auth)))
        elif self.exhange == 'bitmex':
            loop.create_task(self.run_loop(ccxt.bitmex(auth)))
        elif self.exhange == 'huobipro':
            loop.create_task(self.run_loop(ccxt.huobipro()))
        elif self.exhange == 'liqui':
            loop.create_task(self.run_loop(ccxt.liqui(auth)))
        elif self.exhange == 'bitfinex2':
            loop.create_task(self.run_loop(ccxt.bitfinex2(auth)))
        elif self.exhange == 'bitfinex':
            loop.create_task(self.run_loop(ccxt.bitfinex(auth)))
        elif self.exhange == 'okex':
            loop.create_task(self.run_loop(ccxt.okex(auth)))
        elif self.exhange == 'kucoin':
            loop.create_task(self.run_loop(ccxt.kucoin(auth)))
        elif self.exhange == 'bittrex':
            loop.create_task(self.run_loop(ccxt.bittrex(auth)))
        elif self.exhange == 'qryptos':
            loop.create_task(self.run_loop(ccxt.qryptos(auth)))
        elif self.exhange == 'kraken':
            loop.create_task(self.run_loop(ccxt.kraken(auth)))

        loop.run_forever()
async def getbinanceob():
    binex = ccxt.binance()
    outdic = dict()
    exlist = ['LTC/ETH', 'OMG/ETH', 'QTUM/ETH', 'XRP/ETH', 'BCH/ETH', 'NEO/ETH', 'ETH/BTC', 'LTC/BTC',
              'OMG/BTC', 'QTUM/BTC', 'XRP/BTC', 'BCH/BTC', 'NEO/BTC', 'GAS/BTC', 'LTC/BNB', 'NEO/BNB']
    for ex in exlist:
        try:
            outdic[ex] = await binex.fetch_order_book(ex)
        except BaseException as e:
            print("Error in fetching binance order book %s: %s" % (ex, e))

    return outdic
Exemple #4
0
    def test_monitor_full_book_stream(self):
        exchanges = [ccxt.binance(), ccxt.gemini(), ccxt.bitmex()]
        loop = asyncio.get_event_loop()
        t1 = ManageThread(SYMBOL, 'fetchOrderBook', exchanges, 5000, loop=loop)
        t1.daemon = True
        t1.start()

        def pass_test(m):
            if 'bids' in m:
                return True
            return False

        ub = UnifiedOrderBook(SYMBOL, exchanges[0])
        ub.monitor_full_book_stream()
        t1.join()
        self.assertEqual(2 + 2, 4)
Exemple #5
0
 def __init__(self):
     self.liqui = Liqui(settings.LIQUI.API_KEY, settings.LIQUI.API_SECRET)
     self.binance = Client(settings.BINANCE.API_KEY,
                           settings.BINANCE.API_SECRET)
     self.markets = {
         'LIQUI':
         ccxt.liqui({
             'apiKey': settings.LIQUI.API_KEY,
             'secret': settings.LIQUI.API_SECRET
         }),
         'BINANCE':
         ccxt.binance({
             'apiKey': settings.BINANCE.API_KEY,
             'secret': settings.BINANCE.API_SECRET
         })
     }
     self.minimum_order = settings.MINIMUM_AMOUNT_TO_TRADE
Exemple #6
0
    def test_manage_ticker(self):
        exchanges = [ccxt.binance(), ccxt.gemini(), ccxt.bitmex()]
        loop = asyncio.get_event_loop()
        uam = UnifiedAPIManager(SYMBOL, 'fetchTicker', exchanges, 5000)
        loop.run_until_complete(uam.filter_exchanges())

        def pass_test(m):
            if 'high' in m:
                return True
            return False

        t2 = ConsumeThread(SYMBOL.replace('/', '_') + '_ticker', pass_test)
        t2.start()
        loop.run_until_complete(
            uam.manage(stop_at=datetime.datetime.utcnow() +
                       datetime.timedelta(seconds=2)))
        t2.join()
        self.assertEqual(2 + 2, 4)
Exemple #7
0
participants = ['binance', 'bitfinex', 'bittrex', 'huobi']
existance = {}
loggers = {}
for ex in participants:
    existance[ex] = []
    loggers[ex] = setup_logger('%s' % ex, '%s.log' % ex)

fees = {
    'binance': 0.05 / 100,
    'bitfinex': 0.1 / 100,
    'bittrex': 0.25 / 100,
    'huobi': 0.04 / 100
}

exs = {
    'binance': ccxt.binance(),
    'bitfinex': ccxt.bitfinex(),
    'bittrex': ccxt.bittrex(),
    'huobi': ccxt.huobipro()
}

datas = {}
universe = pd.read_excel('binance/backtest_fee0.2&volumefilter.xlsx')
loop = asyncio.get_event_loop()

k = 0.5
target_vol = 0.25
fee = 0.2 / 100
window = 500
min_volume = {'USDT': 5000000, 'BTC': 500, 'ETH': 10000, 'BNB': 500000}
pairs = []
Exemple #8
0
allcoin = ccxt.allcoin({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
anxpro = ccxt.anxpro({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bibox = ccxt.bibox({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
binance = ccxt.binance({
    'enableRateLimit': True,
    'rateLimit': 1000,
    'apiKey': "kHgviPR8ijyNWn0PcltvzWkOqpr3nlDzGp6wY2ZEsQNa1F7k3ePhV0C7oOq8e6Cu",
    'secret': "aqdBURqQxxk29mE31mEMIpW6zI5QsA5PKw1wf8VI7XDGG1WxJrAFWkTwEnMOJQbB",
    #'verbose': True,
})
bit2c = ccxt.bit2c({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bitbay = ccxt.bitbay({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bitcoincoid = ccxt.bitcoincoid({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
Exemple #9
0
import ccxt. async as ccxt
from bot_crawler import BotCrawler
from helper import NoInternetException

if __name__ == '__main__':
    # initialize exchangers instances
    gateways = [
        ccxt.cex(),
        ccxt.poloniex(),
        ccxt.binance(),
        ccxt.kraken(),
        ccxt.bitfinex2(),
        ccxt.okex()
    ]
    # define pairs for analysis
    pairs = ['XRP/BTC', 'XLM/BTC']
    # run the bot
    crawler = BotCrawler(gateways, pairs, 10.3)
    try:
        crawler.run(5)
    except KeyboardInterrupt:
        print('stop.')
    except NoInternetException:
        print('Connect to the Internet to run the program!')
    async def print_complex_arbs_task(self):
        while True:
            self.print_arbs(self.complex_arbs())
            await asyncio.sleep(1)

    async def populate_task(self, exchange):
        while True:
            try:
                await self.exchange_rates.populate(
                    exchange, blacklisted=self.blacklisted)
            except (TimeoutError, RequestTimeout, ExchangeError) as e:
                logging.error(e)
            await asyncio.sleep(5)


if __name__ == "__main__":
    EXCHANGES = {
        ccxt.bittrex({'enableRateLimit': True}),
        ccxt.gdax({'enableRateLimit': True}),
        ccxt.kraken({'enableRateLimit': True}),
        ccxt.poloniex({'enableRateLimit': True}),
        FastCryptopia({'enableRateLimit': True}),
        ccxt.gemini({'enableRateLimit': True}),
        ccxt.kucoin({'enableRateLimit': True}),
        ccxt.binance({'enableRateLimit': True})
    }
    logging.basicConfig(level=logging.INFO)
    start_with = ("ETH", 10)
    arbs = Sharpshooter(EXCHANGES, start_with).run_once()
    Sharpshooter.print_arbs(arbs)
Exemple #11
0
import ccxt.async as ccxt
from bot_speculator import BotSpeculator
from helper import NoInternetException

if __name__ == '__main__':
    # initialize exchangers instances

    kraken = ccxt.kraken({'apiKey': 'yourapikey',
                          'secret': 'yoursecrect'})
    binance = ccxt.binance({'apiKey': 'yourapikey',
                            'secret': 'yoursecrect'})
    # group them together
    gateways = [binance, kraken]  #[cex, binance, bittrex, poloniex, kraken]
    # define pairs for analysis
    pairs = ['XRP/BTC']
    # run the bot
    speculator = BotSpeculator(gateways, pairs, 10.3)
    try:
        speculator.run(5)
    except KeyboardInterrupt:
        print('stop.')
    except NoInternetException:
        print('Connect to the Internet to run the program!')
Exemple #12
0
# Logger for this module
log = logging.getLogger(__name__)
log_format = '%(asctime)s %(levelname)-5.5s [%(name)s-%(funcName)s:%(lineno)d][%(threadName)s] %(message)s'
log_filename = datetime.now().strftime('SpreadFinder.%Y%m%d-%H%M%S.log')
logfile = logdir + log_filename
logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s',
                    filename=logfile,
                    level=logging.INFO)

starttime = time.time()
hitbtc = ccxt.hitbtc({'apiKey': '', 'secret': ''})

kucoin = ccxt.kucoin({'apiKey': '', 'secret': ''})

binance = ccxt.binance({'apiKey': '', 'secret': ''})

poloniex = ccxt.poloniex({'apiKey': '', 'secret': ''})

okex = ccxt.okex()
okex.name = 'okex'
huobi = ccxt.huobi()

symbol = 'NEO/ETH'
exchanges = [hitbtc, binance, kucoin, okex]
ioloop = asyncio.get_event_loop()

bids_df = pd.DataFrame()
asks_df = pd.DataFrame()

bids_filename = savedir + datetime.now().strftime(
Exemple #13
0
import asyncio
import time

import ccxt.async as ccxt
import pandas as pd
from IPython.display import display

gateio = ccxt.gateio()
gdax = ccxt.gdax()
binance = ccxt.binance()
bitbank = ccxt.bitbank()
bit2c = ccxt.bit2c()
bitbay = ccxt.bitbay()


exchanges = {
    gateio: ['ETH/BTC', 'LTC/BTC'],
    gdax: ['ETH/BTC', 'LTC/BTC', 'BTC/USD'],
    binance: ['ETH/BTC', 'LTC/BTC'],
    bitbank: ['ETH/BTC', 'LTC/BTC'],
    bit2c: ['BTC/NIS', 'LTC/NIS'],
    bitbay: ['ETH/BTC', 'LTC/BTC']
}


async def get_top_of_book(top_bids, top_asks, exchange, symbol):
    book = await exchange.fetch_order_book(symbol)
    top_bids[exchange.name][symbol] = float(book['bids'][0][0])
    top_bids[exchange.name]["taker"] = exchange.fees['trading']['taker']
    top_asks[exchange.name][symbol] = float(book['asks'][0][0])
Exemple #14
0
    def __init__(self, exchange_id, config):
        threading.Thread.__init__(self)

        self.ob_constant = OD_TICK_TIMER
        self.bl_constant = BALANCE_TICK_TIMER
        self.trade_constant = TRADE_TICK_TIMER

        self.stop_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=TICK_TIMER)
        self.orderbook_tick_time = datetime.datetime.now(
        ) + datetime.timedelta(seconds=self.ob_constant)
        self.balance_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=self.bl_constant)
        self.trade_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=self.trade_constant)
        self.info_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=INFO_TIMER)

        self.config = config
        self.orderbook_count = 0
        self.pair_info = dict()

        self.exhange = exchange_id
        self.is_auth = False
        self.name = '[ccxt %s]' % self.exhange
        self.pair_list = set()

        if self.exhange == 'liqui':
            self.ob_constant = 30
            self.bl_constant = 60

        self.ccxt_in_queue = self.config['in_queue']
        self.ccxt_out_queue = self.config['out_queue']

        #self.pair_list = self.config['pairs']

        # for i in self.config['pairs']:
        #     i['balance_tick'] = True
        #     self.pair_list.add( i['name'] )

        auth = {}
        if 'auth' in self.config.keys():
            auth = self.config['auth']
            self.is_auth = True
            self.name = '[ccxt %s %s*]' % (self.exhange, auth['apiKey'][:4])

        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        if self.exhange == 'hitbtc':
            loop.create_task(self.run_loop(ccxt.hitbtc(auth)))
        elif self.exhange == 'coinmarketcap':
            loop.create_task(self.run_loop(ccxt.coinmarketcap()))
        elif self.exhange == 'binance':
            loop.create_task(self.run_loop(ccxt.binance(auth)))
        elif self.exhange == 'bitmex':
            loop.create_task(self.run_loop(ccxt.bitmex(auth)))
        elif self.exhange == 'huobipro':
            loop.create_task(self.run_loop(ccxt.huobipro()))
        elif self.exhange == 'liqui':
            loop.create_task(self.run_loop(ccxt.liqui(auth)))
        elif self.exhange == 'bitfinex2':
            loop.create_task(self.run_loop(ccxt.bitfinex2(auth)))
        elif self.exhange == 'bitfinex':
            loop.create_task(self.run_loop(ccxt.bitfinex(auth)))
        elif self.exhange == 'okex':
            loop.create_task(self.run_loop(ccxt.okex(auth)))
        elif self.exhange == 'kucoin':
            loop.create_task(self.run_loop(ccxt.kucoin(auth)))
        elif self.exhange == 'bittrex':
            loop.create_task(self.run_loop(ccxt.bittrex(auth)))
        elif self.exhange == 'qryptos':
            loop.create_task(self.run_loop(ccxt.qryptos(auth)))
        elif self.exhange == 'kraken':
            loop.create_task(self.run_loop(ccxt.kraken(auth)))

        loop.run_forever()