def get_asset_operations(portfolio_id, asset_name):
  managed_portfolio = portfolio_manager.get_portfolio(portfolio_id)
  managed_asset = asset_manager.get_asset(managed_portfolio, asset_name)
  asset_operations = asset_manager.get_operations(managed_asset)

  return flask.jsonify([
      asset_operation.to_dict()
      for asset_operation in asset_operations.values()
  ])
Exemple #2
0
def get_asset(portfolio_id, asset_name):
    managed_portfolio = portfolio_manager.get_portfolio(portfolio_id)
    managed_asset = asset_manager.get_asset(managed_portfolio, asset_name)
    asset_operations = asset_manager.get_operations(managed_asset)
    asset_position = position_manager.get_position(managed_asset)

    return flask.render_template(
        'views/asset.jinja2',
        portfolio=managed_portfolio,
        asset=managed_asset,
        asset_operations=asset_operations,
        asset_position=asset_position,
    )
def update_portfolio_asset(portfolio_id, asset_code):
  managed_portfolio = portfolio_manager.get_portfolio(portfolio_id)
  managed_asset = asset_manager.get_asset(managed_portfolio, asset_code)

  request_data = flask.request.get_json()

  asset_name = request_data.get('asset_name')
  asset_price = float(request_data.get('asset_price', 0.0))
  asset_currency = request_data.get('asset_currency')

  managed_asset = asset_manager.update_asset(
      managed_portfolio, managed_asset, asset_name, asset_price,
      asset_currency)

  return managed_asset.to_dict()
def create_asset_operation(portfolio_id, asset_code):
  request_data = flask.request.get_json()

  managed_portfolio = portfolio_manager.get_portfolio(portfolio_id)
  managed_asset = asset_manager.get_asset(managed_portfolio, asset_code)

  timestamp_int = int(request_data['timestamp'])
  timestamp = datetime.datetime.fromtimestamp(timestamp_int)

  operation_type_name = request_data['operation_type']
  operation_type = operation_manager.get_operation_type(operation_type_name)

  quantity = int(request_data['quantity'])
  price_per_unit = float(request_data['price_per_unit'])
  operation_currency = request_data['operation_currency']

  new_operation = operation_manager.add_operation(
      managed_portfolio, managed_asset, timestamp, operation_type, quantity,
      price_per_unit, operation_currency)

  return new_operation.to_dict()
def update_asset_stats(portfolio_id, asset_name):
  managed_portfolio = portfolio_manager.get_portfolio(portfolio_id)
  managed_asset = asset_manager.get_asset(managed_portfolio, asset_name)
  asset_stats = stats_manager.update_asset_stats(managed_asset)

  return flask.jsonify(asset_stats.to_dict())
def get_portfolio_asset_balance(portfolio_id, asset_name):
  managed_portfolio = portfolio_manager.get_portfolio(portfolio_id)
  managed_asset = asset_manager.get_asset(managed_portfolio, asset_name)
  asset_position = position_manager.get_position(managed_asset)
  return asset_position.to_dict()
def delete_portfolio_asset(portfolio_id, asset_code):
  managed_portfolio = portfolio_manager.get_portfolio(portfolio_id)
  managed_asset = asset_manager.get_asset(managed_portfolio, asset_code)
  asset_manager.delete_asset(managed_portfolio, managed_asset)
  return managed_asset.to_dict()