def place_offer(self, mb_amount, chosen_est_price, timeout, config): """ Sells the received MB amount for the chosen estimated price on the Tribler market. :param mb_amount: Amount of MB to sell :param config: config :param timeout: timeout of the offer to place :param chosen_est_price: Target amount of BTC to receive :return: success of offer placement """ if chosen_est_price == 0 or mb_amount == 0: return False config.bump_offer_date() coin = 'TBTC' if plebnet_settings.get_instance().wallets_testnet( ) else 'BTC' config.set('last_offer', {coin: chosen_est_price, 'MB': mb_amount}) if coin == 'TBTC': return market_controller.put_ask( first_asset_amount=mb_amount, first_asset_type='MB', second_asset_amount=btc_to_satoshi(chosen_est_price), second_asset_type=coin, timeout=timeout) return market_controller.put_bid( first_asset_amount=btc_to_satoshi(chosen_est_price), first_asset_type=coin, second_asset_amount=mb_amount, second_asset_type='MB', timeout=timeout)
def place_offer(chosen_est_price, config): """ Sell all available MB for the chosen estimated price on the Tribler market. :param config: config :param chosen_est_price: Target amount of BTC to receive :return: success of offer placement """ available_mb = market_controller.get_balance('MB') if available_mb == 0: logger.log("No MB available") return False config.bump_offer_date() config.set('last_offer', {'BTC': chosen_est_price, 'MB': available_mb}) price_per_unit = max(0.0001, chosen_est_price / float(available_mb)) return market_controller.put_ask(price=price_per_unit, price_type='BTC', quantity=available_mb, quantity_type='MB', timeout=plebnet_settings.TIME_IN_HOUR)
def test_put_ask(self): self.true_put = Market._put_request Market._put_request = MagicMock(return_value=True) assert(Market.put_ask(10, 'BTC', 10, 'MB', 100)) Market._put_request = self.true_put