Esempio n. 1
0
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
Esempio n. 2
0
 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
Esempio n. 3
0
 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))
Esempio n. 4
0
 def insert(self, dto):
     reg = Asset()
     reg.map(dto)
     reg.calculate()
     return AssetDb().insert(reg)
Esempio n. 5
0
 def update(self, id, dto):
     reg = Asset()
     reg.map(dto)
     reg.calculate()
     return AssetDb().update(id, reg)