def executeTrades(token): """ carries out the trades identified and specified in checkArbitrage(token) Flooring and rounding is used in the quantity calculations so as to make sure that the amount matches the step size and minimum quantities required by binance for the given asset """ binance.marketBuy("ETHUSDT", binance.BUY, round(math.floor(100000*int(float(binance.balances()["USDT"]['free'])))*1/float(binance.prices()["ETHUSDT"]) / 100000, 5), test=False) binance.marketBuy(token+"ETH", binance.BUY, math.floor((10**getDigits(token)*int(float(binance.balances()["ETH"]['free'])*1/float(binance.prices()[token+"ETH"]))))/(10**getDigits(token)), test=False) binance.marketBuy(token+"BTC", binance.SELL, math.floor((10**getDigits(token))*float(binance.balances()[token]["free"]))/(10**getDigits(token)), test=False) binance.marketBuy("BTCUSDT", binance.SELL, math.floor(float(binance.balances()["BTC"]['free'])*1000000) / 1000000, test=False) # precision will always be 10^6 for BTC
def main(): """main function""" config.create_config() binance_auth() if len(sys.argv) > 1 and sys.argv[1] == '--help': print("Test binance authentication using config creds") sys.exit(0) try: binance.balances() print("Success") except ValueError: sys.exit("Auth Error")
def testforNumberErrors(): list = binance.balances() for sym in list: if (sym == "USDT" or sym == "BTC"): continue sym = sym + "BTC" pof = float(binance.prices()[sym]) if (btcBalance < pof): are = float( main.calcAmountNeeded(pof, btcBalance, constants.PERCENT)) are = des(are, TRUNCATE, 3, DECIMAL_PLACES) else: are = int(main.calcAmountNeeded(pof, btcBalance, constants.PERCENT)) try: pof = des(pof, TRUNCATE, 8, DECIMAL_PLACES) binance.order(sym, binance.BUY, are, pof, binance.LIMIT, binance.GTC, test=True) except Exception as e: print(e) print(sym) finally: time.sleep(1) print(sym) return
def get_balances(): balances = binance.balances() prices = binance.prices() epoch = time.time() data_balances = {"balances": balances, "date": epoch} data_prices = {"prices": prices, "date": epoch} balancesCollection.insert_one(data_balances) pricesCollection.insert_one(data_prices) print("inserted data")
#this is a bridge between binance api and lpmbot. please write binance API details in here #https://github.com/toshima/binance this is the link to the binance api i`m using import binance import sys binance.set("API", "SECRET") # api first and then secret if sys.argv[ 1 ] == ("prices"): print(binance.prices()) elif sys.argv[ 1 ] == ("balances"): print(binance.balances()) else: print ("Please write a valid argument")
def binance_summary(): # instead of having the API in the script..not a perfect solution sign_key, sign_SECRET = get_credentials('binance_api') api_info = { 'sign_key': sign_key, 'sign_SECRET': sign_SECRET, 'sign_id': 'anyone', 'coin_symbol': 'ZEC', } binance.set(api_info['sign_key'], api_info['sign_SECRET']) relation = {'ZEC': 'ZECBTC', 'BTC': 'BTCUSDT'} prices = binance.prices() balances = binance.balances() btc_price = float(prices['BTCUSDT']) # print ("The current Bitcoin price is $ {0:.2f}").format(btc_price) print # print float(prices['ZECBTC']) # cycle thru all coins balances for key in balances.keys(): # if balance is greater than 0, display balance info if float(balances[key]['free']) > 0: # determine 'free' balance balance_coin = float(balances[key]['free']) # handle BTC different because other coins are based on BTC if key == 'BTC': # determine the coins current price coin_price = float(prices[relation[key]]) # calculate the coin balance in USD balance_usd = balance_coin * float(prices[relation[key]]) # display information to screen template = ("The {0} price is currently $ {1:.2f}") print template.format(key, coin_price) else: # calculate the price of the coin in USD not BTC coin_price = float(prices[relation[key]]) * btc_price # calculate the coin balance in USD balance_usd = (float(prices[relation[key]]) * balance_coin * btc_price) # display information to screen template = ("The {0} price is currently $ {1:.2f}") print template.format(key, coin_price) print("\n\tYour {0} balance is {1}").format(key, balance_coin) print("\tYour {0} balance is worth $ {1:.2f}".format( key, balance_usd)) print
import main from ccxt.base.decimal_to_precision import decimal_to_precision as des from ccxt.base.decimal_to_precision import TRUNCATE from ccxt.base.decimal_to_precision import DECIMAL_PLACES #import asyncio import datetime import matplotlib import binance api_key = 'fpbbveGPWhP0r0ozRpfMdKkMfwhD1J6lGBVpzqIZW3IcA7NQ06kYT9p9uF37nCXz' secret = 'gUie4OPO6F3O1IME54dOMQdiMraQHRmC9H3qfA9p4zunPUl9iRpCOOJ3dhJybl1n' binance.set(api_key, secret) # setting up btcBalance = float( binance.balances()["BTC"]['free']) # reterives my btc balance print("Your bitcoin balance is %s" % btcBalance) # my btc balance def testforNumberErrors(): list = binance.balances() for sym in list: if (sym == "USDT" or sym == "BTC"): continue sym = sym + "BTC" pof = float(binance.prices()[sym]) if (btcBalance < pof): are = float( main.calcAmountNeeded(pof, btcBalance, constants.PERCENT)) are = des(are, TRUNCATE, 3, DECIMAL_PLACES)
from ccxt.base.decimal_to_precision import TRUNCATE from ccxt.base.decimal_to_precision import DECIMAL_PLACES #import asyncio import datetime import matplotlib import binance api_key = 'add api key' secret = 'add secrect' binance.set(api_key, secret) # setting up boughtCryptos = {} # reterives my btc balance btcBalance = float(binance.balances()["BTC"]['free']) print("Your bitcoin balance is %s" % btcBalance) # my btc balance symbol = input("what currency") + "BTC" # symbol of first symbol = symbol.upper() print(symbol) # dec.decimal_to_precision() priceOfWanted = float(binance.prices()[symbol]) # how much coin->btc is worth print(priceOfWanted) # binance.or # binance.order(symbol,binance.BUY,) #exchange.enableRateLimit = True
#calculating profit is percentage profit = ((current_price / avg_bought_price) - 1) * 100 # print "%s profit is "%market_type + str(profit) +str(" %") if market_type not in summary: summary.append(market_type) if profit not in profit_list: #problem : this makes error if prices changes very quickly! profit_list.append(profit) return market_type, profit except ZeroDivisionError as Zero_Division_Error: return str("Try_different_market") balance_data = b.balances() for coin_type in balance_data: if float(balance_data["%s" % coin_type]['free']) >= float( 0.000001) or float( balance_data["%s" % coin_type]['locked']) >= float( 0.000001): # if there are some amount to the coin_type coin_type_BTC = str("%sBTC") % coin_type if coin_type_BTC == "BTCBTC": continue coin_type_BTC_data = profit_calculator(coin_type_BTC) if coin_type_BTC_data == "Try_different_market": coin_type_ETH = str("%sETH") % coin_type if coin_type_ETH == "ETHETH": continue
def get_binance_values(): """Get totals for each crypto from binance and convert to USD/GBP""" mydict = lambda: defaultdict(mydict) result = mydict() binance_auth() all_balances = binance.balances() prices = binance.prices() bitcoin_totals = 0 gbp_total = 0 usd_total = 0 currency = CurrencyRates() for key in all_balances: current_value = float(all_balances[key]["free"]) + float( all_balances[key]["locked"]) if float(current_value) > 0: # available currency result["binance"][key]["count"] = current_value if key == "BTC": bcoin = float(current_value) bitcoin_totals += float(bcoin) elif key == "USDT": bcoin = float(current_value) / float(prices["BTCUSDT"]) bitcoin_totals += bcoin else: # other currencies that need converting to BTC try: bcoin = float(current_value) * float( prices[key + "BTC"]) # value in BTC bitcoin_totals += bcoin except KeyError: LOGGER.critical("Error: Unable to quantify currency: %s ", key) continue add_value(key, bcoin) usd2gbp = lambda: currency.get_rate("USD", "GBP") usd = bcoin * float(prices["BTCUSDT"]) gbp = usd2gbp() * usd usd_total += usd gbp_total += gbp result["binance"][key]["BTC"] = bcoin result["binance"][key]["USD"] = usd result["binance"][key]["GBP"] = gbp usd_total = bitcoin_totals * float(prices["BTCUSDT"]) result["binance"]["TOTALS"]["BTC"] = bitcoin_totals result["binance"]["TOTALS"]["USD"] = usd_total result["binance"]["TOTALS"]["count"] = "" for _ in range(3): # Try to get exchange rate 3 times before giving up try: gbp_total = currency.get_rate("USD", "GBP") * usd_total except RatesNotAvailableError: continue break result["binance"]["TOTALS"]["GBP"] = gbp_total add_value("USD", usd_total) add_value("GBP", gbp_total) return default_to_regular(result)