def bitasset_local(bitshares, base_bitasset, default_account): asset = base_bitasset() dex = Dex(blockchain_instance=bitshares) # Set initial price feed price = Price(1.5, base=asset, quote=Asset("TEST")) bitshares.publish_price_feed(asset.symbol, price, account=default_account) # Borrow some amount to_borrow = Amount(100, asset) dex.borrow(to_borrow, collateral_ratio=2.1, account=default_account) # Drop pricefeed to cause margin call price = Price(1.0, base=asset, quote=Asset("TEST")) bitshares.publish_price_feed(asset.symbol, price, account=default_account) return asset
def borrow(ctx, amount, symbol, ratio, account): """ Borrow a bitasset/market-pegged asset """ from bitshares.dex import Dex dex = Dex(bitshares_instance=ctx.bitshares) print_tx( dex.borrow(Amount(amount, symbol), collateral_ratio=ratio, account=account))
data = ticker.get('quoteSettlement_price') feed_price = data.get('price') print(feed_price) # получаем баланс в шарах на аккаунте balance = account.balance(quote) # всегда берем целую часть шар для займа. остаток оставляем на комиссии collateral = int(balance.get('amount')) print(collateral) if collateral > 0: # находим сколько можно напечатать юаней с нашим перекрытием debt = (1/feed_price)/init_ratio*collateral print(debt) # подготавливаем переменную вида "1 CNY" amount = Amount(debt, base) print(amount) # печатаем битассет dex.borrow(amount, collateral, our_account) # расчитываем call price #call_price = 1/((debt/collateral)*margin_ratio) #print(call_price) print('done!')