Skip to content

Commit

Permalink
Schedule sample CL: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 9, 2023
1 parent e0fdc8e commit 757610f
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 2 deletions.
4 changes: 4 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
64ECD6852A9DDF6200B36935 /* DXInstrumentProfileCollector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6842A9DDF6200B36935 /* DXInstrumentProfileCollector.swift */; };
64ECD6872A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6862A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift */; };
64FCAF902A572D4600971F4E /* libDxFeedGraalNativeSdk.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 64125E352A1F689A00FB32BA /* libDxFeedGraalNativeSdk.dylib */; platformFilters = (macos, ); settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
64FFE59F2AD430E4003D3353 /* ScheduleCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64FFE59E2AD430E4003D3353 /* ScheduleCommand.swift */; };
803BAC1629BFA50700FFAB1C /* DXFeedFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 803BAC0D29BFA50700FFAB1C /* DXFeedFramework.framework */; };
803BAC1C29BFA50700FFAB1C /* DxFeedSwiftFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 803BAC1029BFA50700FFAB1C /* DxFeedSwiftFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
8088D76529C0FBCE00F240CB /* ThreadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8088D76329C0FBCE00F240CB /* ThreadManager.swift */; };
Expand Down Expand Up @@ -708,6 +709,7 @@
64ECD6812A9DDC2800B36935 /* DXInstrumentProfileReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileReader.swift; sourceTree = "<group>"; };
64ECD6842A9DDF6200B36935 /* DXInstrumentProfileCollector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileCollector.swift; sourceTree = "<group>"; };
64ECD6862A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileConnection.swift; sourceTree = "<group>"; };
64FFE59E2AD430E4003D3353 /* ScheduleCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleCommand.swift; sourceTree = "<group>"; };
803BAC0D29BFA50700FFAB1C /* DXFeedFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DXFeedFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; };
803BAC1029BFA50700FFAB1C /* DxFeedSwiftFramework.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DxFeedSwiftFramework.h; sourceTree = "<group>"; };
803BAC1529BFA50700FFAB1C /* DXFeedFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DXFeedFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -854,6 +856,7 @@
645BE8512AC31E7C0028243D /* PerfTestCommand.swift */,
648BD5682AC450D6004A3A95 /* ConnectCommand.swift */,
6486B97E2AD4167800D8D5FA /* LiveIpfCommand.swift */,
64FFE59E2AD430E4003D3353 /* ScheduleCommand.swift */,
648BD56A2AC4576F004A3A95 /* HelpCommand.swift */,
648BD56C2AC56A04004A3A95 /* SubscriptionUtils.swift */,
);
Expand Down Expand Up @@ -1857,6 +1860,7 @@
641BDD582AC71CCE00236B78 /* LatencyTestCommand.swift in Sources */,
644FE5CD2AC1E9E200580E3A /* PerfDiagnostic.swift in Sources */,
644FE5CF2AC1F25900580E3A /* DXFTimer.swift in Sources */,
64FFE59F2AD430E4003D3353 /* ScheduleCommand.swift in Sources */,
647426A82ABC7F5E0012F793 /* ConnectEventListener.swift in Sources */,
644FE5CE2AC1EC1500580E3A /* TimeInterval+Ext.swift in Sources */,
64148B672ABB5C320063110E /* main.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "DXFeedLiveIpfSample https://demo:[email protected]/ipf"
argument = "ScheduleSample /Users/akosylo/Downloads/schedule.zip /Users/akosylo/Downloads/sample.ipf.zip IBM 2011-05-26-14:15:00"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "DXFeedLiveIpfSample https://demo:[email protected]/ipf"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Connect mddqa.in.devexperts.com:7400 Candle AAPL{=d} 20230201Z"
isEnabled = "NO">
Expand Down
17 changes: 17 additions & 0 deletions DXFeedFramework/Native/Schedule/NativeSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ class NativeSchedule {
}
}

public static func getTradingVenues(profile: InstrumentProfile ) throws -> [String] {
let thread = currentThread()
let mapper = InstrumentProfileMapper()
let native = mapper.toNative(instrumentProfile: profile)
var resultVenues = [String]()
if let result = try? ErrorCheck.nativeCall(thread, dxfg_Schedule_getTradingVenues(thread, native)) {
for index in 0..<result.pointee.size {
let venue = result.pointee.elements[Int(index)]
resultVenues.append(String(pointee: venue))
}
_ = try? ErrorCheck.nativeCall(thread,
dxfg_CList_String_release(thread,
result))
}
return resultVenues
}

public func getName() throws -> String {
let thread = currentThread()
let name = try ErrorCheck.nativeCall(thread, dxfg_Schedule_getName(thread, schedule))
Expand Down
8 changes: 8 additions & 0 deletions DXFeedFramework/Schedule/DXSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public class DXSchedule {
let native = try NativeSchedule(instrumentProfile: instrumentProfile, venue: venue)
self.init(native: native)
}
/// Returns trading venues for specified instrument profile.
/// - Parameters:
/// - profile: instrument profile those schedule is requested
/// - Returns: trading venue those schedule is requested
/// - Throws: GraalException. Rethrows exception from Java.recore
public static func getTradingVenues(profile: InstrumentProfile ) throws -> [String] {
return try NativeSchedule.getTradingVenues(profile: profile)
}

/// Returns day that contains specified time.
///
Expand Down
85 changes: 85 additions & 0 deletions Samples/PerfTestCL/ScheduleCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// ScheduleCommand.swift
// Tools
//
// Created by Aleksey Kosylo on 09.10.23.
//

import Foundation
import DXFeedFramework

class ScheduleCommand: ToolsCommand {
var cmd = "ScheduleSample"

var shortDescription = "A sample program that demonstrates different use cases of Schedule API."

var fullDescription: String =
"""
A sample program that demonstrates different use cases of Schedule API.
Usage:
usage: ScheduleSample <defaults> <profiles> <symbol> [time]
Where:
<defaults> is a URL to Schedule API defaults file
<profiles> is a URL to IPF file
<symbol> is a ticker symbol used for sample
[time] is a time used for sample in a format yyyy-MM-dd-HH:mm:ss
sample: ScheduleSample schedule.properties.zip sample.ipf.zip IBM 2011-05-26-14:15:00
"""

func execute() {
var arguments: [String]!
do {
arguments = try ArgumentParser().parse(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 3)
} catch {
print(fullDescription)
}
do {
let defaultFile = arguments[1]
let profileFile = arguments[2]
let symbol = arguments[3]

let fileManager = FileManager.default
if !fileManager.fileExists(atPath: defaultFile) {
throw ArgumentParserException.error(message: "File \(defaultFile) doesn't exist")
}
try DXSchedule.setDefaults(Data(contentsOf: URL(filePath: defaultFile)))

let reader = DXInstrumentProfileReader()
let profiles = try reader.readFromFile(address: profileFile)?.reduce(into: [String: InstrumentProfile]()) {
$0[$1.symbol] = $1
}
guard let profiles = profiles else {
fatalError("IPF Profiles is nil for \(profileFile)")
}
print("Loaded \(profiles.count) instrument profiles")
if arguments.count == 5 {
let time = arguments[4]
}


checkAllSchedules(Array(profiles.values))
} catch {
print("ScheduleSample error: \(error)")
}
}

private func checkAllSchedules(_ profiles: [InstrumentProfile]) {
var successes = 0
profiles.forEach { profile in
do {
let schedule = try DXSchedule(instrumentProfile: profile)
let venues = try DXSchedule.getTradingVenues(profile: profile)
successes += 1
} catch {
print("Error getting schedule for \(profile.symbol)(\(profile.tradingHours)): \(error)")
}
}

print("Checked \(profiles.count) instrument profiles: \(successes) successes, \((profiles.count - successes)) failures");

}
}
1 change: 1 addition & 0 deletions Samples/PerfTestCL/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let commands: [ToolsCommand] = [PerfTestCommand(),
ConnectCommand(),
LatencyTestCommand(),
LiveIpfCommand(),
ScheduleCommand(),
HelpCommand()]

func getCommand(_ cmd: String) -> ToolsCommand? {
Expand Down
2 changes: 1 addition & 1 deletion Samples/Utils/ArgumentParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Cmd \(cmd) contains not enough \(cmd.count - 1) arguments. Expected \(requiredNu
""")
}

return Array(cmd[1...cmd.count - 1])
return Array(cmd[1..<cmd.count])
}
}

0 comments on commit 757610f

Please sign in to comment.