當前位置: 首頁>>代碼示例>>Python>>正文


Python Wad.from_number方法代碼示例

本文整理匯總了Python中pymaker.numeric.Wad.from_number方法的典型用法代碼示例。如果您正苦於以下問題:Python Wad.from_number方法的具體用法?Python Wad.from_number怎麽用?Python Wad.from_number使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pymaker.numeric.Wad的用法示例。


在下文中一共展示了Wad.from_number方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_should_not_create_any_orders_but_not_terminate_if_eth_balance_before_minimum

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_not_create_any_orders_but_not_terminate_if_eth_balance_before_minimum(self, deployment: Deployment, tmpdir):
        # given
        config_file = BandConfig.two_adjacent_bands_config(tmpdir)

        # and
        keeper = OasisMarketMakerKeeper(args=args(f"--eth-from {deployment.our_address} "
                                                  f"--tub-address {deployment.tub.address} "
                                                  f"--oasis-address {deployment.otc.address} "
                                                  f"--buy-token-address {deployment.sai.address} "
                                                  f"--sell-token-address {deployment.gem.address} "
                                                  f"--price-feed tub "
                                                  f"--config {config_file} "
                                                  f"--min-eth-balance 100.0"),
                                        web3=deployment.web3)
        keeper.lifecycle = Lifecycle(web3=keeper.web3)

        # and
        self.mint_tokens(deployment)
        self.set_price(deployment, Wad.from_number(100))

        # and
        self.leave_only_some_eth(deployment, Wad.from_number(10.0))  # there is a 5.0 ETH block reward even in testrpc,
                                                                     # that's why `--min-eth-balance` is higher than 10

        # when
        keeper.approve()
        self.synchronize_orders_twice(keeper)

        # then
        assert len(deployment.otc.get_orders()) == 0
        assert not keeper.lifecycle.terminated_internally
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:33,代碼來源:test_oasis_market_maker_keeper.py

示例2: get_price

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def get_price(self) -> Price:
        data, timestamp = self.feed.get()

        try:
            if 'buyPrice' in data:
                buy_price = Wad.from_number(data['buyPrice'])

            elif 'price' in data:
                buy_price = Wad.from_number(data['price'])

            else:
                buy_price = None
        except:
            buy_price = None

        try:
            if 'sellPrice' in data:
                sell_price = Wad.from_number(data['sellPrice'])

            elif 'price' in data:
                sell_price = Wad.from_number(data['price'])

            else:
                sell_price = None
        except:
            sell_price = None

        return Price(buy_price=buy_price, sell_price=sell_price)
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:30,代碼來源:price_feed.py

示例3: test_should_use_individual_buy_and_sell_prices_if_both_available

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_use_individual_buy_and_sell_prices_if_both_available(self):
        # when
        price_feed = WebSocketPriceFeed(FakeFeed({"buyPrice": "120.75", "sellPrice": "130.75"}))

        # then
        assert(price_feed.get_price().buy_price == Wad.from_number(120.75))
        assert(price_feed.get_price().sell_price == Wad.from_number(130.75))
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:9,代碼來源:test_price_feed.py

示例4: test_should_not_cancel_anything_if_no_orders_to_cancel_regardless_of_price_availability

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_not_cancel_anything_if_no_orders_to_cancel_regardless_of_price_availability(self, tmpdir):
        # given
        config = BandConfig.sample_config(tmpdir)
        bands = self.create_bands(config)

        # when
        price = Price(buy_price=Wad.from_number(100), sell_price=Wad.from_number(200))
        orders_to_cancel = bands.cancellable_orders([], [], price)
        # then
        assert(orders_to_cancel == [])

        # when
        price = Price(buy_price=Wad.from_number(100), sell_price=None)
        orders_to_cancel = bands.cancellable_orders([], [], price)
        # then
        assert(orders_to_cancel == [])

        # when
        price = Price(buy_price=None, sell_price=Wad.from_number(200))
        orders_to_cancel = bands.cancellable_orders([], [], price)
        # then
        assert(orders_to_cancel == [])

        # when
        price = Price(buy_price=None, sell_price=None)
        orders_to_cancel = bands.cancellable_orders([], [], price)
        # then
        assert(orders_to_cancel == [])
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:30,代碼來源:test_band.py

