Skip to content

Commit 2aff4d1

Browse files
committed
Fix first price search
1 parent 0192f39 commit 2aff4d1

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

IG/sources/database/price/DBPrice.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ extension IG.Database.Request.Price {
155155
/// Returns the first price starting from a given date to an optional end date (or the last stored price) which matches the buying or selling price.
156156
/// - parameter epic: Instrument's epic (such as `CS.D.EURUSD.MINI.IP`).
157157
/// - parameter from: The date from which to start the query.
158-
/// - parameter to: The date from which to end the query.
158+
/// - parameter to: The date from which to end the query. If `nil`, all prices from `from` to the end available prices will be searched.
159159
/// - parameter buying: The buying price at which to match the price.
160160
/// - parameter selling: The selling price at which to match the price.
161161
/// - returns: A signal with price point matching the closure as value.
@@ -174,9 +174,9 @@ extension IG.Database.Request.Price {
174174
}
175175

176176
let buyPrice = Int32(clamping: buying, multiplyingByPowerOf10: IG.Database.Price.Point.powerOf10)
177-
query.append(" AND \(buyPrice) <= highBid")
177+
query.append(" AND (\(buyPrice) <= highBid")
178178
let sellPrice = Int32(clamping: selling, multiplyingByPowerOf10: IG.Database.Price.Point.powerOf10)
179-
query.append(" AND \(sellPrice) <= lowAsk")
179+
query.append(" OR \(sellPrice) >= lowAsk)")
180180

181181
query.append(" ORDER BY date ASC LIMIT 1")
182182
return (tableName, query)
@@ -320,9 +320,13 @@ extension IG.Database {
320320
extension IG.Database.Price {
321321
/// Price Snap.
322322
public struct Point: Decodable {
323-
/// Bid price (i.e. the price another trader is willing to sell a currency pair for).
323+
/// Bid price (i.e. the price another trader is willing to buy for).
324+
///
325+
/// The _bid price_ is always lower than the _ask price_.
324326
public let bid: Decimal
325-
/// Ask price (i.e. the price another trader will buy a currency pair at).
327+
/// Ask price (i.e. the price another trader will sell at).
328+
///
329+
/// The _ask price_ is always higher than the _bid price_.
326330
public let ask: Decimal
327331
/// The middle price between the *bid* and the *ask* price.
328332
public var mid: Decimal { self.bid + 0.5 * (self.ask - self.bid) }

0 commit comments

Comments
 (0)