def _bid(self, account, auction_asset, price): market = cybex.Market(base=cybex.Asset("CYB"), quote=auction_asset, cybex_instance=self._instance) memo_id = generate_id() nonce = generate_nonce() data = { "account": account, "asset": auction_asset['symbol'], "price": price, "nonce": nonce } self._bid_history.append(data) with open(self._bid_history_fname, "w") as fd: fd.write(json.dumps(self._bid_history)) data = json.dumps(data) print("blind data:", data) memo_data = self._encrypt(data) print("encrypt blind data:", memo_data) self._instance.custom([], memo_id, memo_data, account=self._host) market.buy(price, self._amount, self._expiration, killfill=False, account=account)
def deal(self, auction_asset, price): if isinstance(auction_asset, str): asset = cybex.Asset(auction_asset) else: asset = auction_asset host_instance = cybex.account.Account(self._host, cybex_instance=self._instance) # we don't have any asset, issue new assets if host_instance.balance(asset).amount == 0: print("issue new asset: {}".format(asset['symbol'])) self._instance.issue_asset(to=self._host, amount=self._amount, asset=asset, account=self._host) print("asset {} has amount: {}".format( asset['symbol'], host_instance.balance(asset).amount)) self._deal(asset, price) # remove this asset in db since it was sold in real market. resp = dict(status="success", price=price, amount=self._amount) print(resp) return json.dumps(resp)
def create_asset(symbol, instance, account): asset = instance.create_asset(symbol=symbol, precision=0, max_supply=10000, core_exchange_ratio={symbol: 100, 'CYB': 1}, account=account) asset = cybex.Asset(symbol, cybex_instance=instance) return asset
def get_asset(symbol, instance=None, account=None): try: asset = cybex.Asset(symbol, cybex_instance=instance) except AssetDoesNotExistsException: if not account: raise instance.create_asset(symbol=symbol, precision=0, max_supply=10000, core_exchange_ratio={symbol: 100, 'CYB': 1}, account=account) asset = cybex.Asset(symbol, cybex_instance=instance) # cache_asset(symbol, account) return asset
def _create_asset(self, symbol): asset = self._instance.create_asset(symbol=symbol, precision=0, max_supply=10000, core_exchange_ratio={ symbol: 100, 'CYB': 1 }, account=self._host) asset = cybex.Asset(symbol, cybex_instance=self._instance) return asset
def _deal(account, auction_asset, price, amount=1, expiration=3600, instance=None, market=None): if isinstance(auction_asset, str): auction_asset = cybex.Asset(auction_asset, cybex_instance=instance) if not market: market = get_market(auction_asset, instance) market.sell(price, amount, expiration, killfill=False, account=account)
def update_assetSupply(inst, symbol, max_supply): asset = cybex.Asset(symbol) options = asset['options'] account = cybex.Account(inst.const['master_account']) options.update({ "max_supply": max_supply }) op = operations.Asset_update(**{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "issuer": account["id"], "asset_to_update": asset["id"], "new_options": options, "extensions": [], "prefix": inst.prefix }) return inst.finalizeOp(op, account["name"], "active")
def _deal(self, auction_asset, price): market = cybex.Market(base=cybex.Asset("CYB"), quote=auction_asset, cybex_instance=self._instance)
def get_market(auction_asset, instance): _market = cybex.Market(base=cybex.Asset("CYB"), quote=auction_asset, cybex_instance=instance) return _market