Skip to content

Commit f20711f

Browse files
committed
Migration to Decimal64 1
1 parent f8d50f7 commit f20711f

25 files changed

Lines changed: 76 additions & 58 deletions

IG/IG.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@
793793
8D569217245FE63D00E9E621 /* c */,
794794
8DDB43AA2479704800A65CA5 /* CharacterSet.swift */,
795795
8D3C262422E9FA020080D3C1 /* Collections.swift */,
796+
8D911F6422ECF4CA0038E899 /* Decimal.swift */,
796797
8DDB43AD2479982800A65CA5 /* Foundation */,
797798
8DC4CA4B2149A6CE00344CBF /* Operators.swift */,
798799
8DE50471245AD09C001BD304 /* UnfairLock.swift */,
@@ -1065,7 +1066,6 @@
10651066
children = (
10661067
8DC4CA492149A6CE00344CBF /* Date.swift */,
10671068
8D9FB786231F943C00D76B6A /* DateFormatter.swift */,
1068-
8D911F6422ECF4CA0038E899 /* Decimal.swift */,
10691069
8D88F5F8246C79D900743B2B /* UTC.swift */,
10701070
);
10711071
path = Foundation;

IG/sources/api/API.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ public final class API {
1414
internal final let channel: IG.API.Channel
1515

1616
/// Namespace for endpoints related to the current API session (e.g. log in/out, refresh token, etc.).
17-
public final var session: IG.API.Request.Session { .init(api: self) }
17+
@inlinable public final var session: IG.API.Request.Session { .init(api: self) }
1818
/// Namespace for endpoints related to the user's account/s (e.g. account info, transactions, activity, etc.).
19-
public final var accounts: IG.API.Request.Accounts { .init(api: self) }
19+
@inlinable public final var accounts: IG.API.Request.Accounts { .init(api: self) }
2020
/// Namespace for endpoints related to the IG markets (e.g. market info, snapshots, etc.).
21-
public final var markets: IG.API.Request.Markets { .init(api: self) }
21+
@inlinable public final var markets: IG.API.Request.Markets { .init(api: self) }
2222
/// Namespace for endpoints related to price data point retrieval (e.g. return all data points for EUR/USD market with resolution of 1 minute).
23-
public final var price: IG.API.Request.Price { .init(api: self) }
23+
@inlinable public final var price: IG.API.Request.Price { .init(api: self) }
2424
/// Namespace for endpoints related to open positions (e.g. create a position, tweak it, or close it).
25-
public final var positions: IG.API.Request.Positions { .init(api: self) }
25+
@inlinable public final var positions: IG.API.Request.Positions { .init(api: self) }
2626
/// Namespace for endpoints related to open working orders (e.g. create a working order, tweak it, or close it).
27-
public final var workingOrders: IG.API.Request.WorkingOrders { .init(api: self) }
27+
@inlinable public final var workingOrders: IG.API.Request.WorkingOrders { .init(api: self) }
2828
/// Namespace for endpoints related to IG nodes; that is what IG uses to navigate its tree of available markets.
29-
public final var nodes: IG.API.Request.Nodes { .init(api: self) }
29+
@inlinable public final var nodes: IG.API.Request.Nodes { .init(api: self) }
3030
/// Namespace for endpoints related to watchlist management (e.g. create/remove watchlist, add/remove markets to it, etc.).
31-
public final var watchlists: IG.API.Request.Watchlists { .init(api: self) }
31+
@inlinable public final var watchlists: IG.API.Request.Watchlists { .init(api: self) }
3232
/// Namespace for endpoints related to endpoints scrapped from IG website (e.g. economic calendar).
33-
public final var scrapped: IG.API.Request.Scrapped { .init(api: self) }
33+
@inlinable public final var scrapped: IG.API.Request.Scrapped { .init(api: self) }
3434

3535
/// Initializer for an API instance, giving you the default options.
3636
///

IG/sources/api/accounts/APIAccounts.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ extension IG.API.Request {
55
/// List of endpoints related to user accounts.
66
public struct Accounts {
77
/// Pointer to the actual API instance in charge of calling the endpoint.
8-
internal unowned let api: IG.API
8+
@usableFromInline internal unowned let api: IG.API
99
/// Hidden initializer passing the instance needed to perform the endpoint.
1010
/// - parameter api: The instance calling the actual endpoints.
11-
init(api: IG.API) { self.api = api }
11+
@usableFromInline internal init(api: IG.API) { self.api = api }
1212
}
1313
}
1414

IG/sources/api/dealings/APIPosition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extension IG.API.Request {
88
internal unowned let api: IG.API
99
/// Hidden initializer passing the instance needed to perform the endpoint.
1010
/// - parameter api: The instance calling the actual endpoint.
11-
init(api: IG.API) { self.api = api }
11+
@usableFromInline internal init(api: IG.API) { self.api = api }
1212
}
1313
}
1414

IG/sources/api/dealings/APIWorkingOrder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extension IG.API.Request {
88
internal unowned let api: IG.API
99
/// Hidden initializer passing the instance needed to perform the endpoint.
1010
/// - parameter api: The instance calling the actual endpoint.
11-
init(api: IG.API) { self.api = api }
11+
@usableFromInline internal init(api: IG.API) { self.api = api }
1212
}
1313
}
1414

