def get_account_info(client): """Get user's balance info.""" assets = [] total = 0 response = client.query_private('Balance', {}) balance = response.get('result') if not balance: from app import sentry sentry.captureMessage(response.get('error')) return None, None # TODO: # Collect all paris used in balance and query them once together. pair_list = [asset + 'ZUSD' for asset in balance.keys() if asset[0] == 'X'] response = client.query_public('Ticker', {'pair': ','.join(pair_list)}) pair_price = response.get('result') print(response) for asset in balance.keys(): if asset[0] == 'X': pair_name = asset + 'ZUSD' new_asset = Asset(asset, float(balance.get(asset)), float(pair_price.get(pair_name).get('c')[0])) else: new_asset = Asset(asset, amount=float(balance.get(asset)), total=float(balance.get(asset))) assets.append(new_asset.to_dict()) total += new_asset.total return assets, total
def subscribe_asset(self, symbol, exchange, secType): asset_key = f"{symbol}@{exchange}" self.assetCache[asset_key] = Asset(symbol=symbol, exchange=exchange, secType=secType, client=self) return asset_key
def set_asset(self, guid, description, type, uri, duration_secs=None, pin=None, how_many=None, shuffle=None): self.kv.set_asset(guid, Asset(uri, guid, description, type, duration_secs, pin, how_many, shuffle))
def insert(self, dto): reg = Asset() reg.map(dto) reg.calculate() return AssetDb().insert(reg)
def update(self, id, dto): reg = Asset() reg.map(dto) reg.calculate() return AssetDb().update(id, reg)