本文整理匯總了Python中pymaker.numeric.Wad.min方法的典型用法代碼示例。如果您正苦於以下問題:Python Wad.min方法的具體用法?Python Wad.min怎麽用?Python Wad.min使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymaker.numeric.Wad
的用法示例。
在下文中一共展示了Wad.min方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _new_buy_orders
# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import min [as 別名]
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
示例2: deposit_for_sell_order
# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import min [as 別名]
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
示例3: deposit_for_buy_order
# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import min [as 別名]
def deposit_for_buy_order(self, missing_buy_amount: Wad):
# We always want to deposit at least `min_sai_deposit`. If `missing_buy_amount` is less
# than that, we deposit `min_sai_deposit` anyway.
if Wad(0) < missing_buy_amount < self.min_sai_deposit:
missing_buy_amount = self.min_sai_deposit
# We can never deposit more than our available SAI balance.
depositable_sai = self.sai.balance_of(self.our_address)
missing_buy_amount = Wad.min(missing_buy_amount, depositable_sai)
# If we still can deposit something, and it's at least `min_sai_deposit`, then we do deposit.
if missing_buy_amount > Wad(0) and missing_buy_amount >= self.min_sai_deposit:
receipt = self.idex.deposit_token(self.sai.address, missing_buy_amount).transact(gas_price=self.gas_price)
return receipt is not None and receipt.successful
else:
return False
示例4: available_limit
# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import min [as 別名]
def available_limit(self, timestamp: int):
if len(self.side_limits) > 0:
return Wad.min(*map(lambda limit: limit.available_limit(timestamp, self.side_history), self.side_limits))
else:
return Wad.from_number(2**256 - 1)