aboutsummaryrefslogtreecommitdiff
path: root/src/info.c
blob: bde4bf4b4047801ac815475931d06a3b36d1a78b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "globals.h"

void info_handler(struct player_t *player)
{
    char *sym;
    printf("Enter the ticker symbol of the stock to get information for: ");
    sym = read_ticker();

    struct stock_t *stock = find_stock(player, sym);

    if(!stock)
    {
        printf("Couldn't find '%s' in portfolio.\n", sym);
        free(sym);
        return;
    }

    printf("Updating price data...\n");
    if(!get_stock_info(sym, &stock->current_price, &stock->fullname))
    {
        printf("Failed to update prices.\n");
        return;
    }

    free(sym);


    printf("Transaction history for '%s':\n", stock->symbol);
    printf("================================================================================\n");
    print_history(stock);
    printf("================================================================================\n");

    printf("Current price: $%llu.%02llu\n", stock->current_price.cents / 100, stock->current_price.cents % 100);
}