本文整理匯總了Python中pymaker.numeric.Wad.max方法的典型用法代碼示例。如果您正苦於以下問題:Python Wad.max方法的具體用法?Python Wad.max怎麽用?Python Wad.max使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymaker.numeric.Wad
的用法示例。
在下文中一共展示了Wad.max方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _new_buy_orders
# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import max [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: available_limit
# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import max [as 別名]
def available_limit(self, timestamp: int, side_history: SideHistory):
assert(isinstance(side_history, SideHistory))
items = filter(lambda item: timestamp - self.seconds < item['timestamp'] <= timestamp, side_history.get_items())
used_amount = reduce(Wad.__add__, map(lambda item: item['amount'], items), Wad(0))
return Wad.max(self.amount - used_amount, Wad(0))
示例3: deposit_for_sell_order
# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import max [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
示例4: depositable_balance
# 需要導入模塊: from pymaker.numeric import Wad [as 別名]
# 或者: from pymaker.numeric.Wad import max [as 別名]
def depositable_balance(self, token: Address) -> Wad:
if token == EtherDelta.ETH_TOKEN:
return Wad.max(eth_balance(self.web3, self.our_address) - self.eth_reserve, Wad(0))
else:
return ERC20Token(web3=self.web3, address=token).balance_of(self.our_address)