def close_all(self): """ Close all positions """ if self.get_position_size() == 0: return BitMexStub.close_all(self) self.close_signals.append(self.index)
def __init__(self): """ コンストラクタ :param periods: """ BitMexStub.__init__(self, threading=False) self.enable_trade_log = False self.start_balance = self.get_balance()
def close_all(self): """ すべてのポジションを解消する。 """ if self.get_position_size() == 0: return BitMexStub.close_all(self) self.close_signals.append(self.index)
def on_update(self, bin_size, strategy): """ Register the strategy function. :param strategy: """ self.__load_ohlcv(bin_size) BitMexStub.on_update(self, bin_size, strategy) self.__crawler_run()
def on_update(self, bin_size, strategy): """ 戦略の関数を登録する。 :param strategy: """ self.__load_ohlcv(bin_size) BitMexStub.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 BitMexStub.close_all_at_price(self, price) self.close_signals.append(self.index)
def __init__(self, account, pair): """ constructor :account: :pair: :param periods: """ BitMexStub.__init__(self, account, pair, threading=False) self.pair = pair self.enable_trade_log = False self.start_balance = self.get_balance()
def entry(self, id, long, qty, limit=0, stop=0, when=True): """ 注文をする。pineの関数と同等の機能。 https://jp.tradingview.com/study-script-reference/#fun_strategy{dot}entry :param id: 注文の番号 :param long: ロング or ショート :param qty: 注文量 :param limit: 指値 :param stop: ストップ指値 :param when: 注文するか :return: """ BitMexStub.entry(self, id, long, qty, limit, stop, when)
def order(self, id, long, qty, limit=0, stop=0, post_only=False, reduce_only=False, allow_amend=True, 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: """ BitMexStub.order(self, id, long, qty, limit, stop, post_only, reduce_only, allow_amend, when)
def commit(self, id, long, qty, price): """ 約定する。 :param id: 注文番号 :param long: ロング or ショート :param qty: 注文量 :param price: 価格 """ BitMexStub.commit(self, id, long, qty, price) if long: self.buy_signals.append(self.index) else: self.sell_signals.append(self.index)
def commit(self, id, long, qty, price, need_commission=True): """ 約定する。 :param id: 注文番号 :param long: ロング or ショート :param qty: 注文量 :param price: 価格 :param need_commission: 手数料が発生するか """ BitMexStub.commit(self, id, long, qty, price, need_commission) if long: self.buy_signals.append(self.index) else: self.sell_signals.append(self.index)
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? """ BitMexStub.commit(self, id, long, qty, price, need_commission) if long: self.buy_signals.append(self.index) else: self.sell_signals.append(self.index)
def run(self): """ ˜ Botを起動する関数。 """ logger.info(f"Starting Bot") logger.info(f"Strategy : {type(self).__name__}") if self.hyperopt: logger.info(f"Bot Mode : Hyperopt") self.params_search() return elif self.stub_test: logger.info(f"Bot Mode : Stub") self.exchange = BitMexStub() elif self.back_test: logger.info(f"Bot Mode : Back test") self.exchange = BitMexBackTest() else: logger.info(f"Bot Mode : Trade") self.exchange = BitMex(demo=self.test_net) self.exchange.ohlcv_len = self.ohlcv_len() self.exchange.on_update(self.bin_size, self.strategy) self.exchange.show_result()
def run(self): """ ˜ Bot 기동 """ if self.hyperopt: logger.info(f"Bot Mode : Hyperopt") self.params_search() return elif self.stub_test: logger.info(f"Bot Mode : Stub") self.exchange = BitMexStub() elif self.back_test: logger.info(f"Bot Mode : Back test") self.exchange = BitMexBackTest() else: logger.info(f"Bot Mode : Trade") self.exchange = BitMex(demo=self.test_net) 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"Resolution : {self.resolution()}") logger.info(f"Balance : {self.exchange.get_balance()}") notify(f"Starting Bot\n" f"Strategy : {type(self).__name__}\n" f"Resolution : {self.resolution()}\n" f"Balance : {self.exchange.get_balance()/100000000} XBT") self.exchange.show_result()
def run(self): if self.hyperopt: raise Exception( "Trading View Strategy dose not support hyperopt Mode.") elif self.back_test: raise Exception( "Trading View Strategy dose not support backtest Mode.") elif self.stub_test: # if you want to use binance futures # self.exchange = BinanceFuturesStub(account=self.account, pair=self.pair) self.exchange = BitMexStub(account=self.account, pair=self.pair) logger.info(f"Bot Mode : Stub") else: # if you want to use binance #self.exchange = BinanceFutures(account=self.account, pair=self.pair, demo=self.test_net) self.exchange = BitMex(account=self.account, pair=self.pair, demo=self.test_net) logger.info(f"Bot Mode : Trade") 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()/100000000} XBT") self.subscriber.on_message(self.__on_message)
def run(self): if self.hyperopt: raise Exception( "Trading View Strategy dose not support hyperopt Mode.") elif self.back_test: raise Exception( "Trading View Strategy dose not support backtest Mode.") elif self.stub_test: self.exchange = BitMexStub() logger.info(f"Bot Mode : Stub") else: self.exchange = BitMex(demo=self.test_net) logger.info(f"Bot Mode : Trade") logger.info(f"Starting Bot") logger.info(f"Strategy : {type(self).__name__}") logger.info(f"Resolution : {self.resolution()}") logger.info(f"Balance : {self.exchange.get_balance()}") notify(f"Starting Bot\n" f"Strategy : {type(self).__name__}\n" f"Resolution : {self.resolution()}\n" f"Balance : {self.exchange.get_balance()/100000000} XBT") self.subscriber.on_message(self.__on_message)
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()