Beispiel #1
0
def metadata_json():
    meta = warden_metadata()
    # jsonify transactions
    for wallet in meta['txs']:
        try:
            meta['txs'][wallet] = meta['txs'][wallet].to_dict()
        except Exception:
            pass
    try:
        meta['df_old'] = meta['df_old'].to_dict()
    except Exception:
        pass

    try:
        meta['full_df'] = meta['full_df'].to_dict()
    except Exception:
        pass

    try:
        meta['old_new_df_old'] = meta['old_new_df_old'].to_dict()
    except Exception:
        pass

    return (json.dumps(meta, default=lambda o: '<not serializable>'))
Beispiel #2
0
def warden_page():
    # For now pass only static positions, will update prices and other
    # data through javascript after loaded. This improves load time
    # and refresh speed.
    # Get positions and prepare df for delivery

    df = positions()
    try:
        df = positions()
    except Exception as e:
        flash(f"Error getting transactions: {e}", "danger")
        return redirect(url_for("warden.newtrade"))

    if df.index.name != 'trade_asset_ticker':
        df.set_index('trade_asset_ticker', inplace=True)
    df = df[df['is_currency'] == 0].sort_index(ascending=True)
    df = df.to_dict(orient='index')

    # Create a custody DF
    transactions = transactions_fx()
    custody_df = transactions.groupby(["trade_account", "trade_asset_ticker"
                                       ])[["trade_quantity"]].sum()

    # Open Counter, increment, send data
    try:
        counter = pickle_it('load', 'counter.pkl')
        if counter == 'file not found':
            raise
        counter += 1
        pickle_it('save', 'counter.pkl', counter)
        if counter == 25:
            flash(
                "Looks like you've been using the app frequently. " +
                "Consider donating to support it.", "info")
        if counter == 50:
            flash(
                "Open Source software is transparent and free. " +
                "Support it. Make a donation.", "info")
        if counter % 100:
            flash(
                "Looks like you are a frequent user of the WARden. " +
                "Consider a donation.", "info")

    except Exception:
        # File wasn't found. Create start at zero
        flash(
            "Welcome. Consider making a donation " +
            "to support this software.", "info")
        counter = 0
        pickle_it('save', 'counter.pkl', counter)

    meta = warden_metadata()

    # Sort the wallets by balance
    sorted_wallet_list = []
    try:
        for wallet in current_app.specter.wallet_alias_list():
            wallet_df = meta['full_df'].loc[meta['full_df']['wallet_alias'] ==
                                            wallet]
            if wallet_df.empty:
                balance = 0
            else:
                balance = wallet_df['amount'].sum()
            sorted_wallet_list.append((wallet, balance))

        sorted_wallet_list = sorted(sorted_wallet_list,
                                    reverse=True,
                                    key=itemgetter(1))
        sorted_wallet_list = [i[0] for i in sorted_wallet_list]
        wallets_exist = True
    except Exception as e:

        logging.error(e)
        wallets_exist = False

    from api.routes import alert_activity
    if not current_app.downloading:
        activity = alert_activity()
    else:
        activity = False

    templateData = {
        "title": "Portfolio Dashboard",
        "warden_metadata": meta,
        "portfolio_data": df,
        "FX": current_app.settings['PORTFOLIO']['base_fx'],
        "alerts": activity,
        "current_app": current_app,
        "sorted_wallet_list": sorted_wallet_list,
        "wallets_exist": wallets_exist,
        "custody_df": custody_df
    }
    return (render_template('warden/warden.html', **templateData))
Beispiel #3
0
def warden_page():
    # For now pass only static positions, will update prices and other
    # data through javascript after loaded. This improves load time
    # and refresh speed.
    # Get positions and prepare df for delivery

    try:
        df = positions()
    except Exception:
        flash("Seems like transactions may be downloading... Check Specter Transactions for status.", "warning")
        return redirect(url_for("warden.newtrade"))

    if df.empty:
        flash("No Transactions Found. You can start by including a transaction below. You may also Connect to Specter or import a CSV file.", "info")
        return redirect(url_for("warden.newtrade"))

    if df.index.name != 'trade_asset_ticker':
        df.set_index('trade_asset_ticker', inplace=True)
    df = df[df['is_currency'] == 0].sort_index(ascending=True)
    df = df.to_dict(orient='index')

    # Create a custody DF
    transactions = transactions_fx()
    custody_df = transactions.groupby(["trade_account", "trade_asset_ticker"
                                       ])[["trade_quantity"]].sum()

    # Open Counter, increment, send data
    counter_file = os.path.join(home_path(),
                                'warden/counter.json')
    donated = False
    try:
        with open(counter_file) as data_file:
            json_all = json.loads(data_file.read())
        if json_all == "donated":
            donated = True
        else:
            counter = int(json_all)
            counter += 1
            if counter == 25:
                flash(
                    "Looks like you've been using the app frequently. " +
                    "Awesome! Consider donating.", "info")
            if counter == 50:
                flash(
                    "Open Source software is transparent and free. " +
                    "Support it. Make a donation.", "info")
            if counter == 200:
                flash(
                    "Looks like you are a frequent user of the WARden. " +
                    "Have you donated?", "info")
            if counter >= 1000:
                flash(
                    "You've opened this page 1,000 times or more. " +
                    "Really! Time to make a donation?", "danger")
            with open(counter_file, 'w') as fp:
                json.dump(counter, fp)

    except Exception:
        # File wasn't found. Create start at zero
        if not donated:
            flash(
                "Welcome. Consider making a donation " +
                "to support this software.", "info")
            counter = 0
            with open(counter_file, 'w') as fp:
                json.dump(counter, fp)

    meta = warden_metadata()

    # Sort the wallets by balance
    sorted_wallet_list = []
    try:
        for wallet in current_app.specter.wallet_alias_list():
            wallet_df = meta['full_df'].loc[meta['full_df']['wallet_alias'] == wallet]
            if wallet_df.empty:
                balance = 0
            else:
                balance = wallet_df['amount'].sum()
            sorted_wallet_list.append((wallet, balance))

        sorted_wallet_list = sorted(sorted_wallet_list, reverse=True, key=itemgetter(1))
        sorted_wallet_list = [i[0] for i in sorted_wallet_list]
        wallets_exist = True
    except Exception:
        wallets_exist = False

    from api.routes import alert_activity
    if not current_app.downloading:
        activity = alert_activity()
    else:
        activity = False

    templateData = {
        "title": "Portfolio Dashboard",
        "warden_metadata": meta,
        "portfolio_data": df,
        "FX": current_app.settings['PORTFOLIO']['base_fx'],
        "donated": donated,
        "alerts": activity,
        "current_app": current_app,
        "sorted_wallet_list": sorted_wallet_list,
        "wallets_exist": wallets_exist,
        "custody_df": custody_df
    }
    return (render_template('warden/warden.html', **templateData))