示例5: test_available_limit_is_always_max_if_no_limits_defined_even_when_orders_are_being_placed

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
 def test_available_limit_is_always_max_if_no_limits_defined_even_when_orders_are_being_placed(self, no_limits):
     # when
     no_limits.use_limit(self.time_zero, Wad.from_number(5))
     # then
     assert no_limits.available_limit(self.time_zero - 1) == Wad.from_number(2**256 - 1)
     assert no_limits.available_limit(self.time_zero) == Wad.from_number(2**256 - 1)
     assert no_limits.available_limit(self.time_zero + 1) == Wad.from_number(2**256 - 1)
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:9,代碼來源:test_limit.py

示例6: test_limit_renews_when_the_slot_is_over

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
 def test_limit_renews_when_the_slot_is_over(self, sample_limits):
     # when
     sample_limits.use_limit(self.time_zero, Wad.from_number(5))
     # then
     assert sample_limits.available_limit(self.time_zero) == Wad.from_number(95)
     assert sample_limits.available_limit(self.time_zero + 60*60 - 1) == Wad.from_number(95)
     assert sample_limits.available_limit(self.time_zero + 60*60) == Wad.from_number(100)
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:9,代碼來源:test_limit.py

示例7: test_should_use_same_buy_and_sell_price_if_only_one_price_available

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_use_same_buy_and_sell_price_if_only_one_price_available(self):
        # when
        price_feed = WebSocketPriceFeed(FakeFeed({"price": "125.75"}))

        # then
        assert(price_feed.get_price().buy_price == Wad.from_number(125.75))
        assert(price_feed.get_price().sell_price == Wad.from_number(125.75))
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:9,代碼來源:test_price_feed.py

示例8: test_should_support_config_files_with_variables

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_support_config_files_with_variables(self, deployment: Deployment, tmpdir):
        # given
        config_file = BandConfig.with_variables_config(tmpdir)

        # and
        keeper = OasisMarketMakerKeeper(args=args(f"--eth-from {deployment.our_address} "
                                                  f"--tub-address {deployment.tub.address} "
                                                  f"--oasis-address {deployment.otc.address} "
                                                  f"--buy-token-address {deployment.sai.address} "
                                                  f"--sell-token-address {deployment.gem.address} "
                                                  f"--price-feed tub "
                                                  f"--config {config_file}"),
                                        web3=deployment.web3)
        keeper.lifecycle = Lifecycle(web3=keeper.web3)

        # and
        self.mint_tokens(deployment)
        self.set_price(deployment, Wad.from_number(100))

        # when
        keeper.approve()
        self.synchronize_orders_twice(keeper)

        # then
        assert len(deployment.otc.get_orders()) == 1

        # and
        assert self.orders_by_token(deployment, deployment.gem)[0].maker == deployment.our_address
        assert self.orders_by_token(deployment, deployment.gem)[0].pay_amount == Wad.from_number(5.0)
        assert self.orders_by_token(deployment, deployment.gem)[0].pay_token == deployment.gem.address
        assert self.orders_by_token(deployment, deployment.gem)[0].buy_amount == Wad.from_number(520)
        assert self.orders_by_token(deployment, deployment.gem)[0].buy_token == deployment.sai.address
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:34,代碼來源:test_oasis_market_maker_keeper.py

示例9: __init__

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def __init__(self, dictionary: dict):
        super()._validate_deprecated_properties(dictionary)

        super().__init__(min_margin=dictionary['minMargin'],
                         avg_margin=dictionary['avgMargin'],
                         max_margin=dictionary['maxMargin'],
                         min_amount=Wad.from_number(dictionary['minAmount']),
                         avg_amount=Wad.from_number(dictionary['avgAmount']),
                         max_amount=Wad.from_number(dictionary['maxAmount']),
                         dust_cutoff=Wad.from_number(dictionary['dustCutoff']))
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:12,代碼來源:band.py

