Exemple #1
0
def exchangeObject(exchange_in):
    exchanges = [ccxt.acx(),ccxt.bitbay(),ccxt.bitfinex(),ccxt.bitflyer(),ccxt.bithumb(),ccxt.bitlish(),ccxt.bitmarket(),ccxt.bitmex(),ccxt.bitso(),
                         ccxt.bitstamp(),ccxt.bitstamp1(),ccxt.bittrex(),ccxt.bl3p(),ccxt.bleutrade(),ccxt.btcbox(),ccxt.btcchina(),ccxt.btcexchange(),ccxt.btcmarkets(),ccxt.btctradeua(),ccxt.btcturk(),
                         ccxt.btcx(),ccxt.bxinth(),ccxt.ccex(),ccxt.cex(),ccxt.chbtc(),ccxt.chilebit(),ccxt.coincheck(),ccxt.coinfloor(),ccxt.coingi(),ccxt.coinmarketcap(),ccxt.coinmate(),
                         ccxt.coinsecure(),ccxt.coinspot(),ccxt.cryptopia(),ccxt.dsx(),ccxt.exmo(),ccxt.flowbtc(),ccxt.foxbit(),ccxt.fybse(),ccxt.fybsg(),ccxt.gatecoin(),ccxt.gateio(),ccxt.gdax(),
                         ccxt.gemini(),ccxt.getbtc(),ccxt.hitbtc(),ccxt.huobi(),ccxt.huobicny(),ccxt.independentreserve(),ccxt.itbit(),ccxt.jubi(),ccxt.kraken(),ccxt.kucoin(),
                         ccxt.kuna(),ccxt.lakebtc(),ccxt.liqui(),ccxt.livecoin(),ccxt.luno(),ccxt.mercado(),ccxt.mixcoins(),ccxt.nova(),ccxt.okcoincny(),ccxt.okcoinusd(),ccxt.okex(),ccxt.paymium(),
                         ccxt.poloniex(),ccxt.qryptos(),ccxt.quadrigacx(),ccxt.southxchange(),ccxt.surbitcoin(),ccxt.therock(),ccxt.tidex(),ccxt.urdubit(),ccxt.vaultoro(),ccxt.vbtc(),
                         ccxt.virwox(),ccxt.wex(),ccxt.xbtce(),ccxt.yobit(),ccxt.yunbi(),ccxt.zaif(),ccxt.zb()]

    for count, exchange in enumerate([str(x) for x in exchanges]):
            if exchange_in.lower() in exchange:
                return exchanges[count]
                break
Exemple #2
0
    def __init__(self):
        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
            })
        }

        # Init markets
        for key, value in self.markets.items():
            value.load_markets()
Exemple #3
0
def get_coins_liqui():
    exchange = ccxt.liqui()
    markets = exchange.fetch_markets()
    try:
        for market in markets:
            symbol = market['base']
            try:
                name = coins[symbol].lower()
            except Exception as e:
                # print(f'Failed to match ' + symbol + '. Consider adding to coins.py.')
                continue
            symbol_name[symbol] = name
            name_symbol[name] = symbol
            symbol_exchange[symbol] = 'liqui'
        # print(f'Found {len(markets)} markets.')
    except Exception as e:
        print(f'Failed to get markets from Liqui ({e})')
Exemple #4
0
 def get(cls):
     return {
         'binance':
         ccxt.binance({
             'apiKey': 'YOUR_PUBLIC_API_KEY',
             'secret': 'YOUR_SECRET_PRIVATE_KEY',
         }),
         'bitstamp':
         ccxt.bitstamp({
             'apiKey': 'YOUR_PUBLIC_API_KEY',
             'secret': 'YOUR_SECRET_PRIVATE_KEY',
         }),
         'bittrex':
         ccxt.bittrex({
             'apiKey': os.environ.get("BITTREX_KEY"),
             'secret': os.environ.get("BITTREX_SECRET"),
         }),
         'gdax':
         ccxt.gdax({
             'apiKey': 'YOUR_PUBLIC_API_KEY',
             'secret': 'YOUR_SECRET_PRIVATE_KEY',
         }),
         'hitbtc':
         ccxt.hitbtc({
             'apiKey': 'YOUR_PUBLIC_API_KEY',
             'secret': 'YOUR_SECRET_PRIVATE_KEY',
         }),
         'kraken':
         ccxt.kraken({
             'apiKey': 'YOUR_PUBLIC_API_KEY',
             'secret': 'YOUR_SECRET_PRIVATE_KEY',
         }),
         'liqui':
         ccxt.liqui({
             'apiKey': 'YOUR_PUBLIC_API_KEY',
             'secret': 'YOUR_SECRET_PRIVATE_KEY',
         }),
         'poloniex':
         ccxt.poloniex({
             'apiKey': 'YOUR_PUBLIC_API_KEY',
             'secret': 'YOUR_SECRET_PRIVATE_KEY',
         }),
         # add additional supported exchanges
     }
