Beispiel #1
0
def asset_list(term=None):
    import csv
    master_list = []
    if term is None:
        term = ""
    # Alphavantage Currency List - CSV
    filename = os.path.join(current_path(),
                            'static/csv_files/physical_currency_list.csv')
    with open(filename, newline='') as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            if term.upper() in row[0].upper() or term in row[1].upper():
                master_list.append({
                    'symbol': row[0],
                    'name': row[1],
                    'provider': 'aa_fx'
                })
    # Alphavantage Digital Currency list
    filename = os.path.join(current_path(),
                            'static/csv_files/digital_currency_list.csv')
    with open(filename, newline='') as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            if term.upper() in row[0].upper() or term.upper() in row[1].upper(
            ):
                master_list.append({
                    'symbol': row[0],
                    'name': row[1],
                    'provider': 'aa_digital'
                })
    # Alphavantage Stock Search EndPoint
    try:
        url = 'https://www.alphavantage.co/query?function=SYMBOL_SEARCH'
        url += '&keywords=' + term
        url += '&apikey=' + api
        result = requests.get(url).json()
        result = result['bestMatches']
        for element in result:
            master_list.append({
                'symbol':
                element['1. symbol'],
                'name':
                element['2. name'],
                'provider':
                'aa_stock',
                'notes':
                element['3. type'] + ' ' + element['4. region'],
                'fx':
                element['8. currency']
            })
    except Exception:
        pass
    return (master_list)
Beispiel #2
0
def histvol():
    # if there's rolling variable, get it, otherwise default to 30
    if request.method == "GET":
        try:
            q = int(request.args.get("rolling"))
        except ValueError:
            q = 30
    else:
        q = 30

    ticker = request.args.get("ticker")
    metadata = request.args.get("meta")

    # When ticker is not sent, will calculate for portfolio
    if not ticker:
        data = generatenav()
        data["vol"] = (data["NAV_fx"].pct_change().rolling(q).std() *
                       (365**0.5) * 100)
        # data.set_index('date', inplace=True)
        vollist = data[["vol"]]
        vollist.index = vollist.index.strftime("%Y-%m-%d")
        datajson = vollist.to_json()

    if ticker:
        filename = "thewarden/historical_data/" + ticker + ".json"
        filename = os.path.join(current_path(), filename)

        try:
            with open(filename) as data_file:
                local_json = json.loads(data_file.read())
                data_file.close()
                prices = pd.DataFrame(
                    local_json["Time Series (Digital Currency Daily)"]).T
                prices["4b. close (USD)"] = prices["4b. close (USD)"].astype(
                    np.float)
                prices["vol"] = (
                    prices["4b. close (USD)"].pct_change().rolling(q).std() *
                    (365**0.5) * 100)
                pricelist = prices[["vol"]]
                datajson = pricelist.to_json()

        except (FileNotFoundError, KeyError):
            datajson = "Ticker Not Found"

    if metadata is not None:
        metatable = {}
        metatable["mean"] = vollist.vol.mean()
        metatable["max"] = vollist.vol.max()
        metatable["min"] = vollist.vol.min()
        metatable["last"] = vollist.vol[-1]
        metatable["lastvsmean"] = (
            (vollist.vol[-1] / vollist.vol.mean()) - 1) * 100
        metatable = json.dumps(metatable)
        return metatable

    return datajson
Beispiel #3
0
def fx_list():
    fx_dict = {}
    filename = os.path.join(current_path(),
                            'static/csv_files/physical_currency_list.csv')
    with open(filename, newline='') as csvfile:
        reader = csv.reader(csvfile)
        fx_dict = {rows[0]: rows[1] for rows in reader}
    q = request.args.get("term")
    if q is None:
        q = ""
    list_key = {
        key: value
        for key, value in fx_dict.items() if q.upper() in key.upper()
    }
    list_value = {
        key: value
        for key, value in fx_dict.items() if q.upper() in value.upper()
    }
    list = {**list_key, **list_value}
    list = json.dumps(list)
    return list
Beispiel #4
0
def fxsymbol(fx, output='symbol'):
    # Gets an FX 3 letter symbol and returns the HTML symbol
    # Sample outputs are:
    # "EUR": {
    # "symbol": "",
    # "name": "Euro",
    # "symbol_native": "",
    # "decimal_digits": 2,
    # "rounding": 0,
    # "code": "EUR",
    # "name_plural": "euros"
    from warden_modules import current_path
    filename = os.path.join(current_path(), 'static/json_files/currency.json')
    with open(filename) as fx_json:
        fx_list = json.load(fx_json)
    try:
        out = fx_list[fx][output]
    except Exception:
        if output == 'all':
            return (fx_list[fx])
        out = fx
    return (out)
Beispiel #5
0
 def test_paths(self):
     print("Checking that current and home paths can be returned...")
     print(f"Current Path: {current_path()}")
     print(f"Home Path: {home_path()}")
     self.assertIsNotNone(current_path())
     self.assertIsNotNone(home_path())