示例10: test_should_place_extra_order_only_if_order_brought_below_min

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_place_extra_order_only_if_order_brought_below_min(self, deployment: Deployment, tmpdir):
        # given
        config_file = BandConfig.sample_config(tmpdir)

        # and
        keeper = OasisMarketMakerKeeper(args=args(f"--eth-from {deployment.our_address} "
                                                  f"--tub-address {deployment.tub.address} "
                                                  f"--oasis-address {deployment.otc.address} "
                                                  f"--buy-token-address {deployment.sai.address} "
                                                  f"--sell-token-address {deployment.gem.address} "
                                                  f"--price-feed tub "
                                                  f"--config {config_file}"),
                                        web3=deployment.web3)
        keeper.lifecycle = Lifecycle(web3=keeper.web3)

        # and
        self.mint_tokens(deployment)
        self.set_price(deployment, Wad.from_number(100))

        # and
        keeper.approve()
        self.synchronize_orders_twice(keeper)
        assert len(deployment.otc.get_orders()) == 2
        sai_order_id = self.orders_by_token(deployment, deployment.sai)[0].order_id

        # when
        deployment.otc.take(sai_order_id, Wad.from_number(20)).transact()
        # and
        keeper.order_book_manager.wait_for_order_book_refresh()
        # and
        self.synchronize_orders_twice(keeper)
        # then
        assert len(deployment.otc.get_orders()) == 2

        # when
        deployment.otc.take(sai_order_id, Wad.from_number(5)).transact()
        # and
        keeper.order_book_manager.wait_for_order_book_refresh()
        # and
        self.synchronize_orders_twice(keeper)
        # then
        assert len(deployment.otc.get_orders()) == 2

        # when
        deployment.otc.take(sai_order_id, Wad.from_number(1)).transact()
        # and
        keeper.order_book_manager.wait_for_order_book_refresh()
        # and
        self.synchronize_orders_twice(keeper)
        # then
        assert len(deployment.otc.get_orders()) == 3
        assert deployment.otc.get_orders()[2].pay_amount == Wad.from_number(26)
        assert deployment.otc.get_orders()[2].pay_token == deployment.sai.address
        assert deployment.otc.get_orders()[2].buy_amount == Wad(270833333333333333)
        assert deployment.otc.get_orders()[2].buy_token == deployment.gem.address
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:57,代碼來源:test_oasis_market_maker_keeper.py

示例11: test_should_not_create_orders_if_neither_buy_nor_sell_price_available

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_not_create_orders_if_neither_buy_nor_sell_price_available(self, tmpdir):
        # given
        config = BandConfig.sample_config(tmpdir)
        bands = self.create_bands(config)

        # when
        price = Price(buy_price=None, sell_price=None)
        new_orders, _, _ = bands.new_orders([], [], Wad.from_number(1000000), Wad.from_number(1000000), price)

        # then
        assert(new_orders == [])
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:13,代碼來源:test_band.py

示例12: test_value_2

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_value_2(self):
        # given
        price_feed_1 = FakePriceFeed()
        price_feed_2 = FakePriceFeed()
        average_price_feed = AveragePriceFeed([price_feed_1, price_feed_2])

        # and
        price_feed_2.set_price(Wad.from_number(17.5))

        # expect
        assert average_price_feed.get_price().buy_price == Wad.from_number(17.5)
        assert average_price_feed.get_price().sell_price == Wad.from_number(17.5)
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:14,代碼來源:test_price_feed.py

