def order_book_sell(self, coin, fillamount): #TO SELL CRYPTO # coinspot requires API key for all requests if self.name == 'coinspot': coinspot = ccxt.coinspot() coinspot.apiKey = '88cfb4705e658dea85ed0f580b40a4ce' coinspot.secret = 'KTGVNEK33Q85FBKUQA02AVLEE7B0JHK5G25XNCZZ29F80H1T2M6ETAVCMMB8HT9YXL1ELCRNU2VG3PPVW' orde = exchanges[self.name].fetch_order_book(coin + '/' + self.nativeCurrency, limit=1000) print(orde['bids']) totalfilled = 0 totalpaid = 0 i = 0 while totalfilled <= fillamount: if i < len(orde['bids']): price = orde['bids'][i][0] amount = orde['bids'][i][1] totalfilled += amount totalpaid += price * amount i += 1 else: totalpaid = totalpaid * 2 break if totalfilled > fillamount: totalpaid -= orde['bids'][i - 1][0] * (totalfilled - fillamount) print(totalpaid) return (totalpaid / fillamount)
def order_book_sell(self, coin, fillamount): #TO SELL CRYPTO # coinspot requires API key for all requests if self.name == 'coinspot': coinspot = ccxt.coinspot() coinspot.apiKey = config.coinspot_api_key coinspot.secret = config.coinspot_secret orde = exchanges[self.name].fetch_order_book(coin + '/' + self.nativeCurrency, limit=1000) print(orde['bids']) totalfilled = 0 totalpaid = 0 i = 0 while totalfilled <= fillamount: if i < len(orde['bids']): price = orde['bids'][i][0] amount = orde['bids'][i][1] totalfilled += amount totalpaid += price * amount i += 1 else: totalpaid = totalpaid * 2 break if totalfilled > fillamount: totalpaid -= orde['bids'][i - 1][0] * (totalfilled - fillamount) print(totalpaid) return (totalpaid / fillamount)
def update(self): print('Updating the prices at: ' + self.name + ' ...') # Each exchange requires a different method for getting the prices so we must go case by case if self.name == 'coinspot': #Coinspot requires a key to access the public api coinspot = ccxt.coinspot() coinspot.apiKey = '88cfb4705e658dea85ed0f580b40a4ce' coinspot.secret = 'KTGVNEK33Q85FBKUQA02AVLEE7B0JHK5G25XNCZZ29F80H1T2M6ETAVCMMB8HT9YXL1ELCRNU2VG3PPVW' response = requests.get( "https://www.coinspot.com.au/pubapi/latest") coinspotresponse = response.json() for i, coin in enumerate(settings.Coins): try: temp = coinspotresponse['prices'][str.lower(coin)] self.sellAsks[i] = float(temp['ask']) #sell asks self.buyBids[i] = float(temp['bid']) # buy bids self.successfullyLoaded[i] = 1 except: self.sellAsks[i] = 1000000 self.buyBids[i] = .001 elif self.name == 'coinspot nominal': cs = coinspotscrape.coinspotscrape() for i, coin in enumerate(settings.Coins): try: self.sellAsks[i] = cs.bid(coin) self.buyBids[i] = cs.ask(coin) self.successfullyLoaded[i] = 1 except: self.sellAsks[i] = 1000000 self.buyBids[i] = .001 elif self.name == 'coinjar': for i, coin in enumerate(settings.Coins): response = requests.get( "https://api.coinjar.com/v3/exchange_rates.json") datacoin = response.json() try: temp = datacoin['exchange_rates'][coin + self.nativeCurrency] self.sellAsks[i] = float(temp['ask']) self.buyBids[i] = float(temp['bid']) self.successfullyLoaded[i] = 1 except: self.sellAsks[i] = 1000000 self.buyBids[i] = .001 else: print('Exchange not found')
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
ccxt.cex(), ccxt.chbtc(), ccxt.chilebit(), ccxt.cobinhood(), ccxt.coincheck(), ccxt.coinegg(), ccxt.coinex(), ccxt.coinexchange(), ccxt.coinfloor(), ccxt.coingi(), ccxt.coinmarketcap(), ccxt.coinmate(), ccxt.coinnest(), ccxt.coinone(), ccxt.coinsecure(), ccxt.coinspot(), ccxt.coolcoin(), ccxt.cryptopia(), ccxt.dsx(), ccxt.ethfinex(), ccxt.exmo(), ccxt.exx(), ccxt.flowbtc(), ccxt.foxbit(), ccxt.fybse(), ccxt.fybsg(), ccxt.gatecoin(), ccxt.gateio(), ccxt.gdax(), ccxt.gemini(), ccxt.getbtc(),