本文整理汇总了Python中pymaker.numeric.Wad类的典型用法代码示例。如果您正苦于以下问题:Python Wad类的具体用法?Python Wad怎么用?Python Wad使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Wad类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:28,代码来源:price_feed.py
示例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
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:28,代码来源:band.py
示例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))
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:7,代码来源:test_price_feed.py
示例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 == [])
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:28,代码来源:test_band.py
示例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)
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:7,代码来源:test_limit.py
示例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))
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:7,代码来源:test_price_feed.py
示例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
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:31,代码来源:test_oasis_market_maker_keeper.py
示例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)
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:7,代码来源:test_limit.py
示例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
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:32,代码来源:test_oasis_market_maker_keeper.py
示例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']))
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:10,代码来源:band.py
示例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
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:55,代码来源:test_oasis_market_maker_keeper.py
示例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 == [])
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:11,代码来源:test_band.py
示例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))
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:12,代码来源:test_price_feed.py
示例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))
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:12,代码来源:test_price_feed.py
示例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)
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:12,代码来源:test_price_feed.py
示例16: test_should_cancel_selected_sell_orders_to_bring_the_band_total_below_max_and_closest_to_it
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,代码行数:52,代码来源:test_oasis_market_maker_keeper.py
示例17: test_should_create_only_sell_orders_if_only_sell_price_is_available
def test_should_create_only_sell_orders_if_only_sell_price_is_available(self, tmpdir):
# given
config = BandConfig.sample_config(tmpdir)
bands = self.create_bands(config)
# when
price = Price(buy_price=None, sell_price=Wad.from_number(200))
new_orders, _, _ = bands.new_orders([], [], Wad.from_number(1000000), Wad.from_number(1000000), price)
# then
assert(len(new_orders) == 1)
assert(new_orders[0].is_sell is True)
assert(new_orders[0].price == Wad.from_number(208))
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:13,代码来源:test_band.py
示例18: our_available_balance
def our_available_balance(self, our_balances, token: Address) -> Wad:
if token == EtherDelta.ETH_TOKEN:
try:
return Wad.from_number(our_balances['ETH']['available'])
except KeyError:
return Wad(0)
elif token == self.sai.address:
try:
return Wad.from_number(our_balances['DAI']['available'])
except KeyError:
return Wad(0)
else:
raise Exception("Unknown token")
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:13,代码来源:idex_market_maker_keeper.py
示例19: test_should_cancel_orders_if_price_disappears
def test_should_cancel_orders_if_price_disappears(self, tmpdir):
# given
config = BandConfig.sample_config(tmpdir)
bands = self.create_bands(config)
# and
buy_order = FakeOrder(Wad.from_number(75), Wad.from_number(96))
sell_order = FakeOrder(Wad.from_number(7.5), Wad.from_number(208))
# when
price = Price(buy_price=Wad.from_number(100), sell_price=Wad.from_number(200))
orders_to_cancel = bands.cancellable_orders([buy_order], [sell_order], price)
# then
assert(orders_to_cancel == [])
# when
price = Price(buy_price=Wad.from_number(100), sell_price=None)
orders_to_cancel = bands.cancellable_orders([buy_order], [sell_order], price)
# then
assert(orders_to_cancel == [sell_order])
# when
price = Price(buy_price=None, sell_price=Wad.from_number(200))
orders_to_cancel = bands.cancellable_orders([buy_order], [sell_order], price)
# then
assert(orders_to_cancel == [buy_order])
# when
price = Price(buy_price=None, sell_price=None)
orders_to_cancel = bands.cancellable_orders([buy_order], [sell_order], price)
# then
assert(orders_to_cancel == [buy_order, sell_order])
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:32,代码来源:test_band.py
示例20: deposit_for_sell_order
def deposit_for_sell_order(self, missing_sell_amount: Wad):
# We always want to deposit at least `min_eth_deposit`. If `missing_sell_amount` is less
# than that, we deposit `min_eth_deposit` anyway.
if Wad(0) < missing_sell_amount < self.min_eth_deposit:
missing_sell_amount = self.min_eth_deposit
# We can never deposit more than our available ETH balance minus `eth_reserve` (reserve for gas).
depositable_eth = Wad.max(eth_balance(self.web3, self.our_address) - self.eth_reserve, Wad(0))
missing_sell_amount = Wad.min(missing_sell_amount, depositable_eth)
# If we still can deposit something, and it's at least `min_eth_deposit`, then we do deposit.
if missing_sell_amount > Wad(0) and missing_sell_amount >= self.min_eth_deposit:
receipt = self.idex.deposit(missing_sell_amount).transact(gas_price=self.gas_price)
return receipt is not None and receipt.successful
else:
return False
开发者ID:laoyaoshine514,项目名称:market-maker-keeper,代码行数:16,代码来源:idex_market_maker_keeper.py
注:本文中的pymaker.numeric.Wad类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论