Exemplo n.º 1
0
def accountHistory(client, symb) -> bool:

	try:
		tradeHist = client.get_my_trades(symbol=symb, recvWindow = BU.getRecvWindow())
	except Exception as e:
		print(f"Erro at client.get_my_trades(symbol={symb}): {e}")
		return False

	tradeHistTot = len(tradeHist)

	if BU.getExportXLS() == True:
		BP.printTradeHistoryXLSHEADER()
		[BP.printTradeHistoryXLS(n) for n in tradeHist]
	else:
		print(f"Trade history {symb}:")
		[BP.printTradeHistory(n, i, tradeHistTot) for i, n in enumerate(tradeHist, 1)]

	print(f"All trade history {symb}:")

	try:
		tradeAllHist = client.get_all_orders(symbol=symb, recvWindow = BU.getRecvWindow())
	except Exception as e:
		print(f"Erro at client.get_all_orders(symbol={symb}): {e}")
		return False

	tradeAllHistTot = len(tradeAllHist)

	if BU.getExportXLS() == True:
		BP.printTradeAllHistXLSHEADER()
		[BP.printTradeAllHistXLS(n) for n in tradeAllHist]
	else:
		print(f"Trade history [{symb}]:")
		[BP.printTradeAllHist(n, i, tradeAllHistTot) for i, n in enumerate(tradeAllHist, 1)]

	try:
		allDust = client.get_dust_log(recvWindow = BU.getRecvWindow())
	except BinanceWithdrawException as e:
		print(f"Erro at client.get_dust_log() BinanceWithdrawException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_dust_log(): {e}")
		return False

	allDustTot = len(allDust['results']['rows'])

	if BU.getExportXLS() == True:
		print("============== UNDERCONSTRUCTION ==========================")
	else:
		print("Log of small amounts exchanged for BNB:")
		[BP.printDustTrade(n, i, allDustTot) for i, n in enumerate(allDust['results']['rows'], 1)]

	return True
