-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
99 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// ScheduleUtils.swift | ||
// DXFeedFramework | ||
// | ||
// Created by Aleksey Kosylo on 10.10.23. | ||
// | ||
|
||
import Foundation | ||
import DXFeedFramework | ||
|
||
class ScheduleUtils { | ||
static func findNext5Days(_ profile: InstrumentProfile, time: Long, separator: String) throws -> String { | ||
let schedule = try DXSchedule(instrumentProfile: profile) | ||
var day: ScheduleDay? = try schedule.getDayByTime(time: time) | ||
var dates = [String]() | ||
dates.append("5 next holidays for \(profile.symbol):") | ||
for _ in 0..<5 { | ||
day = try day?.getNext(filter: DayFilter.holiday) | ||
dates.append("\(day?.yearMonthDay ?? 0)") | ||
} | ||
return dates.joined(separator: separator) | ||
} | ||
|
||
static func getSessions(_ profile: InstrumentProfile, time: Long) throws -> String { | ||
let schedule = try DXSchedule(instrumentProfile: profile) | ||
let session = try schedule.getSessionByTime(time: time) | ||
let nextTradingSession = session.isTrading ? session : try session.getNext(filter: .trading) | ||
let nearestSession = try schedule.getNearestSessionByTime(time: time, filter: .trading) | ||
|
||
func sessionDescription(_ session: ScheduleSession?) -> String { | ||
guard let session = session else { | ||
return "" | ||
} | ||
return session.toString() | ||
} | ||
return """ | ||
Current session for \(profile.symbol): \(sessionDescription(session)) | ||
Next trading session for \(profile.symbol): \(sessionDescription(nextTradingSession)) | ||
Nearest trading session for \(profile.symbol): \(sessionDescription(nearestSession)) | ||
""" | ||
} | ||
} |