本文整理匯總了Python中pymaker.numeric.Wad類的典型用法代碼示例。如果您正苦於以下問題:Python Wad類的具體用法?Python Wad怎麽用?Python Wad使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Wad類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_price
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)
示例2: _new_buy_orders
def _new_buy_orders(self, our_buy_orders: list, our_buy_balance: Wad, target_price: Wad):
"""Return buy orders which need to be placed to bring total amounts within all buy bands above minimums."""
assert(isinstance(our_buy_orders, list))
assert(isinstance(our_buy_balance, Wad))
assert(isinstance(target_price, Wad))
new_orders = []
limit_amount = self.buy_limits.available_limit(time.time())
missing_amount = Wad(0)
for band in self.buy_bands:
orders = [order for order in our_buy_orders if band.includes(order, target_price)]
total_amount = self.total_amount(orders)
if total_amount < band.min_amount:
price = band.avg_price(target_price)
pay_amount = Wad.min(band.avg_amount - total_amount, our_buy_balance, limit_amount)
buy_amount = pay_amount / price
missing_amount += Wad.max((band.avg_amount - total_amount) - our_buy_balance, Wad(0))
if (pay_amount >= band.dust_cutoff) and (pay_amount > Wad(0)) and (buy_amount > Wad(0)):
self.logger.debug(f"Using price {price} for new buy order")
our_buy_balance = our_buy_balance - pay_amount
limit_amount = limit_amount - pay_amount
new_orders.append(NewOrder(is_sell=False, price=price, pay_amount=pay_amount, buy_amount=buy_amount,
confirm_function=lambda: self.buy_limits.use_limit(time.time(), pay_amount)))
return new_orders, missing_amount
示例3: test_should_use_individual_buy_and_sell_prices_if_both_available
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))
示例4: test_should_not_cancel_anything_if_no_orders_to_cancel_regardless_of_price_availability
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 == [])
示例5: test_available_limit_is_always_max_if_no_limits_defined_even_when_orders_are_being_placed
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)
示例6: test_should_use_same_buy_and_sell_price_if_only_one_price_available
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))
示例7: test_should_not_create_any_orders_but_not_terminate_if_eth_balance_before_minimum
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
示例8: test_limit_renews_when_the_slot_is_over
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)
示例9: test_should_support_config_files_with_variables
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
示例10: __init__
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']))
示例11: test_should_place_extra_order_only_if_order_brought_below_min
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
示例12: test_should_not_create_orders_if_neither_buy_nor_sell_price_available
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 == [])
示例13: test_should_handle_only_buy_price_or_only_sell_price
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))
示例14: test_should_default_to_price_if_no_buy_price_or_no_sell_price
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))
示例15: test_value_2
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)