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

KDE's Doxygen guidelines are available online.