Alkimia API

alkonlinequote.h
1/*
2 SPDX-FileCopyrightText: 2004 Ace Jones acejones @users.sourceforge.net
3 SPDX-FileCopyrightText: 2018 Ralf Habacker ralf.habacker @freenet.de
4 SPDX-FileCopyrightText: 2020 Thomas Baumgart <tbaumgart@kde.org>
5
6 This file is part of libalkimia.
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#ifndef ALKONLINEQUOTE_H
12#define ALKONLINEQUOTE_H
13
14#include <alkimia/alkvalue.h>
15
16#include <QDateTime>
17#include <QMap>
18#include <QObject>
19#include <QString>
20
22class AlkOnlineQuotesProfile;
23
25
26/**
27Retrieves a price quote from a web-based quote source
28
29@author Ace Jones acejones @users.sourceforge.net
30*/
31class ALK_EXPORT AlkOnlineQuote : public QObject
32{
33 Q_OBJECT
34public:
35 explicit AlkOnlineQuote(AlkOnlineQuotesProfile *profile = 0, QObject * = 0);
37
38 /**
39 * Hold errors reported from price quote fetching and parsing
40 *
41 * The implementation provides a type safe way to use
42 * bit operations like '|=' for combining values and '&'
43 * for checking value presence.
44 */
45 class ALK_EXPORT Errors
46 {
47 public:
48 enum Type {
49 None,
50 Data,
51 Date,
52 DatePattern,
53 DateFormat,
54 Price,
55 PricePattern,
56 Script,
57 Source,
58 Symbol,
59 Success,
60 Timeout,
61 URL,
62 };
63
64 Errors();
65 Errors(Type type);
66 Errors& operator|=(Type t);
67 bool operator &(Type t) const;
68 bool operator ==(Type t) const;
69 bool operator !=(Type t) const;
70 bool isEmpty() const;
71
72 protected:
73 QList<Type> m_type;
74 };
75
76 /**
77 * Supported values for returning prices in special cases
78 */
80 /**
81 * No handling of special cases
82 */
84 /**
85 * If no price is available in the specified period,
86 * but older ones are available, the most current price
87 * is returned.
88 */
90 /**
91 * If the date range has the same start and end date,
92 * is identical to the current date, no price was
93 * found but older ones are available, the most current
94 * price is returned. (Default)
95 */
96 AlwaysWhenToday
97 };
98
99 AlkOnlineQuotesProfile *profile();
100 void setProfile(AlkOnlineQuotesProfile *profile);
101
102 /**
103 * Set accepted language the online quote should be returned for
104 *
105 * @param language accepted language to set
106 */
107 void setAcceptLanguage(const QString &language);
108
109 /**
110 * Return actual used timeout for fetching online quotes
111 * If the returned value is -1, no timeout has been set.
112 * @return timeout
113 */
114 int timeout() const;
115
116 /**
117 * Set timeout for fetching online quotes
118 * If the timeout is != -1, a request to retrieve online quotes will be aborted
119 * if the time set with this function has been exceeded.
120 * @param newTimeout timeout in millseconds
121 */
122 void setTimeout(int newTimeout);
123
124 /**
125 * Defines a date range within which the data is to be retrieved.
126 * This range is only taken into account for data in CSV format and
127 * provides online quotes via the `quotes` signal.
128 * @param from first date to include the online quote
129 * @param to last date to include the online quote
130 */
131 void setDateRange(const QDate &from, const QDate &to);
132
133 /**
134 * Returns the status of the price to be returned for special date ranges.
135 *
136 * See setReturnLastPriceState() for details.
137 *
138 * @return current state used, see AlkOnlineQuote::LastPriceState for the supported values.
139 */
140 LastPriceState returnLastPriceState();
141
142 /**
143 * Sets the status of the price to be returned for special date range.
144 *
145 * This setting is intended for handling special cases when returning
146 * prices and rates, for example in cases where the time range for a
147 * price query does not match the delivered prices, e.g. because only
148 * today was specified and the last available price is from the day
149 * before yesterday.
150 *
151 * @param state the state to use, see AlkOnlineQuote::LastPriceState for the supported values.
152 */
153 void setReturnLastPriceState(LastPriceState state);
154
155 /**
156 * Always use signal `quote`.
157 * For online sources in CSV data format (see AlkOnlineQuoteSource::DataFormat),
158 * the quotes found are normally returned via the `quotes` signal,
159 * which can be changed to the `quote` signal using this method.
160 *
161 * This means that sources in CSV format can be processed via the
162 * same interface as other formats.
163 * @param state Enable or disable use of the `quote` signal
164 */
165 void setUseSingleQuoteSignal(bool state);
166
167 /**
168 * Returns the status of whether the `quote` signal is always used
169 * @return current state
170 */
171 bool useSingleQuoteSignal();
172
173 /**
174 * Returns the status whether a search with swapped symbols should
175 * be performed after a query for a symbol returned nothing.
176 * @return current state
177 */
178 bool enableReverseLaunch();
179
180 /**
181 * Set the status whether a search with swapped symbole should be
182 * performed after a query for a symbol returned nothing.
183 * @param state Enable or disable search with swapped symbols
184 */
185 void setEnableReverseLaunch(bool state);
186
187 /**
188 * Provides the currently used online source.
189 * @return online quote source
190 */
191 const AlkOnlineQuoteSource &source() const;
192
193public Q_SLOTS:
194 /**
195 * This launches a web-based quote update for the given @p _symbol.
196 * When the quote is received back from the web source, it will be
197 * emitted on the 'quote' signal.
198 *
199 * If services do not provide a date, parsing of the date can be disabled
200 * by specifying an empty date attribute of the given online source.
201 *
202 * If a timeout is set with @ref setTimeout() and the web source does not
203 * return the requested data, the update will be aborted after this time.
204 *
205 * @param _symbol the trading symbol of the stock to fetch a price for
206 * @param _id an arbitrary identifier, which will be emitted in the quote
207 * signal when a price is sent back.
208 * @param _source the source of the quote (must be a valid value returned
209 * by quoteSources(). Send QString() to use the default
210 * source.
211 * @return bool Whether the quote fetch process was launched successfully
212 * In case of failures it returns false and @ref errors()
213 * could be used to get error details.
214 */
215 bool launch(const QString &_symbol, const QString &_id, const QString &_source = QString());
216
217 /**
218 * If @ref launch() returns false, this method can be used to get details
219 * about the errors that occurred.
220 *
221 * @return bit map of errors, see class @ref Errors for details
222 */
223 const AlkOnlineQuote::Errors &errors();
224
226 void quote(QString id, QString symbol, QDate date, double price);
227 void quotes(const QString &id, const QString &symbol, const AlkDatePriceMap &prices);
228 void failed(QString id, QString symbol);
229 void status(QString s);
230 void error(QString s);
231
232private:
233 class Private;
234 Private *const d;
235
236protected:
237 Private &d_ptr();
238
239 friend class AlkOnlineQuotePrivateTest;
240};
241
242#endif // ALKONLINEQUOTE_H
Hold errors reported from price quote fetching and parsing.
Retrieves a price quote from a web-based quote source.
LastPriceState
Supported values for returning prices in special cases.
@ Always
If no price is available in the specified period, but older ones are available, the most current pric...
@ Off
No handling of special cases.
Q_SCRIPTABLE CaptureState status()
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.