Beispiel #1
0
    def open_trade(self, ohlcv: OHLCV) -> None:
        """
        Method opens a trade for pair in ohlcv

        :param ohlcv: last OHLCV model (candle)
        :type ohlcv: OHLCV model
        :return: None
        :rtype: None
        """
        if self.budget <= 0:
            print("[INFO] Budget is running low, cannot buy")
            return

        date = datetime.fromtimestamp(ohlcv.time / 1000)
        open_trades = len(self.open_trades)
        available_spaces = self.max_open_trades - open_trades
        amount = ((100 / available_spaces) / 100) * self.budget
        self.budget-=amount
        new_trade = Trade()
        new_trade.pair = ohlcv.pair
        new_trade.open = ohlcv.close
        new_trade.current = ohlcv.close
        new_trade.status = "open"
        new_trade.amount = (amount / ohlcv.close)
        new_trade.opened_at = date
        self.open_trades.append(new_trade)
Beispiel #2
0
 def close_trade(self, trade: Trade, reason: str, ohlcv: OHLCV) -> None:
     """
     :param trade: Trade model, trade to close
     :type trade: Trade
     :param reason: Reason for the trade to be closed (SL, ROI, Sell Signal)
     :type reason: string
     :param ohlcv: Last candle
     :type ohlcv: OHLCV model
     :return: None
     :rtype: None
     """
     trade.status = 'closed'
     trade.sell_reason = reason
     trade.close = trade.current
     date = datetime.fromtimestamp(ohlcv.time / 1000)
     trade.closed_at = date
     self.budget += (trade.close * trade.amount)
     self.open_trades.remove(trade)
     self.closed_trades.append(trade)
     self.update_drawdowns_closed_trade(trade)
Beispiel #3
0
    def test_add(self):
        product = Product()
        product.title = "title"
        product.descr = "desc"
        product.type = ProductType.MATERIAL
        product.updated_at = product.inserted_at = util.utcnow()
        self.db.add(product)

        trade = Trade()
        trade.trade_id = self.gen_uid()
        trade.timeout = "1d"
        trade.fee = 0.01
        trade.status = TradeStatus.PENDING
        trade.channel = ChannelType.WAP
        trade.show_url = "url"
        trade.updated_at = trade.inserted_at = util.utcnow()
        trade.product = product

        self.db.add(trade)
        self.db.commit()
        self.assertTrue(True)