Beispiel #1
0
    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
Beispiel #2
0
    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)
Beispiel #3
0
    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
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
    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)
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 def notify_with_datetime(self, message):
     now_timestamp = dt.now_timestamp()
     self.notify(NEWLINE.join([now_timestamp, message]))