def execute_trade(self): decision = self.strategy.run() self.logger.info('Strategy %s decision %s', self.strategy.name, decision) slack.send('Strategy %s decision %s :fire:' % (self.strategy.name, decision)) try: if decision == "SELL": self.logger.info("Trying to %s %0.2f", decision, self.money_to_trade * self.leverage) response = self.client.Order.Order_new( symbol="XBTUSD", side="Sell", orderQty=self.money_to_trade * self.leverage, ).result() self.logger.info("Response %s", response) if decision == "BUY": self.logger.info("Trying to %s %0.2f", decision, self.money_to_trade * self.leverage) response = self.client.Order.Order_new( symbol="XBTUSD", side="Buy", orderQty=self.money_to_trade * self.leverage, ).result() self.logger.info("Response %s", response) except Exception as e: self.logger.error("Trading exception %s", str(e)) return
def announce_changes(): restaurants = [ "Bagel Boss", "Chop't", "Dig Inn", "Empanada Mama", "Eva's", "Galanga", "Hale and Hearty", "Hummus & Pita Co.", "Kosher Deluxe", "Lenwich", "The Mill", "Mooncake", "Poke N' Roll", "Quan Sushi", ] header_message = "IS MY FOOD HERE YET? (reacting with “:fork_and_knife:” mean YES it’s here)" message_payload = slack.send('#grub', header_message, color="#00A2E1") for restaurant in restaurants: header_message = f"{restaurant}" _ = slack.send('#grub', header_message, color="#0089BF") print(message_payload)
def take(top=None, bottom=None): img = 'diffuse.png' meme = 'diffuse-meme.png' camera = picamera.PiCamera() camera.framerate = 24 camera.resolution = (400, 400) camera.capture(img) memegenerator.make(top, bottom, img, meme) slack.send(meme) return img
def validate_data(self, version): errors = version.validate_data() if errors: slack.send( "Skipping S3 upload for {} due to the following errors:\n". format(version.config["name"]) + "\n".join(errors), channel_name="sky-py") return errors
def announce_changes(): sync.update_db_emoticons() # get now as soon as possible after syncing now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) last_time = get_last_announcement_time() if not last_time: print("No previous announcement time; setting to now and exiting.") log_last_announcement(now) return changes = db.get_changes_since(last_time) if not changes: print("No changes") return message = get_change_message(changes) message_payload = slack.send(os.environ['SLACK_EMOTICON_ANNOUNCE_CHANNEL'], message) if len(changes[ADDED]) > 2: slack.reply_to( message_payload, ''.join(map(":{0.name}:".format, changes[ADDED][:MAX_REPLIES])) ) log_last_announcement(now) print(message)
def send_message(self): """Sends a message for all unresolved posts or followups made after self.ignore_before. Uses weights column from input CSV to proportionally allocate staff members to questions""" message, high_priority = "", "" # [network.get_post(cid=108)] for post in network.list_unresolved(): post_id = post.get("nr") assigned = self.oncall(post) if assigned == "ignore": print( f"{datetime.datetime.today().date()}: @{post_id} is marked as ignore" ) continue elif assigned: str = "" for email in assigned: str += f"<!{email}> " str += f"your assigned post (<{self.url_starter}{post_id}|@{post_id}>) needs help!\n" message += str continue for p in self.select_staff(post): # [[email, 61, True], [email2, 61_f1, False]] str = f"<!{p[0]}> please help <{self.url_starter}{p[1]}|@{p[1]}>\n" if p[2]: high_priority += str else: message += str if message: starter = ( "Good morning! Here are today's piazza assignments. You will receive a daily reminder " + "about your unresolved piazza posts. *If you do not know how to answer your post(s), post in general.*\n\n" ) # print(starter + message) send(starter + message, course="cs61a") if high_priority: starter = ( f"<These messages have been unanswered for {self.urgent_threshold} days. " + "*If you were assigned one of these posts, reply to this message after you have resolved it.*\n\n" ) send(starter + high_priority, course="cs61a")
def run_and_notify(self, send_to_s3_override=False): try: slack.send("{} started".format(self.s3_key), channel_name="sky-py") with statsd.timed(self.statsd_time_name): self.run(send_to_s3_override=send_to_s3_override) statsd.increment(self.statsd_time_name, tags=['success']) slack.send("{} finished".format(self.s3_key), channel_name="sky-py") except Exception: statsd.increment(self.statsd_time_name, tags=['error']) slack.send("{} failed".format(self.s3_key), channel_name="sky-py") sentry.handleException(sys.exc_info())
else: direction = 'Short' if strategy.crossunder(ohlc.close, high): extra = "*" msg += "BTC %0.1f%% of %dd high %s%s\n" % (tolerance * 100, lookback, direction, extra) for alert in alerts: extra = '' ohlc = strategy.get_data(symbol=alert['Symbol'], count=alert['Slow'] + 4) if alert['EMA']: fast = ohlc.close.ewm(span=alert['Fast'], adjust=False).mean() slow = ohlc.close.ewm(span=alert['Slow'], adjust=False).mean() else: fast = ohlc.close.rolling(window=alert['Fast']).mean() slow = ohlc.close.rolling(window=alert['Slow']).mean() if fast[-1] >= slow[-1]: direction = 'Long' if strategy.crossabove(fast, slow): extra = "*" else: direction = 'Short' if strategy.crossunder(fast, slow): extra = "*" msg += "%s (%d,%d) %s%s\n" % (alert['Name'], alert['Fast'], alert['Slow'], direction, extra) sleep(0.5) slack.send(msg)
import slack slack.send('Hello from test :fire:')
overlay = next_overlay() capture = None i = 0 while True: camera.start_preview() set_overlay(overlay, camera) c = console.show() if c == console.QUIT: break elif c == console.LEFT: overlay = prev_overlay() elif c == console.RIGHT: overlay = next_overlay() elif c == console.CENTER: capture = 'image{0:04d}.png'.format(i) camera.capture(capture) write(capture,overlay) i = i + 1 elif c == console.PREVIEW and capture is not None: print 'preview ' + capture clear_overlay() camera.stop_preview() Image.open(capture).show(title="Image Preview") sleep(5) elif c == console.SEND and capture is not None: print 'sending ' + capture slack.send(capture) camera.stop_preview()