def updatePricingProspects(self): from rrlib.rrDb import ProspectData as pd from rrlib.rrDb import OptionData as od try: for pt in pd.select().where(pd.BTCcomm.is_null()): self.log.logger.debug(" Put Sell Strategy updating prices for: " + str(pt)) timestamp = od.select(od.timestamp).where((od.stock == pt.stock) & ( od.strike == pt.strike) & (od.expireDate == pt.expireDate)).get().timestamp # TODO if timestamp > 1 dia entonces actualizar manualmente la opción y recargar if ((datetime.datetime.now()-datetime.timedelta(days=1)) > timestamp): monthdif = int(self.diff_month(datetime.datetime.today(), pt.expireDate)) self.db.getOption(pt.stock, int(pt.strike), monthdif) currentPrice = od.select(od.price).where((od.stock == pt.stock) & ( od.strike == pt.strike) & (od.expireDate == pt.expireDate)).get().price pnl = str(round(float(pt.contracts) * (float(pt.price)-float(pt.currentPrice))*100-float(pt.contracts)*2, 2)) self.log.logger.debug(" Put Sell Strategy updating prices for: " + pt.stock+" current price:"+currentPrice + " old price:"+pt.currentPrice) pd.update({pd.currentPrice: currentPrice, pd.pnl: pnl}).where((pd.stock == pt.stock) & (pd.strike == pt.strike) & (pd.expireDate == pt.expireDate)).execute() except Exception as e: self.log.logger.error( " Put Sell Strategy pricing update error") self.log.logger.error(e)
def communicateProspects(self): import datetime from rrlib.rrTelegram import rrTelegram from rrlib.rrIFTTT import rrIFTTT from rrlib.rrDb import ProspectData as pd try: for prospect in pd.select().where(pd.STOcomm.is_null()): report = {} report["value1"] = "Put Sell Strategy: Prospect Found: Stock:"+prospect.stock+" Strike:" + \ prospect.strike+" Expiration Date:" + str(prospect.expireDate) report["value2"] = "Contracts:" + prospect.contracts+" Price:" + str(round(float( prospect.price), 3)) + " RPotential:"+str(round(float(prospect.Rpotential), 2)) report["value3"] = "Stock ownership:" +\ prospect.stockOwnership+" Color:"+prospect.color self.log.logger.debug( " Communicator , invoking with these parameters "+str(report)) self.db.updateServerRun(prospectsFound="Yes") try: r = rrIFTTT().send(report) rrTelegram().sendMessage( str(report["value1"])+" | "+str(report["value2"])+" | "+str(report["value3"])) if str(r) == "<Response [200]>": pd.update({pd.STOcomm: datetime.datetime.today()}).where((pd.stock == prospect.stock) & ( pd.strike == prospect.strike) & (pd.expireDate == prospect.expireDate)).execute() except Exception as e: self.log.logger.error( " Put Sell Strategy prospect IFTTT error") self.log.logger.error(e) except Exception as e: self.log.logger.error( " Put Sell Strategy prospect communicator error") self.log.logger.error(e)
def sendDailyReport(self): from rrlib.rrDb import ProspectData as pd from rrlib.rrTelegram import rrTelegram from rrlib.rrIFTTT import rrIFTTT pnlClosed = 0 numClosed = 0 pnlOpen = 0 numOpen = 0 try: for pt in pd.select().where(pd.BTCcomm.is_null(False)): pnlClosed = pnlClosed + float(pt.pnl) numClosed = numClosed + 1 for pt in pd.select().where(pd.BTCcomm.is_null()): pnlOpen = pnlOpen + float(pt.pnl) numOpen = numOpen + 1 report = {} report["value1"] = "PNL Closed: $" +\ str(round(pnlClosed, 2))+" with "+str(numClosed)+" prospects" report["value2"] = "PNL Open: $" +\ str(round(pnlOpen, 2))+" with "+str(numOpen)+" prospects" report["value3"] = "PNL Total: $"+str( round(pnlClosed + pnlOpen, 2))+" with "+str(numClosed+numOpen)+" prospects" self.log.logger.info("\n\n -------------------DAILY REPORT-------------------\n "+str( report["value1"])+"\n "+str(report["value2"])+"\n "+str(report["value3"]) + "\n ------------------DAILY REPORT-------------------\n") try: r = rrIFTTT().send(report) rrTelegram().sendMessage( str(report["value1"])+" | "+str(report["value2"])+" | "+str(report["value3"])) if str(r) == "<Response [200]>": pass except Exception as e: self.log.logger.error( " Put Sell Strategy daily report communication error") self.log.logger.error(e) except Exception as e: self.log.logger.error( " Put Sell Strategy sending daily report error") self.log.logger.error(e)
def communicateClosing(self): import datetime from rrlib.rrTelegram import rrTelegram from rrlib.rrIFTTT import rrIFTTT from rrlib.rrDb import ProspectData as pd try: for prospect in pd.select().where(pd.BTCcomm.is_null()): if ((float(prospect.price)*float(self.PremiumTarget) > float(prospect.currentPrice)) or (float((prospect.expireDate-datetime.date.today()).days) < float(self.BTCdays))): pnl = str(round(float(prospect.contracts) * (float(prospect.price)-float(prospect.currentPrice))*100-float(prospect.contracts)*2, 2)) report = {} report["value1"] = "Time to close the contract<br>Stock:"+prospect.stock +\ " Strike:" + str(prospect.strike) +\ " Expiration Date:" + str(prospect.expireDate) report["value2"] = "Contracts:" + str(prospect.contracts)+" Closing Price:" +\ str(round(float(prospect.currentPrice), 3)) +\ " PNL for this oppty:" + pnl report["value3"] = "Stock ownership:" +\ str(prospect.stockOwnership)+" Color:"+prospect.color self.log.logger.debug( " Communicator, invoking with these parameters " + str(report)) self.db.updateServerRun(pnl=pnl) try: r = rrIFTTT().send(report) if (self.startbot == "Yes"): rrTelegram().sendMessage( str(report["value1"])+" | "+str(report["value2"])+" | "+str(report["value3"])) if str(r) == "<Response [200]>": pd.update({pd.BTCcomm: datetime.datetime.today(), pd.pnl: pnl}).where((pd.stock == prospect.stock) & (pd.strike == prospect.strike) & (pd.expireDate == prospect.expireDate)).execute() except Exception as e: self.log.logger.error( " Put Sell Strategy comm closing IFTTT error") self.log.logger.error(e) except Exception as e: self.log.logger.error( " Put Sell Strategy communicator closing error") self.log.logger.error(e)
def samples(sample): otus = session.query(OTU).statement otus_df = pd.read_sql_query(otus, session.bind) otus_df.set_index('otu_id', inplace=True) samp_names = session.query(Samples).statement samp_df = pd.read_sql_query(samp_names, session.bind) samp_df.set_index('otu_id', inplace=True) sel_samp = samp_df[sample] otus_id = samp_df['otu_id'] sel_df = pd.select({"otus_id": otu_ids, "samples": sel_samp}) sorted_df = sel_df.sort_values(by=['samples'], ascending=False) sorted_otus = {"otu_ids": list(sorted_df['otu_ids'].values)} sorted_samples = {"sample_values": list(sorted_df['samples'].values)} for i in range(len(sorted_otus["otu_ids"])): sorted_otus["otu_ids"][i] = int(sorted_otus["otu_ids"][i]) for i in range(len(sorted_samples["sample_values"])): sorted_samples["sample_values"][i] = int( sorted_samples["sample_values"][i]) results = [ sorted_otus, sorted_samples, list(all_otus_df["lowest_taxonomic_unit_found"]) ] return jsonify(results)