def liquiAgg(symbols):
    result = []
    try:
        liqui = ccxt.liqui({
            'apiKey': 'apiKey',
            'secret': 'secret',
            'options': {
                'adjustForTimeDifference': True
            }
        })
        totalBalance = liqui.fetch_balance()["free"]
        exchangeSymbols = liqui.symbols
        checkSymbols = list(np.intersect1d(exchangeSymbols, symbols))
        allData = liqui.fetch_tickers(checkSymbols)
        ethPrice = liqui.fetch_ticker("ETH/USDT")["last"]
        btcPrice = liqui.fetch_ticker("BTC/USDT")["last"]
        for s in checkSymbols:
            try:
                quote = s.split("/")[-1]
                dataSymbols = allData[s]
                coinBalance = totalBalance.get(s.split("/")[0], 0)
                volume = int(float(dataSymbols["baseVolume"]))
                ask = dataSymbols["ask"]
                bid = dataSymbols["bid"]
                last = float(dataSymbols["last"])
                if quote == "BTC":
                    volume = int(volume * btcPrice * last)
                elif quote == "ETH":
                    volume = int(volume * ethPrice * last)
                else:
                    volume = int(volume * dataSymbols["last"])
                volume = volume / ethPrice
                result.append(["liqui", s, coinBalance, ask, bid, volume])
            except:
                print("Liqui couldn`t get " + s)
                continue
    except Exception as e:
        print(str(e)[:150])
    return (result)
Exemple #6
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,
                'timeout': settings.LIQUI.TIMEOUT
            }),
            'BINANCE':
            ccxt.binance({
                'apiKey': settings.BINANCE.API_KEY,
                'secret': settings.BINANCE.API_SECRET,
                'timeout': settings.BINANCE.TIMEOUT
            })
        }

        # Init markets
        for key, value in self.markets.items():
            value.load_markets()
Exemple #7
0
    # (ccxt.gemini(), 'https://gemini.com/marketplace/'),
    # # 14. Binance
    # (ccxt.binance({
    #     'apiKey': BINANCE_KEY,
    #     'secret': BINANCE_SECRET,
    # }), 'https://www.binance.com/trade.html?symbol={0}_{1}'),
    # # 16. WEX
    # (ccxt.wex(), 'https://wex.nz/exchange/{0}_{1}'),
    # # 21. CEX.IO
    # (ccxt.cex(), 'https://cex.io/{0}-{1}'),
    # 22. YoBit
    (ccxt.yobit(), 'https://yobit.net/en/trade/{0}/{1}'),
    # # 24. Gatecoin
    # (ccxt.gatecoin(), 'https://gatecoin.com/marketData'),
    # 25. Liqui
    (ccxt.liqui(), 'https://liqui.io/#/exchange/{0}_{1}'),
    # # 26. OKEx
    # (ccxt.okex(), 'https://www.okex.com/'),
    # 43. Tidex
    (ccxt.tidex(), 'https://tidex.com/exchange/{0}/{1}'),
    # 52. Cryptopia
    (ccxt.cryptopia(), 'https://www.cryptopia.co.nz/Exchange/?market={0}_{1}'),
]


def main():
    now = datetime.now()

    # Get all markets
    res = requests.get('https://api.coinmarketcap.com/v1/ticker/')
    markets = res.json()
Exemple #8
0
 ccxt.hitbtc(),
 ccxt.hitbtc2(),
 ccxt.huobi(),
 ccxt.huobicny(),
 ccxt.huobipro(),
 ccxt.ice3x(),
 ccxt.independentreserve(),
 ccxt.indodax(),
 ccxt.itbit(),
 ccxt.jubi(),
 ccxt.kraken(),
 ccxt.kucoin(),
 ccxt.kuna(),
 ccxt.lakebtc(),
 ccxt.lbank(),
 ccxt.liqui(),
 ccxt.livecoin(),
 ccxt.luno(),
 ccxt.lykke(),
 ccxt.mercado(),
 ccxt.mixcoins(),
 ccxt.negociecoins(),
 ccxt.nova(),
 ccxt.okcoincny(),
 ccxt.okcoinusd(),
 ccxt.okex(),
 ccxt.paymium(),
 ccxt.poloniex(),
 ccxt.qryptos(),
 ccxt.quadrigacx(),
 ccxt.quoinex(),