IG/sources/api/entities/APIAccount.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Foundation
1+
import Decimals
22

33
extension IG.API {
44
/// Client account.
@@ -73,13 +73,13 @@ extension IG.API.Account {
7373
/// Account balances.
7474
public struct Balance: Decodable {
7575
/// Balance of funds in the account.
76-
public let value: Decimal
76+
public let value: Decimal64
7777
/// Minimum deposit amount required for margins.
78-
public let deposit: Decimal
78+
public let deposit: Decimal64
7979
/// Profit & Loss amount.
80-
public let profitLoss: Decimal
80+
public let profitLoss: Decimal64
8181
/// Amount available for trading.
82-
public let available: Decimal
82+
public let available: Decimal64
8383

8484
private enum CodingKeys: String, CodingKey {
8585
case value = "balance"
@@ -88,7 +88,7 @@ extension IG.API.Account {
8888
case available
8989
}
9090
}
91-
91+
9292
/// Account preferences.
9393
public struct Preferences: Decodable {
9494
/// Whether the user wants to be allowed to define trailing stop rules for his trade operations.

IG/sources/api/entities/APIChannel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ extension IG.API {
77
/// The `URLSession` instance performing the HTTPS requests.
88
internal let session: URLSession
99

10-
/// The credentials used to call API endpoints.
11-
private var _credentials: IG.API.Credentials?
1210
/// The lock used to restrict access to the credentials.
1311
private let _lock: UnfairLock
12+
/// The credentials used to call API endpoints.
13+
private var _credentials: IG.API.Credentials?
1414
/// The processing queue for the status cancellable.
1515
private let _scheduler: DispatchQueue
1616

IG/sources/api/entities/APICredentials.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extension IG.API {
6868
}
6969

7070
/// Returns `true` when the `expirationDate` is in the past.
71-
public var isExpired: Bool {
71+
@_transparent public var isExpired: Bool {
7272
self.expirationDate < Date()
7373
}
7474
}

IG/sources/api/entities/APIKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension IG.API {
44
public let rawValue: String
55

66
public init(stringLiteral value: String) {
7-
guard Self._validate(value) else { fatalError("The API key provided is not in a valid format") }
7+
precondition(Self._validate(value), "The API key provided is not in a valid format")
88
self.rawValue = value
99
}
1010

IG/sources/api/entities/APIUser.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
extension IG.API {
42
/// A user within the platform.
53
public struct User: ExpressibleByArrayLiteral {
@@ -11,7 +9,7 @@ extension IG.API {
119
/// Initializer providing already with fully formed sub-instances.
1210
/// - parameter name: The user's platform name.
1311
/// - parameter password: The user's password.
14-
@inlinable public init(_ name: Self.Name, _ password: Self.Password) {
12+
@_transparent public init(_ name: Self.Name, _ password: Self.Password) {
1513
self.name = name
1614
self.password = password
1715
}
@@ -20,14 +18,14 @@ extension IG.API {
2018
/// - parameter name: The user's platform name.
2119
/// - parameter password: The user's password.
2220
/// - returns: `nil` if the objects were malformed.
23-
@inlinable public init?(name: String, passsword: String) {
21+
@_transparent public init?(name: String, passsword: String) {
2422
guard let username = Self.Name(rawValue: name),
2523
let password = Self.Password(rawValue: passsword) else { return nil }
2624
self.init(username, password)
2725
}
2826

29-
@inlinable public init(arrayLiteral elements: String...) {
30-
guard elements.count == 2 else { fatalError("A '\(Self.self)' type can only be initialized with an array with two non-empty strings") }
27+
@_transparent public init(arrayLiteral elements: String...) {
28+
precondition(elements.count == 2, "A '\(API.self).\(Self.self)' type can only be initialized with an array with two non-empty strings")
3129
self.init(.init(stringLiteral: elements[0]), .init(stringLiteral: elements[1]))
3230
}
3331
}
@@ -39,7 +37,7 @@ extension IG.API.User {
3937
public let rawValue: String
4038

4139
public init(stringLiteral value: String) {
42-
guard Self._validate(value) else { fatalError("The username '\(value)' is not in a valid format") }
40+
precondition(Self._validate(value), "The username '\(value)' is not in a valid format")
4341
self.rawValue = value
4442
}
4543

@@ -48,7 +46,7 @@ extension IG.API.User {
4846
self.rawValue = rawValue
4947
}
5048

51-
@inlinable public init?(_ description: String) {
49+
@_transparent public init?(_ description: String) {
5250
self.init(rawValue: description)
5351
}
5452

@@ -62,7 +60,7 @@ extension IG.API.User {
6260
self.rawValue = name
6361
}
6462

65-
public static func < (lhs: Self, rhs: Self) -> Bool {
63+
@_transparent public static func < (lhs: Self, rhs: Self) -> Bool {
6664
lhs.rawValue < rhs.rawValue
6765
}
6866

@@ -83,7 +81,7 @@ extension IG.API.User {
8381
public let rawValue: String
8482

8583
public init(stringLiteral value: String) {
86-
guard Self._validate(value) else { fatalError("The password is not in a valid format") }
84+
precondition(Self._validate(value), "The password is not in a valid format")
8785
self.rawValue = value
8886
}
8987

0 commit comments

Comments
 (0)