Esempio n. 1
0
 def order(self,
           id,
           long,
           qty,
           limit=0,
           stop=0,
           post_only=False,
           reduce_only=False,
           trailing_stop=0,
           activationPrice=0,
           when=False):
     """
     places an entry order, works equivalent to tradingview pine script implementation
     https://jp.tradingview.com/study-script-reference/#fun_strategy{dot}entry
     :param id: Order id
     :param long: Long or Short
     :param qty: Quantity
     :param limit: Limit price
     :param stop: Stop limit
     :param post_only: Post only        
     :param when: Do you want to execute the order or not - True for live trading
     :return:
     """
     BinanceFuturesStub.order(self, id, long, qty, limit, stop, post_only,
                              reduce_only, trailing_stop, activationPrice,
                              when)
Esempio n. 2
0
 def entry(self,
           id,
           long,
           qty,
           limit=0,
           stop=0,
           post_only=False,
           when=True,
           round_decimals=3,
           callback=None):
     """
     places an entry order, works equivalent to tradingview pine script implementation
     https://jp.tradingview.com/study-script-reference/#fun_strategy{dot}entry
     :param id: Order id
     :param long: Long or Short
     :param qty: Quantity
     :param limit: Limit price
     :param stop: Stop limit
     :param post_only: Post only        
     :param when: Do you want to execute the order or not - True for live trading
     :round_decimals: Round qty to decimals
     :callback
     :return:
     """
     BinanceFuturesStub.entry(self, id, long, qty, limit, stop, post_only,
                              when, round_decimals, callback)
Esempio n. 3
0
 def close_all(self):
     """
     Close all positions
     """
     if self.get_position_size() == 0:
         return
     BinanceFuturesStub.close_all(self)
     self.close_signals.append(self.index)
Esempio n. 4
0
    def on_update(self, bin_size, strategy):
        """
        Register the strategy function.
        :param strategy:
        """
        self.__load_ohlcv(bin_size)

        BinanceFuturesStub.on_update(self, bin_size, strategy)
        self.__crawler_run()
 def close_all_at_price(self, price):
     """
     close the current position at price, for backtesting purposes its important to have a function that closes at given price
     :param price: price
     """
     if self.get_position_size() == 0:
         return
     BinanceFuturesStub.close_all_at_price(self, price)
     self.close_signals.append(self.index)
Esempio n. 6
0
 def __init__(self, account, pair):
     """
     constructor
     :account:
     :pair:
     :param periods:
     """
     self.pair = pair
     BinanceFuturesStub.__init__(self,
                                 account,
                                 pair=self.pair,
                                 threading=False)
     self.enable_trade_log = False
     self.start_balance = self.get_balance()
Esempio n. 7
0
    def commit(self, id, long, qty, price, need_commission=True):
        """
        Commit
        :param id: order
        :param long: long or short
        :param qty: quantity
        :param price: price
        :param need_commission: use commision or not?
        """
        BinanceFuturesStub.commit(self, id, long, qty, price, need_commission)

        if long:
            self.buy_signals.append(self.index)
        else:
            self.sell_signals.append(self.index)
Esempio n. 8
0
    def run(self):
        """
˜       Function to run the bot
        """
        if self.hyperopt:
            logger.info(f"Bot Mode : Hyperopt")
            self.params_search()
            return

        elif self.stub_test:
            logger.info(f"Bot Mode : Stub")
            if self.exchange_arg == "binance":
                self.exchange = BinanceFuturesStub(account=self.account, pair=self.pair)
            elif self.exchange_arg == "bitmex":
                self.exchange = BitMexStub(account=self.account, pair=self.pair)
            else:
                logger.info(f"--exchange argument missing or invalid")
                return  
        elif self.back_test:
            logger.info(f"Bot Mode : Back test")
            if self.exchange_arg == "binance":
                self.exchange = BinanceFuturesBackTest(account=self.account, pair=self.pair)
            elif self.exchange_arg == "bitmex":
                self.exchange = BitMexBackTest(account=self.account, pair=self.pair)
            else:
                logger.info(f"--exchange argument missing or invalid")
                return
        else:
            logger.info(f"Bot Mode : Trade")
            if self.exchange_arg == "binance":
                self.exchange = BinanceFutures(account=self.account, pair=self.pair, demo=self.test_net)
            elif self.exchange_arg == "bitmex":
                self.exchange = BitMex(account=self.account, pair=self.pair, demo=self.test_net)
            else:
                logger.info(f"--exchange argument missing or invalid")
                return
        self.exchange.ohlcv_len = self.ohlcv_len()
        self.exchange.on_update(self.bin_size, self.strategy)

        logger.info(f"Starting Bot")
        logger.info(f"Strategy : {type(self).__name__}")
        logger.info(f"Balance : {self.exchange.get_balance()}")

        notify(f"Starting Bot\n"
               f"Strategy : {type(self).__name__}\n"
               f"Balance : {self.exchange.get_balance()}")
        
        self.exchange.show_result()