示例13: test_should_handle_only_buy_price_or_only_sell_price

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_handle_only_buy_price_or_only_sell_price(self):
        # when
        price_feed = WebSocketPriceFeed(FakeFeed({"buyPrice": "120.75"}))
        # then
        assert(price_feed.get_price().buy_price == Wad.from_number(120.75))
        assert(price_feed.get_price().sell_price is None)

        # when
        price_feed = WebSocketPriceFeed(FakeFeed({"sellPrice": "130.75"}))
        # then
        assert(price_feed.get_price().buy_price is None)
        assert(price_feed.get_price().sell_price == Wad.from_number(130.75))
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:14,代碼來源:test_price_feed.py

示例14: test_should_default_to_price_if_no_buy_price_or_no_sell_price

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_default_to_price_if_no_buy_price_or_no_sell_price(self):
        # when
        price_feed = WebSocketPriceFeed(FakeFeed({"price": "125.0", "buyPrice": "120.75"}))
        # then
        assert(price_feed.get_price().buy_price == Wad.from_number(120.75))
        assert(price_feed.get_price().sell_price == Wad.from_number(125.0))

        # when
        price_feed = WebSocketPriceFeed(FakeFeed({"price": "125.0", "sellPrice": "130.75"}))
        # then
        assert(price_feed.get_price().buy_price == Wad.from_number(125.0))
        assert(price_feed.get_price().sell_price == Wad.from_number(130.75))
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:14,代碼來源:test_price_feed.py

示例15: test_should_cancel_selected_sell_orders_to_bring_the_band_total_below_max_and_closest_to_it

# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import from_number [as 別名]
    def test_should_cancel_selected_sell_orders_to_bring_the_band_total_below_max_and_closest_to_it(self, deployment: Deployment, tmpdir):
        # given
        config_file = BandConfig.sample_config(tmpdir)

        # and
        keeper = OasisMarketMakerKeeper(args=args(f"--eth-from {deployment.our_address} "
                                                  f"--tub-address {deployment.tub.address} "
                                                  f"--oasis-address {deployment.otc.address} "
                                                  f"--buy-token-address {deployment.sai.address} "
                                                  f"--sell-token-address {deployment.gem.address} "
                                                  f"--price-feed tub "
                                                  f"--config {config_file}"),
                                        web3=deployment.web3)
        keeper.lifecycle = Lifecycle(web3=keeper.web3)

        # and
        self.mint_tokens(deployment)
        self.set_price(deployment, Wad.from_number(100))

        # and
        keeper.approve()
        self.synchronize_orders_twice(keeper)
        assert len(deployment.otc.get_orders()) == 2

        # when [7.5+2.0 = 9.5]
        deployment.otc.make(deployment.gem.address, Wad.from_number(2), deployment.sai.address, Wad.from_number(208)).transact()
        # and
        keeper.order_book_manager.wait_for_order_book_refresh()
        # and
        self.synchronize_orders_twice(keeper)
        # then
        assert len(deployment.otc.get_orders()) == 3

        # when [9.5+0.5 = 10]
        deployment.otc.make(deployment.gem.address, Wad.from_number(0.5), deployment.sai.address, Wad.from_number(52)).transact()
        # and
        keeper.order_book_manager.wait_for_order_book_refresh()
        # and
        self.synchronize_orders_twice(keeper)
        # then
        assert len(deployment.otc.get_orders()) == 4

        # when [10+0.1 = 10.1] --> above max!
        deployment.otc.make(deployment.gem.address, Wad.from_number(0.1), deployment.sai.address, Wad.from_number(10.4)).transact()
        # and
        keeper.order_book_manager.wait_for_order_book_refresh()
        # and
        self.synchronize_orders_twice(keeper)
        # then
        assert len(deployment.otc.get_orders()) == 4
        assert reduce(Wad.__add__, map(lambda order: order.pay_amount, self.orders_by_token(deployment, deployment.gem)), Wad(0)) \
               == Wad.from_number(10.0)
開發者ID:laoyaoshine514,項目名稱:market-maker-keeper,代碼行數:54,代碼來源:test_oasis_market_maker_keeper.py


注:本文中的pymaker.numeric.Wad.from_number方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。