예제 #1
0
def getCEXData():
    cex = ccxt.cex()
    
    orderbook = cex.fetch_order_book ("BTC/USD")
    bid = orderbook['bids'][0][0] if len (orderbook['bids']) > 0 else None
    ask = orderbook['asks'][0][0] if len (orderbook['asks']) > 0 else None
    spread = (ask - bid) if (bid and ask) else None
    print (cex.id, 'market price', { 'bid': bid, 'ask': ask, 'spread': spread })
    #data = requests.get("https://cex.io/api/ticker/BTC/USD").json()
    #print("CEX ",data)
    return { 'bid': bid, 'ask': ask, 'spread': spread } 
예제 #2
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
# -*- coding: utf-8 -*-

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  # noqa: E402

# return up to ten bidasks on each side of the order book stack
print(ccxt.cex().fetch_order_book('BTC/USD', {'depth': 10}))
예제 #4
0

exchange_id = 'binance'
exchange_class = getattr(ccxt, exchange_id)
exchange = exchange_class({
    'apiKey': 'YOUR_API_KEY',
    'secret': 'YOUR_SECRET',
    'timeout': 30000,
    'enableRateLimit': True,


exchange = ccxt.binance ({
    'rateLimit': 10000,  # unified exchange property
    'headers': {
        'YOUR_CUSTOM_HTTP_HEADER': 'YOUR_CUSTOM_VALUE',
    },
    'options': {
        'adjustForTimeDifference': True,  # exchange-specific option
    }
})
exchange.options['adjustForTimeDifference'] = False
import time
if exchange.has['fetchOHLCV']:
    for symbol in exchange.markets:
        time.sleep (exchange.rateLimit / 1000) # time.sleep wants seconds
        print (symbol, exchange.fetch_ohlcv (symbol, '1d'))



ccxt.cex().fetch_order_book('BTC/USD', limit)
예제 #5
0
def create_exchanges():
    """
        instantiate the markets
        to include more exchanges use this function.
        new exchanges need to be hand-coded here
    """
    coinbasepro = ccxt.coinbasepro({
        'apiKey': api_keys.coinbasepro['apiKey'],
        'secret': api_keys.coinbasepro['secret'],
        'enableRateLimit': True,
    })

    cex = ccxt.cex({
        'apiKey': api_keys.cex['apiKey'],
        'secret': api_keys.cex['secret'],
        'enableRateLimit': True,
    })

    poloniex = ccxt.poloniex({
        'apiKey': api_keys.poloniex['apiKey'],
        'secret': api_keys.poloniex['secret'],
        'enableRateLimit': True,
    })

    bittrex = ccxt.bittrex({
        'apiKey': api_keys.bittrex['apiKey'],
        'secret': api_keys.bittrex['secret'],
        'enableRateLimit': True,
    })

    binance = ccxt.binance({
        'apiKey': api_keys.binance['apiKey'],
        'secret': api_keys.binance['secret'],
        'enableRateLimit': True,
    })

    bitfinex = ccxt.bitfinex({
        'apiKey': api_keys.bitfinex['apiKey'],
        'secret': api_keys.bitfinex['secret'],
        'enableRateLimit': True,
    })

    kucoin = ccxt.kucoin({
        'apiKey': api_keys.kucoin['apiKey'],
        'secret': api_keys.kucoin['secret'],
        'enableRateLimit': True,
    })

    kraken = ccxt.kraken({
        'apiKey': api_keys.kraken['apiKey'],
        'secret': api_keys.kraken['secret'],
        'enableRateLimit': True,
        'options': {  # ←--------------------- inside 'options' subkey
            'fetchMinOrderAmounts': False,  # ←---------- set to False 
        }
    })

    bitmex = ccxt.bitmex({
        'apiKey': api_keys.bitmex['apiKey'],
        'secret': api_keys.bitmex['secret'],
        'enableRateLimit': True,
    })

    okex = ccxt.okex({
        'apiKey': api_keys.okex['apiKey'],
        'secret': api_keys.okex['secret'],
        'enableRateLimit': True,
    })

    exchanges = [
        coinbasepro, cex, poloniex, bittrex, binance, bitfinex, kucoin, kraken,
        okex, bitmex
    ]

    return exchanges
예제 #6
0
def init_supported_exchanges():
    objects = {
        "acx": ccxt.acx(),
        "aofex": ccxt.aofex(),
        "bequant": ccxt.bequant(),
        "bibox": ccxt.bibox(),
        "bigone": ccxt.bigone(),
        "binance": ccxt.binance(),
        "bitbank": ccxt.bitbank(),
        "bitbay": ccxt.bitbay(),
        "bitfinex": ccxt.bitfinex(),
        "bitflyer": ccxt.bitflyer(),
        "bitforex": ccxt.bitforex(),
        "bithumb": ccxt.bithumb(),
        "bitkk": ccxt.bitkk(),
        "bitmax": ccxt.bitmax(),
        "bitstamp": ccxt.bitstamp(),
        "bittrex": ccxt.bittrex(),
        "bitz": ccxt.bitz(),
        "bl3p": ccxt.bl3p(),
        "bleutrade": ccxt.bleutrade(),
        "braziliex": ccxt.braziliex(),
        "btcalpha": ccxt.btcalpha(),
        "btcbox": ccxt.btcbox(),
        "btcmarkets": ccxt.btcmarkets(),
        "btctradeua": ccxt.btctradeua(),
        "bw": ccxt.bw(),
        "bybit": ccxt.bybit(),
        "bytetrade": ccxt.bytetrade(),
        "cex": ccxt.cex(),
        "chilebit": ccxt.chilebit(),
        "coinbase": ccxt.coinbase(),
        "coinbasepro": ccxt.coinbasepro(),
        "coincheck": ccxt.coincheck(),
        "coinegg": ccxt.coinegg(),
        "coinex": ccxt.coinex(),
        "coinfalcon": ccxt.coinfalcon(),
        "coinfloor": ccxt.coinfloor(),
        "coinmate": ccxt.coinmate(),
        "coinone": ccxt.coinone(),
        "crex24": ccxt.crex24(),
        "currencycom": ccxt.currencycom(),
        "digifinex": ccxt.digifinex(),
        "dsx": ccxt.dsx(),
        "eterbase": ccxt.eterbase(),
        "exmo": ccxt.exmo(),
        "exx": ccxt.exx(),
        "foxbit": ccxt.foxbit(),
        "ftx": ccxt.ftx(),
        "gateio": ccxt.gateio(),
        "gemini": ccxt.gemini(),
        "hbtc": ccxt.hbtc(),
        "hitbtc": ccxt.hitbtc(),
        "hollaex": ccxt.hollaex(),
        "huobipro": ccxt.huobipro(),
        "ice3x": ccxt.ice3x(),
        "independentreserve": ccxt.independentreserve(),
        "indodax": ccxt.indodax(),
        "itbit": ccxt.itbit(),
        "kraken": ccxt.kraken(),
        "kucoin": ccxt.kucoin(),
        "lakebtc": ccxt.lakebtc(),
        "latoken": ccxt.latoken(),
        "lbank": ccxt.lbank(),
        "liquid": ccxt.liquid(),
        "livecoin": ccxt.livecoin(),
        "luno": ccxt.luno(),
        "lykke": ccxt.lykke(),
        "mercado": ccxt.mercado(),
        "oceanex": ccxt.oceanex(),
        "okcoin": ccxt.okcoin(),
        "okex": ccxt.okex(),
        "paymium": ccxt.paymium(),
        "poloniex": ccxt.poloniex(),
        "probit": ccxt.probit(),
        "southxchange": ccxt.southxchange(),
        "stex": ccxt.stex(),
        "surbitcoin": ccxt.surbitcoin(),
        "therock": ccxt.therock(),
        "tidebit": ccxt.tidebit(),
        "tidex": ccxt.tidex(),
        "upbit": ccxt.upbit(),
        "vbtc": ccxt.vbtc(),
        "wavesexchange": ccxt.wavesexchange(),
        "whitebit": ccxt.whitebit(),
        "yobit": ccxt.yobit(),
        "zaif": ccxt.zaif(),
        "zb": ccxt.zb()
    }
    return objects
예제 #7
0
import asciichart

# -----------------------------------------------------------------------------

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

# -----------------------------------------------------------------------------

import ccxt  # noqa: E402

# -----------------------------------------------------------------------------

exchange = ccxt.cex()
symbol = 'BTC/USD'

# each ohlcv candle is a list of [ timestamp, open, high, low, close, volume ]
index = 4  # use close price from each ohlcv candle

length = 80
height = 15


def print_chart(exchange, symbol, timeframe):

    print("\n" + exchange.name + ' ' + symbol + ' ' + timeframe + ' chart:')

    # get a list of ohlcv candles
    ohlcv = exchange.fetch_ohlcv(symbol, timeframe)
        ...
    ],
    'asks': [
        [ price, amount ],
        [ price, amount ],
        ...
    ],
    'timestamp': 1499280391811, // Unix Timestamp in milliseconds (seconds * 1000)
    'datetime': '2017-07-05T18:47:14.692Z', // ISO8601 datetime string with milliseconds
}
"""
###############################################################################################
#Market Depth

limit = 10
marketDepth = ccxt.cex().fetch_order_book(symbol, limit)
#return up to ten bidasks on each side of the order book stack

###############################################################################################

#Market Price
#current best price
orderbook = kraken.fetch_order_book (kraken.symbols[0])
bid = orderbook['bids'][0][0] if len (orderbook['bids']) > 0 else None
ask = orderbook['asks'][0][0] if len (orderbook['asks']) > 0 else None
spread = (ask - bid) if (bid and ask) else None
print (kraken.id, 'market price', { 'bid': bid, 'ask': ask, 'spread': spread })


###############################################################################################
#Price Tickers
예제 #9
0
파일: main.py 프로젝트: prathap17/DeCrypto
def start_cex_producer():
    products = ["BTC/USD", "ETH/USD", "BCH/USD", "ETH/BTC", "BCH/BTC"]
    while True:
        for product in products:
            data = Cex(product, cex().fetch_order_book(product))
            data.produce()
예제 #10
0
def calc():

    bitfinex = ccxt.bitfinex()
    marketsBf = bitfinex.load_markets()

    cex = ccxt.cex()
    kucoin = ccxt.kucoin()
    poloniex = ccxt.poloniex()
    bittrex = ccxt.bittrex()

    FEE = 1.02  # fee for every trade (2%)
    Diff = 0.6  # 1 % arbitrage to execute
    curr = [
        "ETH/BTC", "OMG/BTC", "LTC/BTC", "DASH/BTC", "ETC/BTC", "OMG/BTC"
    ]  #  "LTC/BTC", "DASH/BTC", "ETC/BTC", "OMG/BTC", "BCH/BTC"     currencies to trade if arbitrage is found
    exc = [
        bitfinex, kucoin, bittrex, cex
    ]  #  cex ,kucoin , bittrex   exchanges to trade on for the function calls

    def getAsk(market, sym):
        orderbook = market.fetch_order_book(sym)
        ask = orderbook['asks'][0][0] if len(orderbook['asks']) > 0 else None
        return ask

    def getBid(market, sym):
        orderbook = market.fetch_order_book(sym)
        bid = orderbook['bids'][0][0] if len(orderbook['bids']) > 0 else None
        return bid

    def compare():
        print("Arbitrage Trader starting up...")
        yon_file = open("yon.txt", "r")
        yon = yon_file.read()
        yon_file.close
        n = 0
        while n <= (len(curr) - 1):
            print("Starting Arbitrage checking for ", curr[n])
            pairpart1 = curr[n]
            m = 0
            while m <= (len(exc) - 1):
                #print "m = " + str(m)
                k = 0
                while k <= (len(exc) - 1):
                    #print "k = " + str(k)
                    try:
                        if (yon == "1"):
                            sprice = getBid(exc[m], curr[n])
                            bprice = getAsk(exc[k], curr[n])
                        else:
                            sprice = getBid(exc[k], curr[n])
                            bprice = getAsk(exc[m], curr[n])

                    except Exception:
                        pass

                    #print ("Sell price = " , str(sprice) , " on " , exc[m].id)
                    #print ("Buy price  = " , str(bprice) , " on " , exc[k].id)

                    if (float(bprice) < float(sprice)):
                        #print ("Opportunity to buy " , curr[n] , " for ", str(bprice), " on ",exc[k]," and sell for " , str(sprice) , " on " , exc[m])
                        yie = ((float(sprice) - float(bprice)) /
                               float(sprice)) * 100.0
                        #print ("Yield before trading costs would be: ",str(yie),"%")

                    if (((float(sprice) - float(bprice)) / float(sprice)) *
                            100.0 > Diff):
                        # make_trade(exc[k], "buy", amount1, pairpart1, "btc", bprice)
                        # make_trade(exc[m], "sell", amount1, pairpart1, "btc", sprice)
                        #printouts for debugging
                        print("price on ", exc[m].id, " for ", curr[n], " is ",
                              str(sprice), " BTC")
                        print("price on ", exc[k].id, " for ", curr[n], " is ",
                              str(bprice), " BTC")
                        print(
                            "executing trade at a win per 1", curr[n], " of ",
                            str(
                                round(((sprice * 0.998) - (bprice * 1.002004)),
                                      8)), "BTC")
                        profit = str(
                            round(
                                100 * (((sprice + bprice) +
                                        (sprice * 0.998) - bprice * 1.002004) -
                                       (sprice + bprice)) / (sprice + bprice),
                                2))
                        print("profit %", profit)
                        with open("log.txt", "a") as text_file:
                            print(
                                f"{curr[n]}      {exc[m].id}      {sprice}    Sell",
                                file=text_file)
                            print(
                                f"{curr[n]}      {exc[k].id}      {bprice}    Buy",
                                file=text_file)
                            print(
                                f"-{exc[k].id}'den alındı {exc[m].id} 'de satıldı-----yön:{yon}------- Profit % {profit}\n",
                                file=text_file)
                            print(f" yön: {yon}")
                            text_file.close
                        yon_filer = open("yon.txt", "w")
                        if yon == "1":
                            yon_filer.write("0")
                        else:
                            yon_filer.write("1")
                        yon_filer.close

                    k += 1
                m += 1
            n += 1

    compare()
예제 #11
0
# The "taker" BUYS the base with the quote
# The "maker" SELLS the base for the quote

# Code inputs:
N_pairs_with_tether    = 10 # Number of pairs to print in exchanges possibly with tether
N_pairs_without_tether = 10 # Number of pairs to print in exchanges without tether
verbose                = False # Do not print market fetching status

# Exchanges with tether (you can transfer USDT between exchanges)
bittrex  = ccxt.bittrex()  # 266 markets
binance  = ccxt.binance()
poloniex = ccxt.poloniex() # 99 markets
kraken   = ccxt.kraken()   # 59 markets

# Exchanges without tether (cannot transfer USD between exchanges)
cex      = ccxt.cex()      # 27 markets
bitstamp = ccxt.bitstamp() # 15 markets
gdax     = ccxt.gdax()     # 10 markets

exchanges = [bittrex, kraken, poloniex, gdax, cex, bitstamp, binance]

# Load markets and check if exchanges are working
working_exchanges = []
for exchange in exchanges:
    # Try loading the markets, if you can, add it to the working exchanges list
    try:
        exchange.load_markets()
        working_exchanges.append(exchange)
    # If you cannot, say so, and dont add it to the list
    except:
        print('%s is down! Excluding %s'%(exchange.name, exchange.name))
예제 #12
0
    'enableRateLimit': True,
})
gemini = ccxt.gemini({
    'enableRateLimit': True,
})
bitfinex = ccxt.bitfinex({
    'enableRateLimit': True,
})
livecoin = ccxt.livecoin({
    'enableRateLimit': True,
})
kucoin = ccxt.kucoin({
    'enableRateLimit': True,
})
cex = ccxt.cex({
    'enableRateLimit': True,
})
bitstamp = ccxt.bitstamp({
    'enableRateLimit': True,
})

binance_ltc_address = 'LLmWdKju3aHzS8q5azoVGSfPV6NY6a4PvY'
exmo_ltc_address = 'LThC9vNBvyJz7UesBAmpMaJNfHFhxXqhb6'
#----------XRP------------
hitbtc_xrp_deposit_address = 'rhL5Va5tDbUUuozS9isvEuv7Uk1uuJaY1T'
hitbtc_xrp_tag = '1492555998'

exmo_xrp_deposit_address = 'rUocf1ixKzTuEe34kmVhRvGqNCofY1NJzV'
exmo_xrp_tag = '363160755'

#----------DAI------------
# -*- coding: utf-8 -*-

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  # noqa: E402

# return up to ten bidasks on each side of the order book stack
print(ccxt.cex().fetch_order_book('BTC/USD', {'depth': 10}))
예제 #14
0
def exchange():
    cursor = con.cursor()
    kraken = ccxt.kraken()
    df = kraken.fetchTicker('BTC/USD')
    df.pop('info')
    df1 = [df]

    cursor.execute(
        "insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('kraken',"
        + str(df['high']) + "," + str(df['low']) + "," + str(df['last']) +
        "," + str(df['timestamp']) + "," + str(df['bid']) + "," +
        str(df['ask']) + ")")
    con.commit()

    cursor = con.cursor()
    bitfinex = ccxt.bitfinex()
    df = bitfinex.fetchTicker('BTC/USD')
    df.pop('info')
    df1 = [df]

    cursor.execute(
        "insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('bitfinex',"
        + str(df['high']) + "," + str(df['low']) + "," + str(df['last']) +
        "," + str(df['timestamp']) + "," + str(df['bid']) + "," +
        str(df['ask']) + ")")
    con.commit()

    # cursor = con.cursor()
    # poloniex = ccxt.poloniex()
    # df = poloniex.fetchTicker('BTC/USD')
    # df.pop('info')
    # df1 = [df]

    # cursor.execute("insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('poloniex',"+str(df['high'])+","+str(df['low'])+","+str(df['last'])+","+str(df['timestamp'])+","+str(df['bid'])+","+str(df['ask'])+ ")")
    # con.commit()

    cursor = con.cursor()
    bitmex = ccxt.bitmex()
    df = bitmex.fetchTicker('BTC/USD')
    df.pop('info')
    df1 = [df]

    cursor.execute(
        "insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('bitmex',"
        + str(df['high']) + "," + str(df['low']) + "," + str(df['last']) +
        "," + str(df['timestamp']) + "," + str(df['bid']) + "," +
        str(df['ask']) + ")")
    con.commit()

    cursor = con.cursor()
    bittrex = ccxt.bittrex()
    df = bittrex.fetchTicker('BTC/USDT')
    df.pop('info')
    df1 = [df]

    cursor.execute(
        "insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('bittrex',"
        + str(df['high']) + "," + str(df['low']) + "," + str(df['last']) +
        "," + str(df['timestamp']) + "," + str(df['bid']) + "," +
        str(df['ask']) + ")")
    con.commit()

    cursor = con.cursor()
    hitbtc = ccxt.hitbtc()
    df = hitbtc.fetchTicker('BTC/USDT')
    df.pop('info')
    df1 = [df]

    cursor.execute(
        "insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('hitbtc',"
        + str(df['high']) + "," + str(df['low']) + "," + str(df['last']) +
        "," + str(df['timestamp']) + "," + str(df['bid']) + "," +
        str(df['ask']) + ")")
    con.commit()

    # cursor = con.cursor()
    # okex = ccxt.okex()
    # df = okex.fetchTicker('BTC/USD')
    # df.pop('info')
    # df1 = [df]

    # cursor.execute("insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('okex',"+str(df['high'])+","+str(df['low'])+","+str(df['last'])+","+str(df['timestamp'])+","+str(df['bid'])+","+str(df['ask'])+ ")")
    # con.commit()

    # cursor = con.cursor()
    # deribit = ccxt.deribit()
    # df = deribit.fetchTicker('BTC/USD')
    # df.pop('info')
    # df1 = [df]

    # cursor.execute("insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('deribit',"+str(df['high'])+","+str(df['low'])+","+str(df['last'])+","+str(df['timestamp'])+","+str(df['bid'])+","+str(df['ask'])+ ")")
    # con.commit()

    # cursor = con.cursor()
    # acx = ccxt.acx()
    # df = acx.fetchTicker('BTC/USDT')
    # df.pop('info')
    # df1 = [df]

    # cursor.execute("insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('acx',"+str(df['high'])+","+str(df['low'])+","+str(df['last'])+","+str(df['timestamp'])+","+str(df['bid'])+","+str(df['ask'])+ ")")
    # con.commit()

    cursor = con.cursor()
    bitstamp = ccxt.bitstamp()
    df = bitstamp.fetchTicker('BTC/USD')
    df.pop('info')
    df1 = [df]

    cursor.execute(
        "insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('bitstamp',"
        + str(df['high']) + "," + str(df['low']) + "," + str(df['last']) +
        "," + str(df['timestamp']) + "," + str(df['bid']) + "," +
        str(df['ask']) + ")")
    con.commit()

    # cursor = con.cursor()
    # gemini = ccxt.gemini()
    # df = gemini.fetchTicker('BTC/USD')
    # df.pop('info')
    # df1 = [df]

    # cursor.execute("insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('gemini',"+str(df['high'])+","+str(df['low'])+","+str(df['last'])+","+str(df['timestamp'])+","+str(df['bid'])+","+str(df['ask'])+ ")")
    # con.commit()

    cursor = con.cursor()
    binance = ccxt.binance()
    df = binance.fetchTicker('BTC/USDT')
    df.pop('info')
    df1 = [df]

    cursor.execute(
        "insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('binance',"
        + str(df['high']) + "," + str(df['low']) + "," + str(df['last']) +
        "," + str(df['timestamp']) + "," + str(df['bid']) + "," +
        str(df['ask']) + ")")
    con.commit()

    # cursor = con.cursor()
    # qryptos = ccxt.qryptos()
    # df = qryptos.fetchTicker('BTC/USDT')
    # df.pop('info')
    # df1 = [df]

    # cursor.execute("insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('qryptos',"+str(df['high'])+","+str(df['low'])+","+str(df['last'])+","+str(df['timestamp'])+","+str(df['bid'])+","+str(df['ask'])+ ")")
    # con.commit()

    # cursor = con.cursor()
    # huobi = ccxt.huobi()
    # df = huobi.fetchTicker('BTC/USDT')
    # df.pop('info')
    # df1 = [df]

    # cursor.execute("insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('huobi',"+str(df['high'])+","+str(df['low'])+","+str(df['last'])+","+str(df['timestamp'])+","+str(df['bid'])+","+str(df['ask'])+ ")")
    # con.commit()

    cursor = con.cursor()
    cex = ccxt.cex()
    df = cex.fetchTicker('BTC/USD')
    df.pop('info')
    df1 = [df]

    cursor.execute(
        "insert into exchanges(exchangeName,high,low,last,timestamp,bid,ask) values('cex',"
        + str(df['high']) + "," + str(df['low']) + "," + str(df['last']) +
        "," + str(df['timestamp']) + "," + str(df['bid']) + "," +
        str(df['ask']) + ")")
    con.commit()
    return "data inserted"
예제 #15
0
def create_exchanges():
    """
        instantiate the markets
        to include more exchanges use this function.
        new exchanges need to be hand-coded here
    """
    coinbasepro = ccxt.coinbasepro({
        'apiKey': api_keys.coinbasepro['apiKey'],
        'secret': api_keys.coinbasepro['secret'],
        'enableRateLimit': True,
    })

    cex = ccxt.cex({
        'apiKey': api_keys.cex['apiKey'],
        'secret': api_keys.cex['secret'],
        'enableRateLimit': True,
    })

    poloniex = ccxt.poloniex({
        'apiKey': api_keys.poloniex['apiKey'],
        'secret': api_keys.poloniex['secret'],
        'enableRateLimit': True,
    })

    bittrex = ccxt.bittrex({
        'apiKey': api_keys.bittrex['apiKey'],
        'secret': api_keys.bittrex['secret'],
        'enableRateLimit': True,
    })

    binance = ccxt.binance({
        'apiKey': api_keys.binance['apiKey'],
        'secret': api_keys.binance['secret'],
        'enableRateLimit': True,
    })

    bitfinex = ccxt.bitfinex({
        'apiKey': api_keys.bitfinex['apiKey'],
        'secret': api_keys.bitfinex['secret'],
        'enableRateLimit': True,
    })

    kucoin = ccxt.kucoin({
        'apiKey': api_keys.kucoin['apiKey'],
        'secret': api_keys.kucoin['secret'],
        'enableRateLimit': True,
    })

    kraken = ccxt.kraken({
        'apiKey': api_keys.kraken['apiKey'],
        'secret': api_keys.kraken['secret'],
    'enableRateLimit': True,
        })

    bitmex = ccxt.bitmex({
        'apiKey': api_keys.bitmex['apiKey'],
        'secret': api_keys.bitmex['secret'],
        'enableRateLimit': True,
    })

    okex = ccxt.okex({
        'apiKey': api_keys.okex['apiKey'],
        'secret': api_keys.okex['secret'],
        'enableRateLimit': True,
    })

    # exchanges = [coinbasepro, poloniex, bittrex, binance, bitfinex, kucoin, bitmex, okex]
    exchanges =     [cex, poloniex, bittrex, binance, bitfinex, kucoin, bitmex, coinbasepro]
    timing_limits = [.35,      .35,       1,     .35,        2,        1,      1,    .35]  # requesting period limit per exchange

    for exchange, timing in zip(exchanges, timing_limits):
        g_storage.timer[exchange.name] = [0, timing]

    # exchanges.pop(exchanges.index(kraken))

    return exchanges
예제 #16
0
import matplotlib.pyplot as plt
import ccxt

pair = 'XRP/BTC'
gateways = [
    ccxt.cex(),
    ccxt.poloniex(),
    ccxt.binance(),
    ccxt.kraken(),
    ccxt.bitfinex2()
]


def percentage(percent, whole) -> float:
    return (percent * whole) / 100.0


def display_ticker(g, p):
    bid = 0
    volume = 0
    try:
        t = g.fetch_ticker(p)
        bid = float(t['bid'])
        volume = float(t['baseVolume'])
        plt.annotate(g.id, (bid, volume))
    except ccxt.ExchangeError as e:
        print(str(e))
    except KeyError as e:
        print('pair', str(e), 'not available for', g.id)
    return bid, volume
    'exchangeName': "gemini",
    'database': gemini_db
})

tidex = ccxt.tidex({
    'rateLimit': 3000,
    'enableRateLimit': True,
    # 'verbose': True,
    'exchangeName': "tidex",
    'database': tidex_db
})

cex = ccxt.cex({
    'rateLimit': 3000,
    'enableRateLimit': True,
    # 'verbose': True,
    'exchangeName': "cex",
    'database': cex_db
})


def koineks_ticker(currency):
    # To use this function, instead of calling a currency pair, just use BTC, ETH, XLM, LTC, DASH,XRP,DOGE

    # Because of pair api response is different than other api calls, there is another dict called koineks_pair to normalize it.

    try:
        exchange = {'database': koineks_db, 'name': 'koineks'}
        data = requests.get('https://koineks.com/ticker')
        high = data.json()[currency]['high']
        low = data.json()[currency]['low']
# -*- coding: utf-8 -*-

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  # noqa: E402

# return up to ten bidasks on each side of the order book stack
limit = 10
print(ccxt.cex().fetch_order_book('BTC/USD', limit))