def percentile(quantity): c = cnx whaletrades = cmd(c,'SELECT * FROM binance.whaletrades ORDER BY ABS(transaction_time) DESC;') y = [int(x['quantity']) for x in whaletrades] pctl = percentileofscore(y,quantity) if quantity < 0: pctl = pctl * -1 return(pctl)
def norm_signals(): c = cnx whalesize = cmd( c, "SELECT new_balance FROM binance.whaletrades ORDER BY transaction_time DESC LIMIT 1 ;", dictionary=False)[0][0] print("whalesize is " + str(whalesize)) buy_quantity = cmd( c, 'SELECT SUM(quantity) FROM binance.whaletrades WHERE quantity > 0;', dictionary=False)[0][0] print("buy quantity " + str(buy_quantity)) sell_quantity = cmd( c, 'SELECT SUM(quantity) FROM binance.whaletrades WHERE quantity < 0;', dictionary=False)[0][0] print("sell quantity " + str(sell_quantity))
def process_queries(self): c = cnx ## Opens connection while True: if not self.queryqueue.empty(): print("queue not empty") query,params = self.queryqueue.get() results = cmd(c,query,dictionary=True,params=params) print("querythread got result: " + st(results)) results = False self.resultqueue.put(results) self.lock.release()
def norm_transaction(quantity, transactions=False): c = cnx if quantity < 0: sign = '<' else: sign = '>' ## Transactions can be supplied as kwarg to avoid mysql query if not transactions: transactions = cmd( c, 'SELECT quantity FROM binance.whaletrades WHERE quantity ' + sign + ' 0;', dictionary=True) transactions = [int(x['quantity']) for x in transactions] pctl = percentileofscore(transactions, quantity) return (quantity, pctl)
## Transactions can be supplied as kwarg to avoid mysql query if not transactions: transactions = cmd( c, 'SELECT quantity FROM binance.whaletrades WHERE quantity ' + sign + ' 0;', dictionary=True) transactions = [int(x['quantity']) for x in transactions] pctl = percentileofscore(transactions, quantity) return (quantity, pctl) c = cnx query = "select * from binance.aggregated_prices WHERE intvl LIKE 'seconds' ORDER BY endTime;" trades = cmd(c, query, dictionary=True) #### Either all purchases or all sales ##c = cnx ##transactions = cmd(c,'SELECT quantity FROM binance.whaletrades;',dictionary=True) ##transactions = [int(x['quantity']) for x in transactions] ## ##sales = [] ##purchases = [] ##for z in transactions: ## quantity,pctl = norm_transaction(z,transactions) ## if quantity < 0: ## sales.append(pctl*-1) ## else: ## purchases.append(pctl) ##