Beispiel #1
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()
Beispiel #2
0
async def main():

    asyncio.ensure_future(status_monitor(status_queue))

    print('Beginning tests')
    exchange = ccxt.bitfinex()
    exchange.verbose = True
    symbols_to_load = [
        'XRP/USD', 'BTC/USD', 'ETH/BTC', 'ETH/USD', 'LTC/BTC', 'LTC/USD'
    ]
    input_coroutines = [
        exchange.subscribe_order_book(symbol, status_queue=status_queue)
        for symbol in symbols_to_load
    ]
    results = await asyncio.gather(*input_coroutines, return_exceptions=True)
    for result, symbol in zip(results, symbols_to_load):
        if isinstance(result, dict):
            print('ERROR loading Symbol: {0}, {1}'.format(symbol, result))

    await asyncio.sleep(3)

    for symbol in symbols_to_load:
        order_book = await exchange.fetchOrderBook(symbol)
        print('')
        print('Symbol: {0} OrderBook: {1}'.format(symbol, order_book))

    ### Fetch multiple order books & automatically subscribe to them
    # input_coroutines = [exchange.fetchOrderBook(symbol) for symbol in symbols_to_load]
    # results = await asyncio.gather(*input_coroutines, return_exceptions=True)
    # for result, symbol in zip(results, symbols_to_load):
    #     if result:
    #         print('')
    #         print(symbol)
    #         print(result)

    print('Finished tests')
Beispiel #3
0
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 = []
info = {}
    return [symbol for symbol in exchange.symbols if is_active_symbol(exchange, symbol)]


def is_active_symbol(exchange, symbol):
    return ('.' not in symbol) and (('active' not in exchange.markets[symbol]) or (exchange.markets[symbol]['active']))


async def fetch_ticker(exchange, symbol):
    ticker = await exchange.fetchTicker(symbol)
    print(exchange.id, symbol, ticker)
    return ticker


async def fetch_tickers(exchange):
    await exchange.load_markets()
    print(exchange.id, 'fetching all tickers by simultaneous multiple concurrent requests')
    symbols_to_load = get_active_symbols(exchange)
    input_coroutines = [fetch_ticker(exchange, symbol) for symbol in symbols_to_load]
    tickers = await asyncio.gather(*input_coroutines, return_exceptions=True)
    for ticker, symbol in zip(tickers, symbols_to_load):
        if not isinstance(ticker, dict):
            print(exchange.id, symbol, 'error')
        else:
            print(exchange.id, symbol, 'ok')
    print(exchange.id, 'fetched', len(list(tickers)), 'tickers')


asyncio.get_event_loop().run_until_complete(fetch_tickers(ccxt.bitfinex({
    'enableRateLimit': True,  # this option enables the built-in rate limiter
})))
# -*- coding: utf-8 -*-

import asyncio
import os
import sys

root = os.path.dirname(
    os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')

import ccxt. async as ccxt  # noqa: E402


async def main(exchange):
    for i in range(0, 10):
        # this can be any call instead of fetch_ticker, really
        print(await exchange.fetch_ticker('BTC/USD'))


# you can set enableRateLimit = True to enable the built-in rate limiter
# this way you request rate will never hit the limit of an exchange
# the library will throttle your requests to avoid that

exchange = ccxt.bitfinex({
    'enableRateLimit': True,  # this option enables the built-in rate limiter
})

asyncio.get_event_loop().run_until_complete(main(exchange))
Beispiel #6
0
    #'verbose': True,
})
bit2c = ccxt.bit2c({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bitbay = ccxt.bitbay({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bitcoincoid = ccxt.bitcoincoid({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bitfinex = ccxt.bitfinex({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bitfinex2 = ccxt.bitfinex2({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bitflyer = ccxt.bitflyer({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bithumb = ccxt.bithumb({
    'enableRateLimit': True,
    'rateLimit': 1000,
})
bitlish = ccxt.bitlish({
    'enableRateLimit': True,
Beispiel #7
0
# -*- coding: utf-8 -*-

import asyncio
import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root)

import ccxt.async as ccxt  # noqa: E402


async def test(exchange):
    print(await exchange.private_post_account_infos())


bitfinex = ccxt.bitfinex({
    'apiKey': "4FlEDtxDl35gdEiobnfZ72vJeZteE4Bb7JdvqzjIjHq",
    'secret': "D4DXM8DZdHuAq9YptUsb42aWT1XBnGlIJgLi8a7tzFH",
    'verbose': True,  # switch it to False if you don't want the HTTP log
})

[asyncio.ensure_future(test(exchange)) for exchange in [bitfinex]]
pending = asyncio.Task.all_tasks()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*pending))
# -*- coding: utf-8 -*-

import asyncio
import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')

import ccxt.async as ccxt  # noqa: E402


async def main(exchange):
    for i in range(0, 10):
        # this can be any call instead of fetch_ticker, really
        print(await exchange.fetch_ticker('BTC/USD'))


# you can set enableRateLimit = True to enable the built-in rate limiter
# this way you request rate will never hit the limit of an exchange
# the library will throttle your requests to avoid that

exchange = ccxt.bitfinex({
    'enableRateLimit': True,  # this option enables the built-in rate limiter
})

asyncio.get_event_loop().run_until_complete(main(exchange))
import asyncio
import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')

import ccxt.async as ccxt  # noqa: E402


async def test(exchange):
    print(await exchange.fetch_balance())


kraken = ccxt.kraken({
    'apiKey': "hEvQNMDIeoCJbr7W/ZBb5CGOrx3G0lWF5B3zqa1JBxdZlEaL8EK+D0Mw",
    'secret': "JaE9wI6Nwgh5oRxiHcVxurwzwBxwc05W/qv/k1srGg4s3EYuXPpNkLLM5NYbbWpM8rCyijIeDavRuqWbU0ZV9A==",
    'verbose': True,  # switch it to False if you don't want the HTTP log
})
bitfinex = ccxt.bitfinex({
    'apiKey': "4FlEDtxDl35gdEiobnfZ72vJeZteE4Bb7JdvqzjIjHq",
    'secret': "D4DXM8DZdHuAq9YptUsb42aWT1XBnGlIJgLi8a7tzFH",
    'verbose': True,  # switch it to False if you don't want the HTTP log
})

[asyncio.ensure_future(test(exchange)) for exchange in [kraken, bitfinex]]
pending = asyncio.Task.all_tasks()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*pending))
Beispiel #10
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()