Skip to content

Commit

Permalink
Feat: add new granularity values
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed Jan 9, 2023
1 parent 9986ea6 commit 7eefda3
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 16 deletions.
20 changes: 10 additions & 10 deletions OandaChandler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
3B226E542962D88100804ACA /* Socket in Frameworks */ = {isa = PBXBuildFile; productRef = 3B226E532962D88100804ACA /* Socket */; };
3B3349F3296B050500A0F03C /* Background.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3349F2296B050500A0F03C /* Background.swift */; };
3B5B5B20296199840084E90F /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B5B5B1F296199840084E90F /* Request.swift */; };
3B5B5B222961B6500084E90F /* Granularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B5B5B212961B6500084E90F /* Granularity.swift */; };
Expand All @@ -18,6 +17,7 @@
3B79971C295C6DB500AD242A /* Creating.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B79971B295C6DB500AD242A /* Creating.swift */; };
3B87BEC52961001800CCE50D /* AuthData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B87BEC42961001800CCE50D /* AuthData.swift */; };
3B87BEC62961019500CCE50D /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3B714149295B24BE00B5358A /* Preview Assets.xcassets */; };
3BB3AD2B296CC1BF00D5BDB3 /* Algorithms in Frameworks */ = {isa = PBXBuildFile; productRef = 3BB3AD2A296CC1BF00D5BDB3 /* Algorithms */; };
3BD8BCCA2960779800B7A908 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD8BCC92960779800B7A908 /* Date.swift */; };
3BD8BCCE29607E5600B7A908 /* Auth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD8BCCD29607E5600B7A908 /* Auth.swift */; };
3BD8BCD029608A3F00B7A908 /* KeychainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD8BCCF29608A3F00B7A908 /* KeychainController.swift */; };
Expand Down Expand Up @@ -46,7 +46,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3B226E542962D88100804ACA /* Socket in Frameworks */,
3BB3AD2B296CC1BF00D5BDB3 /* Algorithms in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -131,7 +131,7 @@
);
name = OandaChandler;
packageProductDependencies = (
3B226E532962D88100804ACA /* Socket */,
3BB3AD2A296CC1BF00D5BDB3 /* Algorithms */,
);
productName = TradingCronical;
productReference = 3B71413F295B24BC00B5358A /* OandaChandler.app */;
Expand Down Expand Up @@ -162,7 +162,7 @@
);
mainGroup = 3B714136295B24BC00B5358A;
packageReferences = (
3B226E522962D88100804ACA /* XCRemoteSwiftPackageReference "BlueSocket" */,
3BB3AD29296CC1BF00D5BDB3 /* XCRemoteSwiftPackageReference "swift-algorithms" */,
);
productRefGroup = 3B714140295B24BC00B5358A /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -402,21 +402,21 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
3B226E522962D88100804ACA /* XCRemoteSwiftPackageReference "BlueSocket" */ = {
3BB3AD29296CC1BF00D5BDB3 /* XCRemoteSwiftPackageReference "swift-algorithms" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Kitura/BlueSocket.git";
repositoryURL = "https://github.com/apple/swift-algorithms.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.0.0;
minimumVersion = 1.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
3B226E532962D88100804ACA /* Socket */ = {
3BB3AD2A296CC1BF00D5BDB3 /* Algorithms */ = {
isa = XCSwiftPackageProductDependency;
package = 3B226E522962D88100804ACA /* XCRemoteSwiftPackageReference "BlueSocket" */;
productName = Socket;
package = 3BB3AD29296CC1BF00D5BDB3 /* XCRemoteSwiftPackageReference "swift-algorithms" */;
productName = Algorithms;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"pins" : [
{
"identity" : "bluesocket",
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Kitura/BlueSocket.git",
"location" : "https://github.com/apple/swift-algorithms.git",
"state" : {
"revision" : "7b23a867008e0027bfd6f4d398d44720707bc8ca",
"version" : "2.0.4"
"revision" : "b14b7f4c528c942f121c8b860b9410b2bf57825e",
"version" : "1.0.0"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
}
],
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion OandaChandler/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ struct ContentView: View {
self.candles = []
}) { Text("Back") }.padding().disabled(isSavingFile)
}
let chartCandles = stride(from: 0, to: candles.count, by: candles.count / 100).map { candles[$0] }
let chartCandles = candles.count > 100
? stride(from: 0, to: candles.count, by: candles.count / 100).map { candles[$0] }
: candles
let minSeries = chartCandles.map { Double(getPricing(candle: $0).l)! }.min()!
let maxSeries = chartCandles.map { Double(getPricing(candle: $0).h)! }.max()!
Chart {
Expand Down
46 changes: 46 additions & 0 deletions OandaChandler/Granularity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import Foundation

enum Granularity: String, CaseIterable, Identifiable {
var id: String { rawValue }
case s5 = "S5"
case s10 = "S10"
case s15 = "S15"
case s30 = "S30"
case m1 = "M1"
case m2 = "M2"
case m5 = "M5"
Expand All @@ -18,9 +22,22 @@ enum Granularity: String, CaseIterable, Identifiable {
case h1 = "H1"
case h2 = "H2"
case h4 = "H4"
case h6 = "H6"
case h8 = "H8"
case h12 = "H12"
case d = "D"
case w = "W"

func getName() -> String {
switch self {
case .s5:
return "5 Second"
case .s10:
return "10 Second"
case .s15:
return "15 Second"
case .s30:
return "30 Second"
case .m1:
return "1 Minute"
case .m2:
Expand All @@ -39,6 +56,35 @@ enum Granularity: String, CaseIterable, Identifiable {
return "2 Hour"
case .h4:
return "4 Hour"
case .h6:
return "6 Hour"
case .h8:
return "8 Hour"
case .h12:
return "12 Hour"
case .d:
return "Day"
case .w:
return "Week"
}
}

func getTimeOffset() -> TimeInterval {
switch self {
case .s5:
return 0.5
case .s10:
return 1
case .s15:
return 2
case .s30:
return 4
case .m1:
return 8
case .m2:
return 16
default:
return 24
}
}

Expand Down
1 change: 1 addition & 0 deletions OandaChandler/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Request: ObservableObject {
let url = URL(string: uri)!
var req = URLRequest(url: url)
req.addValue("Bearer \(authData.token)", forHTTPHeaderField: "Authorization")
print(uri)
return try await URLSession.shared.data(for: req)
}

Expand Down
4 changes: 3 additions & 1 deletion OandaChandler/Views/Creating.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import SwiftUI
import Algorithms

enum OandaMode {
case FXTrade
Expand Down Expand Up @@ -50,7 +51,7 @@ struct CreatingView: View {

func fetchCandles(cb: (Double) -> Void) async {
let request = Request(authData)
let hour_count: Double = 8
let hour_count: Double = granularity.getTimeOffset()
let fromDate = Calendar.current.date(bySettingHour: 1, minute: 0, second: 0, of: from)!
let toDate = Calendar.current.date(bySettingHour: 1, minute: 0, second: 0, of: to)!
// Get the total amount of time units to calculate
Expand Down Expand Up @@ -118,6 +119,7 @@ struct CreatingView: View {
.sorted(by: { (a, b) in a.0 < b.0 })
.map { $0.1 }
.reduce([], +)
.uniqued(on: \.time)
}

var body: some View {
Expand Down

0 comments on commit 7eefda3

Please sign in to comment.