def fetch_eff_tick(self, size=1): timestamp = dt.now_timestamp() book = self.exchange.fetch_order_book(self.symbol) if book: # 実効ASK計算 i = 0 s = 0 while s <= size: s += book['asks'][i][1] i += 1 # 実効BID計算 j = 0 t = 0 while t <= size: t += book['bids'][j][1] j += 1 bid = book['bids'][i - 1][0] ask = book['asks'][j - 1][0] self._logging_tick(bid, ask) return Tick(self.exchange_id, timestamp, bid, ask) else: self.logger.error('(%s) %s', self.exchange_id.value, "can't get tick") return None
def __logging_bot_order(self, order_type, buy_exchange, buy_rate, buy_price, sell_exchange, sell_rate, sell_price, profit, profit_margin): bot_logger = getLogger(LOGGER_NAME_BOT_ORDER) timestamp = dt.now_timestamp() message = "{},{},{},{},{},{},{},{}".format( timestamp, order_type, buy_exchange.value, buy_rate, buy_price, sell_exchange.value, sell_rate, sell_price, profit, profit_margin) bot_logger.info(message)
def fetch_tick(self): timestamp = dt.now_timestamp() tick = self._exec() if tick: self._logging_tick(tick["bid"], tick["ask"]) return Tick(self.exchange_id, timestamp, tick["bid"], tick["ask"]) else: self.logger.error('(%s) %s', self.exchange_id.value, "can't get tick") return None
def notify_order(self, ex_id_ask, ex_id_bid, symbol, amount, expected_profit): now_timestamp = dt.now_timestamp() emoji_gold = "💰" profit_message = "{}円の利益{}".format(expected_profit, emoji_gold) order_message = "{}の{}を{}で買い{}で売りました。".format(amount, symbol, ex_id_ask.value, ex_id_bid.value) message = NEWLINE.join( [profit_message, "", now_timestamp, order_message]) self.notify(message)
def _logging_json(self, keyword): file_name = "{}.json".format(keyword) dir_path = path.ASSETS_LOG_DIR if not os.path.exists(dir_path): os.mkdir(dir_path) file_path = os.path.join(dir_path, file_name) data = {} data["timestamp"] = dt.now_timestamp() data["total"] = self.total for asset in self.assets: data[asset["id"]] = asset json.write(file_path, data)
def _notify_slack(self): slack = SlackClient(env.SLACK_WEBHOOK_URL_ASSET) lines = [] lines.append("現在の資産状況は以下の通り({})".format(dt.now_timestamp())) lines.append("") for asset in self.assets: line = "[{}] {}円/{}BTC({}) 計{}円".format(asset["id"], asset["jpy"], asset["btc"], asset["btc_as_jpy"], asset["total_jpy"]) lines.append(line) line = "[{}] {}円/{}BTC({}) 計{}円".format(self.total["id"], self.total["jpy"], self.total["btc"], self.total["btc_as_jpy"], self.total["total_jpy"]) lines.append(line) message = "\n".join(lines) slack.notify(message)
def logging(self, exchange_id, jpy, btc, btc_as_jpy, total_jpy): logger = self._get_logger(exchange_id) timestamp = dt.now_timestamp() message = "{},{},{},{},{}".format(timestamp, jpy, btc, btc_as_jpy, total_jpy) logger.info(message)
def _logging_tick_historical(self, x, y): timestamp = dt.now_timestamp() self.historical_logger.logging(self.ex_id_x, timestamp, x.bid, x.ask, x.timestamp) self.historical_logger.logging(self.ex_id_y, timestamp, y.bid, y.ask, y.timestamp)
def notify_with_datetime(self, message): now_timestamp = dt.now_timestamp() self.notify(NEWLINE.join([now_timestamp, message]))