def fill_fetch_order(order, market): return Order(market, order.get('id'), Analyser.extract_type(order, market), Analyser.extract_start_amount(order, market), Analyser.extract_remaining_amount_order(order, market), Analyser.extract_price2(order, market), Analyser.extract_status_order(order, market))
def test_extract_no_good_order(self): depth = [[PRICE, 1]] analyser = Analyser() order = analyser.extract_good_order(depth) assert order[0] == PRICE assert order[1] == 0
def _buy(self, market, volume, rate): """ This try to buy the selected coin from the selected market at the selected price. It will cancel the order if it is not able to fill the order instantly. .. todo:: Change the parameters :param market: The analysis object :param volume: The volume wanted :param rate: The wanted rate :return: The order or None if couldn't buy """ try: order = self.trader.buy(market, self.coin, volume, rate) except: logger.exception("Failed to buy {} on {}".format( self.coin, market)) return None logger.debug(order) if not Analyser.is_filled(order, market): return self._handle_miss_buy(order, market) return Trader.fill_buy_sell_order(order, market)
def main(): reporter = Reporter() try: logger.info("Creating strategy") strategy = Balance(settings.COIN, "LIQUI", "BINANCE", Trader(), Analyser(), reporter, Database(), Helper()) logger.info("Start running current strategy") strategy.run() logger.info("Finished running current strategy") except: logger.exception("") reporter.error("Service {} is dead, please revive it!".format( settings.SERVICE_NUMBER))
def test_extract_remaining_amount_liqui(self): amount = Analyser.extract_remaining_amount2(LIQUI_BUY_ORDER, LIQUI) assert amount == 10
def test_extract_remaining_amount_binance(self): amount = Analyser.extract_remaining_amount2(BINANCE_SELL_ORDER, BINANCE) assert amount == 20
def test_extract_start_amount_liqui_order(self): amount = Analyser.extract_start_amount(LIQUI_FETCH_BUY_ORDER, LIQUI) assert amount == 199
def test_extract_start_amount_binance_order(self): amount = Analyser.extract_start_amount(BINANCE_FETCH_SELL_ORDER, BINANCE) assert amount == 192
def test_extract_status_liqui(self): status = Analyser.extract_status(LIQUI_BUY_ORDER, LIQUI) assert status == Status.ONGOING
def test_extract_start_amount_unknown(self): amount = Analyser.extract_start_amount({}, TOTO) assert amount == 0
def test_extract_price_unknown(self): price = Analyser.extract_price2({}, TOTO) assert price == 0
def test_extract_remaining_amount_binance_order(self): amount = Analyser.extract_remaining_amount_order( BINANCE_FETCH_SELL_ORDER, BINANCE) assert amount == 20
def test_extract_status_unknown_order(self): status = Analyser.extract_status_order({}, TOTO) assert status == Status.UNKNOWN
def test_extract_price_liqui_order(self): price = Analyser.extract_price2(LIQUI_FETCH_BUY_ORDER, LIQUI) assert price == 0.00008469
def test_extract_status_binance_order(self): status = Analyser.extract_status_order(BINANCE_FETCH_SELL_ORDER, BINANCE) assert status == Status.DONE
def test_extract_status_liqui_order(self): status = Analyser.extract_status_order(LIQUI_FETCH_BUY_ORDER, LIQUI) assert status == Status.ONGOING
def test_extract_status_binance(self): status = Analyser.extract_status(BINANCE_SELL_ORDER, BINANCE) assert status == Status.DONE
def test_extract_remaining_amount_unknown(self): amount = Analyser.extract_remaining_amount2({}, TOTO) assert amount == 0
def test_extract_type_liqui_order(self): type = Analyser.extract_type(LIQUI_FETCH_BUY_ORDER, LIQUI) assert type == Types.BUY
def test_extract_remaining_amount_liqui_order(self): amount = Analyser.extract_remaining_amount_order( LIQUI_FETCH_BUY_ORDER, LIQUI) assert amount == 10
def test_extract_type_binance_order(self): type = Analyser.extract_type(BINANCE_FETCH_SELL_ORDER, BINANCE) assert type == Types.SELL
def test_extract_type_unknown(self): type = Analyser.extract_type({}, TOTO) assert type == Types.UNKNOWN
def test_extract_price_binance_order(self): price = Analyser.extract_price2(BINANCE_FETCH_SELL_ORDER, BINANCE) assert price == 0.00008762