WU Trading Library 0.2.0
A backtesting and trading strategy library
Loading...
Searching...
No Matches
readers.h
Go to the documentation of this file.
1#ifndef WU_READER_H
2#define WU_READER_H
3
4#include <stdio.h>
5#include "types.h"
6#include "data.h"
7
8/**
9 * Base for a reader, which defines the minimal interface for reading the
10 * next data point from a data source and a method to free the reader's
11 * resources. The delete method should be called by the runner taking
12 * ownership of the reader. It is expected that specific reader
13 * implementations will extend this base structure and implement the
14 * defined methods.
15 */
16typedef struct WU_Reader_ {
17 void* (*next)(struct WU_Reader_* reader);
18 void (*delete)(struct WU_Reader_* reader);
19}* WU_Reader;
20
21#define wu_reader_next(reader) (((WU_Reader)(reader))->next((WU_Reader)(reader)))
22
23#define wu_reader_last_error(reader) ((reader)->last_error)
24
25#define wu_reader_delete(reader) do { \
26 if ((reader) && ((WU_Reader)(reader))->delete) \
27 ((WU_Reader)(reader))->delete((WU_Reader)(reader)); \
28} while(0)
29
30#define WU_CSV_MAX_LINE_SIZE 2048
31#define WU_JSON_MAX_LINE_SIZE 4096
32
38
45
46/**
47 * WU_CsvReader is a concrete implementation of the WU_Reader interface that
48 * reads data from a CSV file.
49 */
63
64/**
65 * WU_JsonReader is a concrete implementation of the WU_Reader interface that
66 * reads data from a JSON Lines file (one valid JSON object per line).
67 */
80
81WU_CsvReader wu_csv_reader_new(FILE *file, WU_DataType data_type,
82 WU_TimeUnit time_units, bool has_headers);
83
84WU_JsonReader wu_json_reader_new(FILE *file, WU_DataType data_type,
85 WU_TimeUnit time_units);
86
87#define WU_READER(r) ((WU_Reader)(r))
88#define wu_reader_list(...) ((WU_Reader[]){__VA_ARGS__, NULL})
89
90#endif // WU_READER_H
WU_CsvReader wu_csv_reader_new(FILE *file, WU_DataType data_type, WU_TimeUnit time_units, bool has_headers)
Definition csv.c:92
#define WU_JSON_MAX_LINE_SIZE
Definition readers.h:31
WU_CsvError
Definition readers.h:33
@ WU_CSV_OK
Definition readers.h:34
@ WU_CSV_ERROR_EOF
Definition readers.h:35
@ WU_CSV_ERROR_PARSE
Definition readers.h:36
WU_JsonReader wu_json_reader_new(FILE *file, WU_DataType data_type, WU_TimeUnit time_units)
Definition json.c:189
WU_JsonError
Definition readers.h:39
@ WU_JSON_ERROR_PARSE
Definition readers.h:42
@ WU_JSON_OK
Definition readers.h:40
@ WU_JSON_ERROR_MISSING_FIELD
Definition readers.h:43
@ WU_JSON_ERROR_EOF
Definition readers.h:41
#define WU_CSV_MAX_LINE_SIZE
Definition readers.h:30
WU_Candle represents an aggregated data point to represent how prices moved within a specific time pe...
Definition data.h:15
WU_CsvReader is a concrete implementation of the WU_Reader interface that reads data from a CSV file.
Definition readers.h:50
WU_CsvError last_error
Definition readers.h:56
WU_DataType data_type
Definition readers.h:55
WU_Single single_value
Definition readers.h:60
WU_Trade trade
Definition readers.h:59
WU_Candle candle
Definition readers.h:58
FILE * file
Definition readers.h:52
union WU_CsvReader_::@275024157131347166202211275356212357011047163065 data
bool has_headers
Definition readers.h:54
char line_buffer[WU_CSV_MAX_LINE_SIZE]
Definition readers.h:53
struct WU_Reader_ base
Definition readers.h:51
WU_JsonReader is a concrete implementation of the WU_Reader interface that reads data from a JSON Lin...
Definition readers.h:68
WU_JsonError last_error
Definition readers.h:73
union WU_JsonReader_::@145171373046065050065215303372316340344321156061 data
WU_Trade trade
Definition readers.h:76
WU_DataType data_type
Definition readers.h:72
struct WU_Reader_ base
Definition readers.h:69
WU_Candle candle
Definition readers.h:75
char line_buffer[WU_JSON_MAX_LINE_SIZE]
Definition readers.h:71
WU_Single single_value
Definition readers.h:77
FILE * file
Definition readers.h:70
Base for a reader, which defines the minimal interface for reading the next data point from a data so...
Definition readers.h:16
WU_Single represents a single value with a timestamp, which can be a price, an indicator value,...
Definition data.h:47
WU_Trade represents a single trade in the market, including the timestamp, price, volume,...
Definition data.h:32
WU_TimeUnit
WU_TimeUnit represents a unit of time used for time-based calculations such as time-weighted returns ...
Definition timeutils.h:10
WU_DataType
WU_DataType represents the type of input data, which can be a candle, a trade, or a single value.
Definition types.h:24