• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thorstenalpers / Finance.NET / 23104701747

15 Mar 2026 06:07AM UTC coverage: 93.634% (-0.8%) from 94.452%
23104701747

push

github

thorstenalpers
Update packages and exclude alpha vantage tests

501 of 615 branches covered (81.46%)

Branch coverage included in aggregate %.

1676 of 1710 relevant lines covered (98.01%)

7439.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.42
/src/Utilities/AlphaVantageParser.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Globalization;
4
using System.Linq;
5
using Ardalis.GuardClauses;
6
using Finance.Net.Enums;
7
using Finance.Net.Exceptions;
8
using Finance.Net.Models.AlphaVantage;
9
using Finance.Net.Models.AlphaVantage.Dtos;
10
using Microsoft.Extensions.Logging;
11
using Newtonsoft.Json;
12

13
namespace Finance.Net.Utilities;
14

15
/// <inheritdoc />
16
internal static class AlphaVantageParser
17
{
18
    public static List<IntradayRecord> ParseIntradayRecords(string symbol, EInterval interval, string jsonResponse)
19
    {
20
        var result = new List<IntradayRecord>();
30✔
21
        var data = JsonConvert.DeserializeObject<IntradayRecordRoot>(jsonResponse);
30✔
22

23
        var timeseries = interval switch
30!
24
        {
30✔
25
            EInterval.Interval_1Min => data?.TimeSeries1Min ?? throw new FinanceNetException($"no timeSeries for {symbol}"),
×
26
            EInterval.Interval_5Min => data?.TimeSeries5Min ?? throw new FinanceNetException($"no timeSeries for {symbol}"),
27!
27
            EInterval.Interval_15Min => data?.TimeSeries15Min ?? throw new FinanceNetException($"no timeSeries for {symbol}"),
2✔
28
            EInterval.Interval_30Min => data?.TimeSeries30Min ?? throw new FinanceNetException($"no timeSeries for {symbol}"),
×
29
            EInterval.Interval_60Min => data?.TimeSeries60Min ?? throw new FinanceNetException($"no timeSeries for {symbol}"),
×
30
            _ => throw new NotImplementedException(),
1✔
31
        };
30✔
32
        foreach (var item in timeseries)
5,456✔
33
        {
34
            var dateTime = DateTime.ParseExact(item.Key, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
2,700✔
35

36
            result.Add(new IntradayRecord
2,700✔
37
            {
2,700✔
38
                DateTime = dateTime,
2,700✔
39

2,700✔
40
                Open = item.Value.Open,
2,700✔
41
                Low = item.Value.Low,
2,700✔
42
                High = item.Value.High,
2,700✔
43
                Close = item.Value.Close,
2,700✔
44
                Volume = item.Value.Volume,
2,700✔
45
            });
2,700✔
46
        }
47
        return result;
28✔
48
    }
49

50
    public static List<Record> ParseRecords<T>(string symbol, DateTime? startDate, DateTime? endDate, string jsonResponse, ILogger<T> logger)
51
    {
52
        var result = new List<Record>();
4✔
53
        Guard.Against.Null(startDate);
4✔
54
        var data = JsonConvert.DeserializeObject<DailyRecordRoot>(jsonResponse);
4✔
55
        if (data?.TimeSeries == null)
4✔
56
        {
57
            throw new FinanceNetException("data is invalid");
1✔
58
        }
59
        foreach (var item in data.TimeSeries)
208✔
60
        {
61
            var today = item.Key.Date;
101✔
62
            if (today > endDate || today < startDate)
101!
63
            {
64
                continue;
65
            }
66
            if (result.Any(e => e.Date == today))
5,051!
67
            {
68
                logger.LogWarning("Bug: Course for {Symbol} for {Date} already added!", symbol, today.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
×
69
            }
70
            else
71
            {
72
                result.Add(new Record
101✔
73
                {
101✔
74
                    Date = today,
101✔
75
                    Open = item.Value.Open,
101✔
76
                    Low = item.Value.Low,
101✔
77
                    High = item.Value.High,
101✔
78
                    Close = item.Value.Close,
101✔
79
                    AdjustedClose = item.Value.AdjustedClose,
101✔
80
                    Volume = item.Value.Volume,
101✔
81
                    SplitCoefficient = item.Value.SplitCoefficient,
101✔
82
                });
101✔
83
            }
84
        }
85
        return result;
3✔
86
    }
87

88
    public static List<ForexRecord> ParseForexRecords<T>(string currency1, string currency2, DateTime startDate, DateTime? endDate, string jsonResponse, ILogger<T> logger)
89
    {
90
        var result = new List<ForexRecord>();
4✔
91
        var data = JsonConvert.DeserializeObject<DailyForexRecordRoot>(jsonResponse);
4✔
92
        if (data?.TimeSeries == null)
4✔
93
        {
94
            throw new FinanceNetException("data is invalid");
1✔
95
        }
96
        foreach (var item in data.TimeSeries)
210✔
97
        {
98
            var today = item.Key;
102✔
99
            if (today > endDate || today < startDate)
102!
100
            {
101
                continue;
102
            }
103
            if (result.Any(e => e.Date == today))
352!
104
            {
105
                logger.LogWarning("Bug: {Currency1} /{Currency2} for {Date} already added!", currency1, currency2, today.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
×
106
            }
107
            else
108
            {
109
                result.Add(new ForexRecord
27✔
110
                {
27✔
111
                    Date = item.Key,
27✔
112
                    Open = item.Value.Open,
27✔
113
                    Low = item.Value.Low,
27✔
114
                    High = item.Value.High,
27✔
115
                    Close = item.Value.Close,
27✔
116
                });
27✔
117
            }
118
        }
119
        return result;
3✔
120
    }
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc