示例#1
0
def portfolio_list(request, investor_id):
    """
    Create portfolio.
    :param request:
    :param investor_id:
    :return:
    """

    if request.method == 'GET':
        #  Gets portfolios and return response
        portfolios = portfolio_services.get_portfolios(investor_id)
        return Response(PortfolioSerializer(portfolios, many=True).data,
                        status=status.HTTP_200_OK)

    if request.method == 'POST':

        # ------------------ Set Default Values -----------------#
        request.data['user'] = investor_id

        #  Set portfolio status to "Active" (1)
        request.data['status'] = 1
        # -------------------------------------------------------#

        serializer = PortfolioSerializer(data=request.data)
        return helper.save_serializer(serializer)
示例#2
0
def create_stock(stock):
    try:
        if jamstockex_api_service.is_stock_symbol_valid(stock['symbol']):
            serializer = StockSerializer(data=stock)
            return helper.save_serializer(serializer)
    except Exception as create_stock_error:
        print(create_stock_error)
示例#3
0
def create_plan_in_db(plan):
    try:
        serializer = PlanSerializer(data=plan)
        return helper.save_serializer(serializer)
    except Exception as e:
        print(e)
        raise e
示例#4
0
def new_investor(request):
    """
    Create an investor.
    :param request:
    :return:
    """
    if request.method == 'POST':

        serializer = InvestorSerializer(data=request.data)
        return helper.save_serializer(serializer)
示例#5
0
def new_notification(request, investor_id, portfolio_id, stock_name):
    """
    Retrieve, update or delete a portfolio stock notification.
    """
    stock = get_object_or_404(Stock, portfolio__user__id=investor_id, portfolio=portfolio_id,
                              symbol=stock_name)

    if request.method == 'POST':
        request.data['stock'] = stock.id
        serializer = NotificationSerializer(data=request.data)
        return helper.save_serializer(serializer)
示例#6
0
def create_transaction(transaction):
    """
    Create a transaction for a stock.
    :param transaction:
    :return:
    """

    try:
        transaction.update(get_transaction_calculation_response(transaction))
        serializer = TransactionSerializer(data=transaction)
        return helper.save_serializer(serializer)
    except Exception as create_transaction_error:
        raise create_transaction_error
示例#7
0
def plan(request, investor_id, portfolio_id, symbol):
    """
    Create a stock plan.
    :param request:
    :param investor_id:
    :param portfolio_id:
    :param symbol:
    :return:
    """

    if request.method == 'POST':
        stock = stock_services.get_stock_serializer(investor_id, portfolio_id,
                                                    symbol)
        request.data["stock"] = stock.id

        serializer = PlanSerializer(data=request.data)
        return helper.save_serializer(serializer)
示例#8
0
def stock_list(request, investor_id, portfolio_id):
    """

    :param request:
    :param investor_id:
    :param portfolio_id:
    :return:
    """

    if request.method == 'GET':
        return Response(stock_services.get_stocks(investor_id, portfolio_id))

    if request.method == 'POST':

        symbol = request.data['symbol']
        if jamstockex_api_service.is_stock_symbol_valid(symbol):
            stock_request_body = request.data
            stock_request_body['portfolio'] = portfolio_id
            serializer = StockSerializer(data=stock_request_body)

            return helper.save_serializer(serializer)
        return Response(CustomJsonResponse.return_portfolio_stock_not_found(), status=status.HTTP_400_BAD_REQUEST)