Exemplo n.º 2
0
def depositAddress(client, ass) -> bool:

	try:
		depAdd = client.get_deposit_address(asset = ass, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_deposit_address() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_deposit_address() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_deposit_address(): {e}")
		return False

	if BU.getExportXLS() == True:

		BP.printDepositAddressXLSHEADER()
		BP.printDepositAddressXLS(depAdd)

	else:
		print(f"Deposit Address for [{ass}]")
		BP.printDepositAddress(depAdd)

	return True
Exemplo n.º 3
0
def depositHistory(client, ass = '') -> bool:

	try:
		deposits = client.get_deposit_history(asset = ass, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_deposit_history() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_deposit_history() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_deposit_history(): {e}")
		return False

	if BU.getExportXLS() == True:

		BP.printDepositHistoryXLSHEADER()
		[BP.printDepositHistoryXLS(n) for n in deposits['depositList']]

	else:

		print(f"Deposit History for [{ass}]")
		[BP.printDepositHistory(n) for n in deposits['depositList']]

	return True
Exemplo n.º 4
0
def withdrawHistory(client, ass = '') -> bool:

	try:
		withdraw = client.get_withdraw_history(asset = ass, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_withdraw_history() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_withdraw_history() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_withdraw_history(): {e}")
		return False

	if BU.getExportXLS() == True:

		BP.printWithdrawHistoryXLSHEADER()
		[BP.printWithdrawHistoryXLS(n) for n in withdraw['withdrawList']]

	else:

		print("Withdraw History")
		[BP.printWithdrawHistory(n) for n in withdraw['withdrawList']]

	return True
Exemplo n.º 5
0
def infoSymbol(client, symb, interv, candlesTot) -> bool:

	try:
		sumbPrc = client.get_klines(symbol = symb, interval = BU.binanceInterval(interv), limit = candlesTot, recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_klines() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_klines() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_klines(): {e}")
		return False

	if sumbPrc is None:
		return False

	if BU.getExportXLS() == True:
		BP.printInfoSymbolValuesXLSHEADER()
		[BP.printInfoSymbolValuesXLS(n) for n in sumbPrc]
	else:
		print(f"Symbol [{symb}] in interval [{interv}]");
		totsumbPrc = len(sumbPrc)
		[BP.printInfoSymbolValues(n, i, totsumbPrc) for i, n in enumerate(sumbPrc, 1)]

	return True
Exemplo n.º 6
0
def subAccountTransferHistory(client, em: str = "") -> bool:

	try:
		sath = client.get_sub_account_transfer_history(email = em, recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_sub_account_transfer_history() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_sub_account_transfer_history() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_sub_account_transfer_history(): {e}")
		return False

	if sath['success'] == True:

		if BU.getExportXLS() == True:
			BP.printsubAccountTransferHistoryXLSHEADER()
			[BP.printsubAccountTransferHistoryXLS(n) for n in sath['transfers']]
		else:
			totSath = len(sath['transfers'])
			print("Sub account(s) transfer history:")
			[BP.printsubAccountTransferHistory(n, i, totSath) for i, n in enumerate(sath['transfers'], 1)]
	else:
		print(f"Sub accounts transfer history returned: [{sath['msg']}]")

	return True
Exemplo n.º 7
0
def marginSymbInfo(client, symb = '') -> bool:

	try:
		mi = client.get_margin_symbol(symbol = symb, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_margin_symbol() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_margin_symbol() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_margin_symbol(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Symbol\tQuote\tBase\tId\tIs Buy Allowed\tIs Margin Trade\tIs Sell Allowed")
		print(f"{mi['symbol']}\t{mi['quote']}\t{mi['base']}\t{mi['id']}\t{mi['isBuyAllowed']}\t{mi['isMarginTrade']}\t{mi['isSellAllowed']}")

	else:
		print(f"Margin symbol info [{symb}]\n")

		print(f"Symbol.........: [{mi['symbol']}]")
		print(f"Quote..........: [{mi['quote']}]")
		print(f"Base...........: [{mi['base']}]")
		print(f"Id.............: [{mi['id']}]")
		print(f"Is Buy Allowed.: [{mi['isBuyAllowed']}]")
		print(f"Is Margin Trade: [{mi['isMarginTrade']}]")
		print(f"Is Sell Allowed: [{mi['isSellAllowed']}]")

	return True
Exemplo n.º 8
0
def listSymbolsRateLimits(client) -> bool:

	try:
		ei = client.get_exchange_info()
	except BinanceAPIException as e:
		print(f"Erro at client.get_exchange_info() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_exchange_info() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_exchange_info(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Rate Limits")
		BP.printListRateLimitXLSHEADER()
		[BP.printListRateLimitXLS(n) for n in ei['rateLimits']]

		print("\nSymbols")
		BP.printListSymbolsXLSHEADER()
		[BP.printListSymbolsXLS(n) for n in ei['symbols']]

	else:
		print("Rate Limits:")
		totei = len(ei['rateLimits'])
		[BP.printListRateLimit(n, i, totei) for i, n in enumerate(ei['rateLimits'], 1)]

		print("Symbols:")
		totei = len(ei['symbols'])
		[BP.printListSymbols(n, i, totei) for i, n in enumerate(ei['symbols'], 1)]

	return True
Exemplo n.º 9
0
def binanceInfo(client) -> bool:

	try:
		sst = client.get_system_status()
	except BinanceAPIException as e:
		print(f"Erro at client.get_system_status() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False

	try:
		st = client.get_server_time()
	except BinanceRequestException as e:
		print(f"Erro at client.get_server_time() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except BinanceAPIException as e:
		print(f"Erro at client.get_server_time() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_server_time(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Server Status")
		BP.printSystemStatusXLS(sst)

		print("\nTime")
		BP.printServerTimeXLS(st)

	else:
		print("Server Status:")
		BP.printSystemStatus(sst)

		print("")
		BP.printServerTime(st)

	return True
Exemplo n.º 10
0
def marginSymbPriceIndex(client, symb = '') -> bool:

	try:
		mp = client.get_margin_price_index(symbol = symb, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_margin_price_index() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_margin_price_index() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_margin_price_index(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Symbol\tPrice\tTime")
		print(f"{mp['symbol']}\t{mp['price']}\t{BU.completeMilliTime(mp['calcTime'])}")

	else:
		print(f"Margin symbol price index [{symb}]\n")

		print(f"Price: [{mp['price']}]")
		print(f"Time.: [{BU.completeMilliTime(mp['calcTime'])}]")

	return True
Exemplo n.º 11
0
def marginOpenOrders(client) -> bool:

	try:
		openMarginOrders = client.get_open_margin_orders(recvWindow = BU.getRecvWindow())
	except BinanceRequestException as e:
		print(f"Erro at client.get_open_margin_orders() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except BinanceAPIException as e:
		print(f"Erro at client.get_open_margin_orders() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_open_margin_orders(): {e}")
		return False

	totOpenMarginOrder = len(openMarginOrders)

	if totOpenMarginOrder != 0:

		if BU.getExportXLS() == True:

			BP.printMarginOrderXLSHEADER()
			[BP.printMarginOrderXLS(n) for n in openMarginOrders]

		else:

			if   totOpenMarginOrder == 1: print("Margin open order:")
			elif totOpenMarginOrder <  1: print(f"Margin open orders ({totOpenMarginOrder}):")

			[BP.printMarginOrder(n, i, totOpenMarginOrder) for i, n in enumerate(openMarginOrders, 1)]
	else:
		print('No margin open orders')

	return True
Exemplo n.º 12
0
def orderBook(client, symb = '', lim = 1000) -> bool:

	try:
		ob = client.get_order_book(symbol = symb, limit = lim, recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_order_book() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_order_book() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_order_book(): {e}")
		return False

	if BU.getExportXLS() == True:
		print(f"Update id\t{ob['lastUpdateId']}")
		BP.printOrderBookXLSHEADER()
		[BP.printOrderBookXLS(n) for n in zip(ob['bids'], ob['asks'])]

	else:
		print(f"Order Book: [{symb}]\n")
		print(f"(Update id: [{ob['lastUpdateId']}])")
		print("\tBids\t\t\t|\t\tAsks")
		print("Qtd\t\tPrice\t\t|\tPrice\t\tQtd")
		[BP.printOrderBook(n) for n in zip(ob['bids'], ob['asks'])]

	return True
Exemplo n.º 13
0
def infoDetailsSymbol(client, symb) -> bool:

	try:
		si = client.get_symbol_info(symb)
	except BinanceAPIException as e:
		print(f"Erro at client.get_symbol_info() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_symbol_info() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_symbol_info(): {e}")
		return False

	if si is None:
		return False

	if BU.getExportXLS() == True:
		BP.printListSymbolsXLSHEADER()
		BP.printListSymbolsXLS(si)

	else:
		print("Symbol: [{symb}]")
		BP.printListSymbols(si)

	return True
Exemplo n.º 14
0
def bookTicker(client, symb = '') -> bool:

	try:
		bt = client.get_orderbook_ticker(symbol = symb, recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_orderbook_ticker() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_orderbook_ticker() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_orderbook_ticker(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Symbol\tBid Price\tBid Qty\tAsk Price\tAsk Qty")
		print(f"{bt['symbol']}\t{bt['bidPrice']}\t{bt['bidQty']}\t{bt['askPrice']}\t{bt['askQty']}")

	else:
		print(f"Latest ticker/price for [{symb}] symbol\n")

		print(f"Symbol...: [{bt['symbol']}]")
		print(f"Bid Price: [{bt['bidPrice']}]")
		print(f"Bid Qtd..: [{bt['bidQty']}]")
		print(f"Ask Price: [{bt['askPrice']}]")
		print(f"Ask Qtd..: [{bt['askQty']}]")

	return True
Exemplo n.º 15
0
def marginAsset(client, ass = '') -> bool:

	try:
		mo = client.get_margin_asset(asset = ass, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_margin_asset() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_margin_asset() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_margin_asset(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Full Name\tName\tIs Borrowable\tIs Mortgageable\tUser Minimum Borrow\tUser Minimum Repay")
		print(f"{mo['assetFullName']}\t{mo['assetName']}\t{mo['isBorrowable']}\t{mo['isMortgageable']}\t{mo['userMinBorrow']}\t{mo['userMinRepay']}")
	else:
		print(f"Query margin asset [{ass}]")

		print(f"Name...............: [{mo['assetName']}]")
		print(f"Full name..........: [{mo['assetFullName']}]")
		print(f"Is borrowable......? [{mo['isBorrowable']}]")
		print(f"Is mortageable.....? [{mo['isMortgageable']}]")
		print(f"User minimum borrow: [{mo['userMinBorrow']}]")
		print(f"User monimum repay.: [{mo['userMinRepay']}]")

	return True
Exemplo n.º 16
0
def olderTrades(client, ass = '') -> bool:

	try:
		th = client.get_historical_trades(symbol = ass, limit = 500, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_historical_trades() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_historical_trades() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_historical_trades(): {e}")
		return False

	if BU.getExportXLS() == True:
		BP.printHistoricalTradesXLSHEADER()
		[BP.printHistoricalTradesXLS(n) for n in th]
	else:
		print("500 older trades for [{ass}]")

		thTot = len(th)
		[BP.printHistoricalTrades(n, i, thTot) for i, n in enumerate(th, 1)]

	return True
Exemplo n.º 17
0
def marginTrades(client, symb = '', fromordid = '', lim = '1000') -> bool:

	try:
		mt = client.get_margin_trades(symbol = symb, fromId = fromordid, limit = lim, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_margin_trades() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_margin_trades() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_margin_trades(): {e}")
		return False

	mttot = len(mt)

	if BU.getExportXLS() == True:
		BP.printMarginTradesXLSHEADER()
		[BP.printMarginTradesXLS(n) for n in mt]
	else:
		if fromordid == '':
			print(f"Margin accounts trades [{symb}] (limit: [{lim}]).")
		else:
			print(f"Margin accounts trades from order id [{fromordid}] for symbol [{symb}] (limit: [{lim}]).")

		[BP.printMarginTrades(n, i, mttot) for i, n in enumerate(mt, 1)]

	return True
Exemplo n.º 18
0
def subAccountsList(client) -> bool:

	try:
		sal = client.get_sub_account_list(recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_sub_account_list() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_sub_account_list() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_sub_account_list(): {e}")
		return False

	totSal = len(sal['subAccounts'])

	if sal['success'] == True and totSal > 0:

		if BU.getExportXLS() == True:
			BP.printsubAccountsListXLSHEADER()
			[BP.printsubAccountsListXLS(n) for n in sal['subAccounts']]
		else:
			print("Sub account(s):")
			[BP.printsubAccountsList(n, i, totSal) for i, n in enumerate(sal['subAccounts'], 1)]
	else:
		print("There are no sub accounts.")

	return True
Exemplo n.º 19
0
def allMarginOrders(client, symb = '', ordid = '', lim = '1000') -> bool:

	try:
		mo = client.get_all_margin_orders(symbol = symb, orderId = ordid, limit = lim, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_all_margin_orders() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_all_margin_orders() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_all_margin_orders(): {e}")
		return False

	motot = len(mo)

	if BU.getExportXLS() == True:
		BP.printTradeAllHistXLSHEADER()
		[BP.printTradeAllHistXLS(n) for n in mo]
	else:
		if ordid == '':
			print(f"All margin accounts orders for symbol [{symb}] (limit: [{lim}]).")
		else:
			print(f"Margin accounts order [{ordid}] for symbol [{symb}] (limit: [{lim}]).")

		[BP.printTradeAllHist(n, i, motot) for i, n in enumerate(mo, 1)]

	return True
Exemplo n.º 20
0
def subAccountsAssets(client, em: str = "", symb: str = "") -> bool:

	try:
		saa = client.get_sub_account_assets(email = em, symbol = symb, recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_sub_account_assets() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_sub_account_assets() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_sub_account_assets(): {e}")
		return False

	if saa['success'] == True:

		if BU.getExportXLS() == True:
			BP.printsubAccountsAssetsXLSHEADER()
			[BP.printsubAccountsAssetsXLS(n) for n in saa['balances']]
		else:
			print("Sub account(s):")
			totSaa = len(saa['balances'])
			[BP.printsubAccountsAssets(n, i, totSaa) for i, n in enumerate(saa['balances'], 1)]
	else:
		print(f"Sub accounts assets returned: [{saa['msg']}]")

	return True
Exemplo n.º 21
0
def accountDetails(client) -> bool:

	try:
		assDet = client.get_asset_details(recvWindow = BU.getRecvWindow())
		tradFee = client.get_trade_fee(recvWindow = BU.getRecvWindow())
	except BinanceWithdrawException as e:
		print(f"Erro get_asset_details and get_trade_fee BinanceWithdrawException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro get_asset_details and get_trade_fee: {e}")
		return False

	if BU.getExportXLS() == True:
		print('Details on Assets')
		BP.printDetailsAssetsXLSHEADER()
		[BP.printDetailsAssetsXLS(n, assDet['assetDetail'][n]) for n in assDet['assetDetail'].keys()]

		print('\nTrade Fee')
		BP.printTradeFeeXLSHEADER()
		[BP.printTradeFeeXLS(n) for n in tradFee['tradeFee']]

	else:
		print('Details on Assets:')
		adTot = len(assDet['assetDetail'])
		[BP.printDetailsAssets(n, assDet['assetDetail'][n], i, adTot) for i, n in enumerate(assDet['assetDetail'].keys(), 1)]

		print('Trade Fee:')
		adTot = len(tradFee['tradeFee'])
		[BP.printTradeFee(n, i, adTot) for i, n in enumerate(tradFee['tradeFee'], 1)]

	return True
Exemplo n.º 22
0
def averagePrice(client, symb = '') -> bool:

	try:
		pa = client.get_avg_price(symbol = symb)
	except BinanceAPIException as e:
		print(f"Erro at client.get_avg_price() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_avg_price() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_avg_price(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Symbol\tPrice\tMins")
		print(f"{symb}\t{pa['price']}\t{pa['mins']}")
	else:
		print("Current average price for a symbol")

		print(f"Symbol...: [{symb}]")
		print(f"Price....: [{pa['price']}]")
		print(f"Mins.....: [{pa['mins']}]")

	return True
Exemplo n.º 23
0
def balanceAccAsset(client, ass = '') -> bool:

	try:
		ba = client.get_asset_balance(asset = ass, recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_asset_balance() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_asset_balance() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_asset_balance(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Asset\tFree\tLocked")
		print(f"{ba['asset']}\t{ba['free']}\t{ba['locked']}")
	else:
		print(f"Account balance for asset [{ass}]")
		print(f"Asset.: [{ba['asset']}]")
		print(f"Free..: [{ba['free']}]")
		print(f"Locked: [{ba['locked']}]")

	try:
		bl = client.get_max_margin_loan(asset = ass, recvWindow = BU.getRecvWindow())
		bt = client.get_max_margin_transfer(asset = ass, recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_max_margin_loan()/get_max_margin_transfer() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_max_margin_loan()/get_max_margin_transfer() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_max_margin_loan()/get_max_margin_transfer(): {e}")
		return False

	if BU.getExportXLS() == True:
		print(f"Margin max borrow amount for {ass}\tMargin max transfer-out amount for {ass}")
		print(f"{bl['amount']}\t{bt['amount']}")
	else:
		print(f"Margin max borrow amount for [{ass}]......: [{bl['amount']}]")
		print(f"Margin max transfer-out amount for [{ass}]: [{bt['amount']}]")

	return True
Exemplo n.º 24
0
def orderSpotLimit(client, symbOrd = '', qtdOrd = 0, prcOrd = 0.0, prcStopOrd = 0.0, prcStopLimitOrd = 0.0, sideOrd = 0) -> [bool, str]:

	if BU.getExportXLS() == True:
		BU.errPrint("Symbol\tSide\tQuantity\tPrice\tStop Price\tLimit OCO")
		BU.errPrint(f"{symbOrd}\t{sideOrd}\t{qtdOrd}\t{prcOrd}\t{prcStopOrd}\t{prcStopLimitOrd}")
	else:
		print(f"Symbol....: [{symbOrd}]")
		print(f"Side......: [{sideOrd}]")
		print(f"Quantity..: [{qtdOrd}]")
		print(f"Price.....: [{prcOrd}]")
		print(f"Stop Price: [{prcStopOrd}]")
		print(f"Limit OCO.: [{prcStopLimitOrd}]")

	if BU.askConfirmation() == False:
		return True, "Cancelled by Confirmation!"

	# TESTING
	global LOCK
	if LOCK == True:
		return False, "Programmed flag order lock ON!"

	try:
		order = client.create_oco_order(symbol               = symbOrd,
		                                side                 = sideOrd,
		                                quantity             = qtdOrd,
		                                price                = prcOrd,
		                                stopPrice            = prcStopOrd,
												  stopLimitPrice       = prcStopLimitOrd,
		                                stopLimitTimeInForce = Client.TIME_IN_FORCE_GTC,
		                                newOrderRespType     = Client.ORDER_RESP_TYPE_FULL)

	except BinanceRequestException as e:
		return False, f"Erro create_oco_order BinanceRequestException: [{e.status_code} - {e.message}]"
	except BinanceAPIException as e:
		return False, f"Erro create_oco_order BinanceAPIException: [{e.status_code} - {e.message}]"
	except BinanceOrderException as e:
		return False, f"Erro create_oco_order BinanceOrderException: [{e.status_code} - {e.message}]"
	except BinanceOrderMinAmountException as e:
		return False, f"Erro create_oco_order BinanceOrderMinAmountException: [{e.status_code} - {e.message}]"
	except BinanceOrderMinPriceException as e:
		return False, f"Erro create_oco_order BinanceOrderMinPriceException: [{e.status_code} - {e.message}]"
	except BinanceOrderMinTotalException as e:
		return False, f"Erro create_oco_order BinanceOrderMinTotalException: [{e.status_code} - {e.message}]"
	except BinanceOrderUnknownSymbolException as e:
		return False, f"Erro create_oco_order BinanceOrderUnknownSymbolException: [{e.status_code} - {e.message}]"
	except BinanceOrderInactiveSymbolException as e:
		return False, f"Erro create_oco_order BinanceOrderInactiveSymbolException: [{e.status_code} - {e.message}]"
	except Expcetion as e:
		return False, f"Erro create_oco_order generic exception: {e}"

	printPlacedOrder(order)

	return True, "Ok"
Exemplo n.º 25
0
def withdrawRequest(client, ass = '', addr = '', amnt = 0) -> bool:

	if BU.getExportXLS() == True:
		print("Asset\tAddress\tAmount")
		print(f"{ass}\t{addr}\t{amnt}")
	else:
		print("Withdraw Request")

		print(f"Asset..: [{ass}]")
		print(f"Address: [{addr}]")
		print(f"Amount.: [{amnt}]")

	if BU.askConfirmation() == False:
		return False

	try:
		withdrawReq = client.withdraw(asset = ass, address = addr, amount = amnt)

	except BinanceRequestException as e:
		print(f"Erro at withdraw BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except BinanceAPIException as e:
		print(f"Erro at withdraw BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceWithdrawException as e:
		print(f"Erro at withdraw BinanceWithdrawException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at withdraw: {e}")
		return False

	if BU.getExportXLS() == True:
		BP.printWithdrawResponseXLSHEADER()
		BP.printWithdrawResponseXLS(withdrawReq)
	else:
		BP.printWithdrawResponse(withdrawReq)

	return True
Exemplo n.º 26
0
def orderStatus(client, symb, ordrId) -> bool:

	try:
		ogs = client.get_order(symbol = symb, orderId = ordrId, recvWindow = BU.getRecvWindow())

	except BinanceAPIException as e:
		print(f"Erro at client.get_order() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_order() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_order(): {e}")
		return False

	if BU.getExportXLS() == True:
		print("Symbol\tOrder Id\tOrder List Id\tClient Order Id\tPrice\tOrig Qty\tExecuted Qty\tCummulative Quote Qty\tStatus\tTime In Force\tType\tSide\tStop Price\tIceberg Qty\tTime\tUpdate Time\tIs Working\tOrig Quote Order Qty")
		print(f"{ogs['symbol']}\t{ogs['orderId']}\t{ogs['orderListId']}\t{ogs['clientOrderId']}\t{ogs['price']}\t{ogs['origQty']}\t{ogs['executedQty']}\t{ogs['cummulativeQuoteQty']}\t{ogs['status']}\t{ogs['timeInForce']}\t{ogs['type']}\t{ogs['side']}\t{ogs['stopPrice']}\t{ogs['icebergQty']}\t{BU.completeMilliTime(ogs['time'])}\t{BU.completeMilliTime(ogs['updateTime'])}\t{ogs['isWorking']}\t{ogs['origQuoteOrderQty']}")

	else:
		print(f"Check an order's id [{ordrId}] and symbol [{symb}] status")

		print(f"Symbol...............: [{ogs['symbol']}]")
		print(f"Order Id.............: [{ogs['orderId']}]")
		print(f"Order List Id........: [{ogs['orderListId']}]")
		print(f"Client Order Id......: [{ogs['clientOrderId']}]")
		print(f"Price................: [{ogs['price']}]")
		print(f"Orig Qty.............: [{ogs['origQty']}]")
		print(f"Executed Qty.........: [{ogs['executedQty']}]")
		print(f"Cummulative Quote Qty: [{ogs['cummulativeQuoteQty']}]")
		print(f"Status...............: [{ogs['status']}]")
		print(f"Time In Force........: [{ogs['timeInForce']}]")
		print(f"Type.................: [{ogs['type']}]")
		print(f"Side.................: [{ogs['side']}]")
		print(f"Stop Price...........: [{ogs['stopPrice']}]")
		print(f"Iceberg Qty..........: [{ogs['icebergQty']}]")
		print(f"Time.................: [{BU.completeMilliTime(ogs['time'])}]")
		print(f"Update Time..........: [{BU.completeMilliTime(ogs['updateTime'])}]")
		print(f"Is Working...........: [{ogs['isWorking']}]")
		print(f"Orig Quote Order Qty.: [{ogs['origQuoteOrderQty']}]")

	return True
Exemplo n.º 27
0
def cancel_a_margin_order(client, symbOrd = '', ordrid = 0) -> [bool, str]:
	print(f"Cancel Margin Order Id [{ordrid}] with Symbol [{symbOrd}]")

	if BU.askConfirmation() == False:
		return True, "Cancelled by Confirmation!"

	# TESTING
	global LOCK
	if LOCK == True:
		return False, "Programmed flag order lock ON!"

	try:
		cancOrd = client.cancel_margin_order(symbol = symbOrd, orderId = ordrid)
	except BinanceRequestException as e:
		return False, f"Erro at client.cancel_margin_order() BinanceRequestException: [{e.status_code} - {e.message}]"

	except BinanceAPIException as e:
		return False, f"Erro at client.cancel_margin_order() BinanceAPIException: [{e.status_code} - {e.message}]"

	except Exception as e:
		return False, f"Erro at client.cancel_margin_order(): {e}"

	if BU.getExportXLS() == True:
		BU.errPrint("Symbol\tOriginal Client Order Id\tOrder Id\tClient Order Id\tPrice\tOriginal Qtd\tExecuted Qty\tCummulative Quote Qty\tStatus\tTime In Force\tType\tSide")
		BU.errPrint(f"{cancOrd['symbol']}\t{cancOrd['origClientOrderId']}\t{cancOrd['orderId']}\t{cancOrd['clientOrderId']}\t{cancOrd['price']}\t{cancOrd['origQty']}\t{cancOrd['executedQty']}\t{cancOrd['cummulativeQuoteQty']}\t{cancOrd['status']}\t{cancOrd['timeInForce']}\t{cancOrd['timeInForce']}\t{cancOrd['type']}\t{cancOrd['side']}")

	else:
		print(f"Symbol..................: [{cancOrd['symbol']}]")
		print(f"Original Client Order Id: [{cancOrd['origClientOrderId']}]")
		print(f"OrderId.................: [{cancOrd['orderId']}]")
		print(f"Client Order Id.........: [{cancOrd['clientOrderId']}]")
		print(f"Price...................: [{cancOrd['price']}]")
		print(f"Original Qtd............: [{cancOrd['origQty']}]")
		print(f"Executed Qty............: [{cancOrd['executedQty']}]")
		print(f"Cummulative Quote Qty...: [{cancOrd['cummulativeQuoteQty']}]")
		print(f"Status..................: [{cancOrd['status']}]")
		print(f"Time In Force...........: [{cancOrd['timeInForce']}]")
		print(f"Type....................: [{cancOrd['type']}]")
		print(f"Side....................: [{cancOrd['side']}]")

	return True, 'Ok'
Exemplo n.º 28
0
def h24PriceChangeStats(client) -> bool:

	try:
		ga = client.get_ticker()
	except BinanceAPIException as e:
		print(f"Erro at client.get_ticker() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_ticker() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_ticker(): {e}")
		return False

	totGa = len(ga)

	if BU.getExportXLS() == True:
		BP.print24hPrcChangStsXLSHEADER()
		[BP.print24hPrcChangStsXLS(n) for n in ga]
	else:
		print("24 hour price change statistics:")
		[BP.print24hPrcChangSts(n, i, totGa) for i, n in enumerate(ga, 1)]
Exemplo n.º 29
0
def orderMargin(client, symbOrd = '', sideOrd = 0, typeOrd = 0, qtdOrd = 0, prcOrd = 0.0, prcStop = 0.0, limit = 0.0) ->[bool, str]:
	print(f"MARGIN Order {typeOrd}")

	if BU.getExportXLS() == True:
		BU.errPrint("Symbol\tSide\tQuantity\tPrice\tStop Price\tLimit OCO\tType")
		BU.errPrint(f"{symbOrd}\t{sideOrd}\t{qtdOrd}\t{prcOrd}\t{prcStop}\t{limit}\t{typeOrd}")
	else:
		print(f"Symbol....: [{symbOrd}]")
		print(f"Side......: [{sideOrd}]")
		print(f"Quantity..: [{qtdOrd}]")
		print(f"Price.....: [{prcOrd}]")
		print(f"Stop Price: [{prcStop}]")
		print(f"Limit OCO.: [{limit}]")
		print(f"Type......: [{typeOrd}]")

	if BU.askConfirmation() == False:
		return True, "Cancelled by Confirmation!"

	# TESTING
	global LOCK
	if LOCK == True:
		return False, "Programmed flag order lock ON!"

	try:
		if typeOrd == 'LIMIT':
			order = client.create_margin_order(symbol           = symbOrd,
		                                      side             = BU.binanceSide(sideOrd),
		                                      type             = Client.ORDER_TYPE_LIMIT,
		                                      timeInForce      = Client.TIME_IN_FORCE_GTC,
		                                      quantity         = qtdOrd,
		                                      price            = prcOrd,
		                                      newOrderRespType = Client.ORDER_RESP_TYPE_FULL)
		else:
			order = client.create_margin_order(symbol           = symbOrd,
		                                      side             = BU.binanceSide(sideOrd),
		                                      type             = BU.binanceOrderType(typeOrd),
		                                      timeInForce      = Client.TIME_IN_FORCE_GTC,
		                                      quantity         = qtdOrd,
		                                      price            = prcOrd,
		                                      stopPrice        = prcStop,
		                                      newOrderRespType = Client.ORDER_RESP_TYPE_FULL)

	except BinanceRequestException as e:
		return False, f"Erro create_margin_order BinanceRequestException: [{e.status_code} - {e.message}]"
	except BinanceAPIException as e:
		return False, f"Erro create_margin_order BinanceAPIException: [{e.status_code} - {e.message}]"
	except BinanceOrderException as e:
		return False, f"Erro create_margin_order BinanceOrderException: [{e.status_code} - {e.message}]"
	except BinanceOrderMinAmountException as e:
		return False, f"Erro create_margin_order BinanceOrderMinAmountException: [{e.status_code} - {e.message}]"
	except BinanceOrderMinPriceException as e:
		return False, f"Erro create_margin_order BinanceOrderMinPriceException: [{e.status_code} - {e.message}]"
	except BinanceOrderMinTotalException as e:
		return False, f"Erro create_margin_order BinanceOrderMinTotalException: [{e.status_code} - {e.message}]"
	except BinanceOrderUnknownSymbolException as e:
		return False, f"Erro create_margin_order BinanceOrderUnknownSymbolException: [{e.status_code} - {e.message}]"
	except BinanceOrderInactiveSymbolException as e:
		return False, f"Erro create_margin_order BinanceOrderInactiveSymbolException: [{e.status_code} - {e.message}]"
	except Exception as e:
		return False, f"Erro create_margin_order generic exception: {e}"

	BP.printMarginOrder(order)

	return True, "Ok"
Exemplo n.º 30
0
def accountInformation(client) -> bool:

	print("Spot accoutn information:")
	try:
		acc = client.get_account(recvWindow = BU.getRecvWindow())
	except BinanceAPIException as e:
		print(f"Erro at client.get_account() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except BinanceRequestException as e:
		print(f"Erro at client.get_account() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_account(): {e}")
		return False

	try:
		accStatus = client.get_account_status(recvWindow = BU.getRecvWindow())
	except BinanceWithdrawException as e:
		print(f"Erro at client.get_account_status() BinanceWithdrawException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_account_status(): {e}")
		return False

	if BU.getExportXLS() == True:
		print(f"Can trade\t{acc['canTrade']}\nCan withdraw\t{acc['canWithdraw']}\nCan deposit\t{acc['canDeposit']}\nAccount type\t{acc['accountType']}\nCommissions Maker\t{acc['makerCommission']}\nCommissions Taker\t{acc['takerCommission']}\nCommissions Buyer\t{acc['buyerCommission']}\nCommissions Seller\t{acc['sellerCommission']}\n")
		print(f"Account status detail\t{accStatus['msg']}\nSuccess\t{accStatus['success']}\n")
	else:
		print(f"Can trade............? [{acc['canTrade']}]")
		print(f"Can withdraw.........? [{acc['canWithdraw']}]")
		print(f"Can deposit..........? [{acc['canDeposit']}]")
		print(f"Account type.........: [{acc['accountType']}]")
		print(f"Account status detail: [{accStatus['msg']}] Success: [{accStatus['success']}]")
		print(f"Commissions..........: Maker: [{acc['makerCommission']}] | Taker: [{acc['takerCommission']}] | Buyer: [{acc['buyerCommission']}] | Seller: [{acc['sellerCommission']}]")

	if len(acc['balances']) != 0:
		if BU.getExportXLS() == True:
			BP.printAccountXLSHEADER()
			[BP.printAccountXLS(n) for n in acc['balances'] if float(n['free']) != 0.0 or float(n['locked']) != 0.0]
		else:
			[BP.printAccount(n) for n in acc['balances'] if float(n['free']) != 0.0 or float(n['locked']) != 0.0]

	print("\nMargin accoutn information:")
	try:
		marginInfo = client.get_margin_account(recvWindow = BU.getRecvWindow())
	except BinanceRequestException as e:
		print(f"Erro at client.get_margin_account() BinanceRequestException: [{e.status_code} - {e.message}]")
		return False
	except BinanceAPIException as e:
		print(f"Erro at client.get_margin_account() BinanceAPIException: [{e.status_code} - {e.message}]")
		return False
	except Exception as e:
		print(f"Erro at client.get_margin_account(): {e}")
		return False

	cleanedMarginAssets = [n for n in marginInfo['userAssets'] if float(n['netAsset']) != 0.0]

	if BU.getExportXLS() == True:
		print("Margin level\tTotal asset of BTC\tTotal liability of BTC\tTotal Net asset of BTC\tTrade enabled")
		print(f"{marginInfo['marginLevel']}\t{marginInfo['totalAssetOfBtc']}\t{marginInfo['totalLiabilityOfBtc']}\t{marginInfo['totalNetAssetOfBtc']}\t{marginInfo['tradeEnabled']}\n")

		print('Borrowed assets:')
		BP.printMarginAssetsXLSHEADER()
		[BP.printMarginAssetsXLS(n) for n in cleanedMarginAssets]
	else:
		print(f"Borrow Enabled........? [{marginInfo['borrowEnabled']}]")
		print(f"Trade enabled.........? [{marginInfo['tradeEnabled']}]")
		print(f"Level.................: [{marginInfo['marginLevel']}]")
		print(f"Total asset of BTC....: [{marginInfo['totalAssetOfBtc']}]")
		print(f"Total liability of BTC: [{marginInfo['totalLiabilityOfBtc']}]")
		print(f"Total Net asset of BTC: [{marginInfo['totalNetAssetOfBtc']}]\n")

		print('Borrowed assets:')
		[BP.printMarginAssets(n, i) for i, n in enumerate(cleanedMarginAssets, 1)]

	return True