Exemple #9
0
class Crypto:
    # dictionary of supported exchanges
    # user needs to input public API key and secret for existing accounts
    exchanges = {
        'binance':
        ccxt.binance({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'bitstamp':
        ccxt.bitstamp({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'bittrex':
        ccxt.bittrex({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'gdax':
        ccxt.gdax({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'hitbtc':
        ccxt.hitbtc({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'kraken':
        ccxt.kraken({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'liqui':
        ccxt.liqui({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'poloniex':
        ccxt.poloniex({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        # add additional supported exchanges
    }

    def __init__(self, exchange='bittrex'):
        self.exchange = self.exchanges[exchange]

    def run_prepump(self):
        prepumped_markets = self.find_prepumped_markets()
        print "Pre-pumped markets on %s:" % (self.exchange.name)
        print prepumped_markets

        hits = []

        # Just test on 10 ranodm markets
        sample_size = 10
        prepumped_markets = self.random_sample(prepumped_markets, sample_size)
        print "Testing: sampling %s markets: " % (sample_size)
        print prepumped_markets

        for market in prepumped_markets:
            print "Testing market %s for arbitrage" % (market)

            result = self.expected_value(market, 0.05, 0.01, 0.0025)
            if result:
                print "- HIT!"
                hits.append(result)
            else:
                print "- None"
            sleep(1)

        print "HITS !!!!!!!!"
        print "Number of hits: ", len(hits)
        print hits

    def fetch_markets(self, symbol):
        prices = {}
        exchanges = self.exchanges

        # pull prices of coin across exchanges
        for key in exchanges:
            try:
                market_info = exchanges[key].fetch_ticker(symbol)
            except:
                continue

            market_bid = market_info["bid"]
            market_ask = market_info["ask"]

            # Ignore when None
            if (market_bid is None) or (market_ask is None):
                continue

            prices.setdefault("bid", {})
            prices.setdefault("ask", {})
            prices["bid"][key] = market_bid
            prices["ask"][key] = market_ask
        return prices
Exemple #10
0
class Crypto:
    # dictionary of supported exchanges
    # user needs to input public API key and secret for existing accounts
    exchanges = {
        'binance':
        ccxt.binance({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'bitstamp':
        ccxt.bitstamp({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'bittrex':
        ccxt.bittrex({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'gdax':
        ccxt.gdax({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'hitbtc':
        ccxt.hitbtc({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'kraken':
        ccxt.kraken({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'liqui':
        ccxt.liqui({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        'poloniex':
        ccxt.poloniex({
            'apiKey': 'YOUR_PUBLIC_API_KEY',
            'secret': 'YOUR_SECRET_PRIVATE_KEY',
        }),
        # add additional supported exchanges
    }

    def __init__(self, exchange='bittrex'):
        self.exchange = self.exchanges[exchange]

    def run_prepump(self):
        prepumped_markets = self.find_prepumped_markets()
        print "Pre-pumped markets on %s:" % (self.exchange.name)
        print prepumped_markets

        hits = []

        # Just test on 10 ranodm markets
        sample_size = 10
        prepumped_markets = self.random_sample(prepumped_markets, sample_size)
        print "Testing: sampling %s markets: " % (sample_size)
        print prepumped_markets

        for market in prepumped_markets:
            print "Testing market %s for arbitrage" % (market)

            result = self.expected_value(market, 0.05, 0.01, 0.0025)
            if result:
                print "- HIT!"
                hits.append(result)
            else:
                print "- None"
            sleep(1)

        print "HITS !!!!!!!!"
        print "Number of hits: ", len(hits)
        print hits

    def fetch_markets(self, symbol):
        prices = {}
        exchanges = self.exchanges

        # pull prices of coin across exchanges
        for key in exchanges:
            try:
                market_info = exchanges[key].fetch_ticker(symbol)
            except:
                continue

            market_bid = market_info["bid"]
            market_ask = market_info["ask"]

            # Ignore when None
            if (market_bid is None) or (market_ask is None):
                continue

            prices.setdefault("bid", {})
            prices.setdefault("ask", {})
            prices["bid"][key] = market_bid
            prices["ask"][key] = market_ask
        return prices

        # check if price variance is greater than cost
    def expected_value(self, market_symbol, unit_gain, transfer_fee,
                       trade_fee):
        prices = self.fetch_markets(market_symbol)
        bid_prices = prices["bid"]
        ask_prices = prices["ask"]

        # select exchanges with highest bid and lowest ask
        high_bid_exchange = max(bid_prices, key=(lambda key: bid_prices[key]))
        high_bid = bid_prices[high_bid_exchange]
        # print "BID PRICES: "
        # print bid_prices
        # print "High bid: %s on %s" % (high_bid, high_bid_exchange)
        low_ask_exchange = min(ask_prices, key=(lambda key: ask_prices[key]))
        low_ask = ask_prices[low_ask_exchange]
        # print "ASK PRICES: "
        # print ask_prices
        # print "low ask: %s on %s" % (low_ask, low_ask_exchange)
        # take difference of prices
        difference = high_bid - low_ask
        costs = (low_ask * trade_fee) + (low_ask * transfer_fee) + (high_bid *
                                                                    trade_fee)
        # print "%s (bid-ask) - %s (costs) = %s (profit)" % (difference, costs, difference - costs)
        # see if difference is greater than transfer fees + trade fees
        if difference > costs:
            # price_risk = # figure out through trial and error
            # calculate expected value:
            # expected_value = difference - ((high_bid * transfer_fee) + (low_ask * trade_fee) + price_risk)
            # while expected value is positive:
            if (difference - costs) > (unit_gain * low_ask):
                return {
                    "market": market_symbol,
                    "high_bid_exchange": high_bid_exchange,
                    "low_ask_exchange": low_ask_exchange,
                    "high_bid": high_bid,
                    "low_ask": low_ask,
                    "costs": costs,
                    "difference": difference
                }
        return False

    # Returns n elements from mylist, randomly sampled
    def random_sample(self, mylist, n):
        return [
            mylist[i] for i in sorted(random.sample(xrange(len(mylist)), n))
        ]

    def get_market_summary(self, market_symbol):
        # we assume market symbol is always in format of "COIN/BTC"
        summary = self.exchange.fetch_ticker(market_symbol)
        low_24_hr = summary["low"]
        last_price = summary["last"]
        ask_price = summary["ask"]
        volume = summary["baseVolume"]
        return [low_24_hr, last_price, ask_price, volume]

    # Finds markets that are pre-pumped
    def find_prepumped_markets(self, prepump_buffer=0.5):
        exchange_markets = self.exchange.load_markets()
        goodMarkets = []
        for market_symbol in exchange_markets:
            currency = exchange_markets[market_symbol]["info"][
                "MarketCurrencyLong"]
            base_currency = exchange_markets[market_symbol]["info"][
                "BaseCurrency"]
            print "Finding details on: %s" % (market_symbol)
            if exchange_markets[market_symbol][
                    "active"] and base_currency == "BTC" and self.coin_pumped(
                        market_symbol, prepump_buffer):
                goodMarkets.append(market_symbol)
        return goodMarkets

    # Return True if market is pre-pumped
    # retry with random wait betwen 1-2s
    @retry(stop_max_attempt_number=3,
           wait_random_min=1000,
           wait_random_max=2000)
    def coin_pumped(self, market_symbol, prepump_buffer=0.5):
        low_24_hr, last_price, ask_price, volume = self.get_market_summary(
            market_symbol)
        if volume < 100 and last_price < (
                1.0 + prepump_buffer
        ) * low_24_hr:  #last_price is smaller than 50% increase since yerterday
            return False
        else:
            return True
Exemple #11
0
parser = argparse.ArgumentParser()
parser.add_argument('filename', type=str, help='the data.json file')

args = parser.parse_args()
table = BeautifulTable()
table.column_headers = ["pair", "price", "ratio", "size", "note"]
table.numeric_precision = 8

exchanges = {
    "bittrex": ccxt.bittrex(),
    "poloniex": ccxt.poloniex(),
    "bitfinex": ccxt.bitfinex(),
    "cryptopia": ccxt.cryptopia(),
    "kraken": ccxt.kraken(),
    "liqui": ccxt.liqui(),
    "binance": ccxt.binance()
}


def load_data(filename):
    with open(args.filename, 'r') as f:
        data = json.load(f, object_pairs_hook=OrderedDict)
        return data


def translate_dash_to_slash(pair):
    """
    Translates BTC-1ST to 1ST/BTC
    Or, if it's already 1ST/BTC, just return that
    """