Skip to content

Commit

Permalink
Schedule: WIP
Browse files Browse the repository at this point in the history
next/prev day,
next/prev session
  • Loading branch information
kosyloa committed Sep 18, 2023
1 parent 32441b9 commit 8bfbc95
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 13 deletions.
24 changes: 24 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@
64ACBCE82A28CF9700032C53 /* IndexedEventSubscriptionSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ACBCE72A28CF9700032C53 /* IndexedEventSubscriptionSymbol.swift */; };
64ACBCEA2A28DDDA00032C53 /* TestEventListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ACBCE92A28DDDA00032C53 /* TestEventListener.swift */; };
64ACBCEC2A29FE2300032C53 /* XCTestCase+Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641BCBB32A1F8ABA00FE23C2 /* XCTestCase+Utils.swift */; };
64B4363A2AB86D1A0003919E /* DayFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B436392AB86D1A0003919E /* DayFilter.swift */; };
64B4363C2AB86F3C0003919E /* DayFilter+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B4363B2AB86F3C0003919E /* DayFilter+Ext.swift */; };
64B4363E2AB883350003919E /* SessionFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B4363D2AB883350003919E /* SessionFilter.swift */; };
64B436402AB8857F0003919E /* SessionFilter+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B4363F2AB8857F0003919E /* SessionFilter+Ext.swift */; };
64B436422AB88DE70003919E /* NativeSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B436412AB88DE70003919E /* NativeSession.swift */; };
64B436442AB88EA40003919E /* NativeDay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B436432AB88EA40003919E /* NativeDay.swift */; };
64B627352A375C0F00196D07 /* QuoteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B627292A375C0E00196D07 /* QuoteModel.swift */; };
64B627382A375C0F00196D07 /* QuoteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B6272C2A375C0E00196D07 /* QuoteViewController.swift */; };
64B627392A375C0F00196D07 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64B6272D2A375C0E00196D07 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -534,6 +540,12 @@
64ACBCE52A28BA7D00032C53 /* SymbolMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolMapper.swift; sourceTree = "<group>"; };
64ACBCE72A28CF9700032C53 /* IndexedEventSubscriptionSymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndexedEventSubscriptionSymbol.swift; sourceTree = "<group>"; };
64ACBCE92A28DDDA00032C53 /* TestEventListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestEventListener.swift; sourceTree = "<group>"; };
64B436392AB86D1A0003919E /* DayFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayFilter.swift; sourceTree = "<group>"; };
64B4363B2AB86F3C0003919E /* DayFilter+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DayFilter+Ext.swift"; sourceTree = "<group>"; };
64B4363D2AB883350003919E /* SessionFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionFilter.swift; sourceTree = "<group>"; };
64B4363F2AB8857F0003919E /* SessionFilter+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionFilter+Ext.swift"; sourceTree = "<group>"; };
64B436412AB88DE70003919E /* NativeSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSession.swift; sourceTree = "<group>"; };
64B436432AB88EA40003919E /* NativeDay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeDay.swift; sourceTree = "<group>"; };
64B627152A375BBA00196D07 /* DXQuoteTableApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DXQuoteTableApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
64B627292A375C0E00196D07 /* QuoteModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuoteModel.swift; sourceTree = "<group>"; };
64B6272C2A375C0E00196D07 /* QuoteViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuoteViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -904,6 +916,8 @@
6498E6B12AB1D41A0093A065 /* DXSchedule.swift */,
6498E6B82AB1DFDB0093A065 /* ScheduleDay.swift */,
6498E6BC2AB1E0510093A065 /* ScheduleSession.swift */,
64B436392AB86D1A0003919E /* DayFilter.swift */,
64B4363D2AB883350003919E /* SessionFilter.swift */,
);
path = Schedule;
sourceTree = "<group>";
Expand All @@ -913,6 +927,10 @@
children = (
6498E6B42AB1D4480093A065 /* NativeSchedule.swift */,
6498E6C32AB20B860093A065 /* ScheduleSessionType+Ext.swift */,
64B4363B2AB86F3C0003919E /* DayFilter+Ext.swift */,
64B4363F2AB8857F0003919E /* SessionFilter+Ext.swift */,
64B436412AB88DE70003919E /* NativeSession.swift */,
64B436432AB88EA40003919E /* NativeDay.swift */,
);
path = Schedule;
sourceTree = "<group>";
Expand Down Expand Up @@ -1700,6 +1718,7 @@
8088D77129C3A25D00F240CB /* SystemProperty.swift in Sources */,
640C3FD42A6179AB00555161 /* CandlePeriod.swift in Sources */,
6498E6B92AB1DFDB0093A065 /* ScheduleDay.swift in Sources */,
64B436422AB88DE70003919E /* NativeSession.swift in Sources */,
6469F8C22A3B169A00846831 /* MathUtil.swift in Sources */,
80FC415929C8EE8B00E6B611 /* DXEndpoint.swift in Sources */,
64C771F62A94ADDA009868C2 /* Direction.swift in Sources */,
Expand All @@ -1723,8 +1742,10 @@
6498E6B22AB1D41A0093A065 /* DXSchedule.swift in Sources */,
646407572AA0C44D006FF769 /* NativeInstrumentProfileCollector.swift in Sources */,
64ACBCDF2A2897EA00032C53 /* String+Symbol.swift in Sources */,
64B4363A2AB86D1A0003919E /* DayFilter.swift in Sources */,
64ECD6872A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift in Sources */,
64278C702A602FA00074B5AA /* Candle+Ext.swift in Sources */,
64B4363C2AB86F3C0003919E /* DayFilter+Ext.swift in Sources */,
6464075B2AA0CEF2006FF769 /* NativeExecutor.swift in Sources */,
64DA26B82AA20095005B1757 /* NativeInstrumentProfileConnection.swift in Sources */,
64104FC32A210F2400D1FC41 /* EventCode+Native.swift in Sources */,
Expand All @@ -1737,6 +1758,8 @@
642BE4CE2A2E29270052340A /* EventMapper.swift in Sources */,
6447A5DB2A8E559000739CCF /* ILastingEvent.swift in Sources */,
64ACBCDD2A28978600032C53 /* Symbol.swift in Sources */,
64B4363E2AB883350003919E /* SessionFilter.swift in Sources */,
64B436402AB8857F0003919E /* SessionFilter+Ext.swift in Sources */,
646407592AA0CA8D006FF769 /* NativeProfileIterator.swift in Sources */,
6469F8C82A3B25C900846831 /* MarketEvent+Access.swift in Sources */,
640C3FD22A6178D200555161 /* CandleSession.swift in Sources */,
Expand Down Expand Up @@ -1798,6 +1821,7 @@
64BA92672A306E3100BE26A0 /* Trade+Ext.swift in Sources */,
640C3FD62A6179E300555161 /* CandleAlignment.swift in Sources */,
640C3FCC2A616B6200555161 /* ArgumentException.swift in Sources */,
64B436442AB88EA40003919E /* NativeDay.swift in Sources */,
642BE4C42A2E1AFF0052340A /* Quote.swift in Sources */,
64656F602A1B9EC2006A0B19 /* EnumUtil.swift in Sources */,
642BE4CA2A2E1C640052340A /* MarketEvent.swift in Sources */,
Expand Down
79 changes: 79 additions & 0 deletions DXFeedFramework/Native/Schedule/DayFilter+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// DayFilter+Ext.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 18.09.23.
//

import Foundation
@_implementationOnly import graal_api

extension DayFilter {
init(value: dxfg_day_filter_prepare_t) {
switch value {
case DXFG_DAY_FILTER_ANY:
self = .any
case DXFG_DAY_FILTER_TRADING:
self = .trading
case DXFG_DAY_FILTER_NON_TRADING:
self = .nonTrading
case DXFG_DAY_FILTER_HOLIDAY:
self = .holiday
case DXFG_DAY_FILTER_SHORT_DAY:
self = .shortDay
case DXFG_DAY_FILTER_MONDAY:
self = .monday
case DXFG_DAY_FILTER_TUESDAY:
self = .tuesday
case DXFG_DAY_FILTER_WEDNESDAY:
self = .wednesday
case DXFG_DAY_FILTER_THURSDAY:
self = .thursday
case DXFG_DAY_FILTER_FRIDAY:
self = .friday
case DXFG_DAY_FILTER_SATURDAY:
self = .saturday
case DXFG_DAY_FILTER_SUNDAY:
self = .sunday
case DXFG_DAY_FILTER_WEEK_DAY:
self = .weekDay
case DXFG_DAY_FILTER_WEEK_END:
self = .weekEnd
default:
fatalError("Wrong qd-value \(value) for DayFilter")
}
}

func toQDValue() -> dxfg_day_filter_prepare_t {
switch self {
case .any:
return DXFG_DAY_FILTER_ANY
case .trading:
return DXFG_DAY_FILTER_TRADING
case .nonTrading:
return DXFG_DAY_FILTER_NON_TRADING
case .holiday:
return DXFG_DAY_FILTER_HOLIDAY
case .shortDay:
return DXFG_DAY_FILTER_SHORT_DAY
case .monday:
return DXFG_DAY_FILTER_MONDAY
case .tuesday:
return DXFG_DAY_FILTER_TUESDAY
case .wednesday:
return DXFG_DAY_FILTER_WEDNESDAY
case .thursday:
return DXFG_DAY_FILTER_THURSDAY
case .friday:
return DXFG_DAY_FILTER_FRIDAY
case .saturday:
return DXFG_DAY_FILTER_SATURDAY
case .sunday:
return DXFG_DAY_FILTER_SUNDAY
case .weekDay:
return DXFG_DAY_FILTER_WEEK_DAY
case .weekEnd:
return DXFG_DAY_FILTER_WEEK_END
}
}
}
23 changes: 23 additions & 0 deletions DXFeedFramework/Native/Schedule/NativeDay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// NativeDay.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 18.09.23.
//

import Foundation
@_implementationOnly import graal_api

class NativeDay {
let native: UnsafeMutablePointer<dxfg_day_t>

init(native: UnsafeMutablePointer<dxfg_day_t>) {
self.native = native
}

deinit {
let thread = currentThread()
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(native.pointee.handler)))
}

}
91 changes: 82 additions & 9 deletions DXFeedFramework/Native/Schedule/NativeSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,25 @@ class NativeSchedule {
public func getDayByTime(time: Long) throws -> ScheduleDay {
let thread = currentThread()
let day = try ErrorCheck.nativeCall(thread, dxfg_Schedule_getDayByTime(thread, schedule, time))
let scheduleDay = try createDay(thread, day)
return scheduleDay
defer {
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(day.pointee.handler)))
}
return try createDay(thread, day)
}

public func getDayById(dayId: Int32) throws -> ScheduleDay {
let thread = currentThread()
let day = try ErrorCheck.nativeCall(thread, dxfg_Schedule_getDayById(thread, schedule, dayId))
defer {
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(day.pointee.handler)))
}
return try createDay(thread, day)
}

private func createDay(_ thread: OpaquePointer?,
_ day: UnsafeMutablePointer<dxfg_day_t>) throws -> ScheduleDay {
let scheduleDay = ScheduleDay()
scheduleDay.nativeSchedule = self
scheduleDay.dayId = try ErrorCheck.nativeCall(thread, dxfg_Day_getDayId(thread, day))
scheduleDay.yearMonthDay = try ErrorCheck.nativeCall(thread, dxfg_Day_getYearMonthDay(thread, day))
scheduleDay.year = try ErrorCheck.nativeCall(thread, dxfg_Day_getYear(thread, day))
Expand All @@ -105,16 +111,83 @@ class NativeSchedule {
let count = sessions.pointee.size
for index in 0..<Int(count) {
if let element = sessions.pointee.elements[index] {
let start = try ErrorCheck.nativeCall(thread, dxfg_Session_getStartTime(thread, element))
let end = try ErrorCheck.nativeCall(thread, dxfg_Session_getEndTime(thread, element))
let nativeType = try ErrorCheck.nativeCall(thread, dxfg_Session_getType(thread, element))
let type = dxfg_session_type_t(UInt32(nativeType))
let session = ScheduleSession(startTime: start,
endTime: end,
type: ScheduleSessionType.getValueFromNative(type))
let session = try createSession(thread,
session: element)
scheduleDay.sessions.append(session)
}
}
return scheduleDay
}

private func createSession(_ thread: OpaquePointer?,
session: UnsafeMutablePointer<dxfg_session_t>) throws -> ScheduleSession {
let start = try ErrorCheck.nativeCall(thread, dxfg_Session_getStartTime(thread, session))
let end = try ErrorCheck.nativeCall(thread, dxfg_Session_getEndTime(thread, session))
let nativeType = try ErrorCheck.nativeCall(thread, dxfg_Session_getType(thread, session))
let type = dxfg_session_type_t(UInt32(nativeType))
let session = ScheduleSession(native: NativeSession(native: session),
nativeSchedule: self,
startTime: start,
endTime: end,
type: ScheduleSessionType.getValueFromNative(type))
return session
}

internal func getNextDay(after day: ScheduleDay, filter: DayFilter ) throws -> ScheduleDay? {
let qdValue = filter.toQDValue()
let thread = currentThread()
let filter = try ErrorCheck.nativeCall(thread, dxfg_DayFilter_getInstance(thread, qdValue))
let currentDay = try ErrorCheck.nativeCall(thread, dxfg_Schedule_getDayById(thread, schedule, day.dayId))
let nextDay = try ErrorCheck.nativeCall(thread, dxfg_Day_getNextDay(thread, currentDay, filter))
let day = try? createDay(thread, nextDay)
try ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(nextDay.pointee.handler)))
return day
}

internal func getPrevtDay(before day: ScheduleDay, filter: DayFilter ) throws -> ScheduleDay? {
let qdValue = filter.toQDValue()
let thread = currentThread()
let filter = try ErrorCheck.nativeCall(thread, dxfg_DayFilter_getInstance(thread, qdValue))
defer {
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(filter.pointee.handler)))
}
let currentDay = try ErrorCheck.nativeCall(thread, dxfg_Schedule_getDayById(thread, schedule, day.dayId))
defer {
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(currentDay.pointee.handler)))
}
let prevDay = try ErrorCheck.nativeCall(thread, dxfg_Day_getPrevDay(thread, currentDay, filter))
defer {
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(prevDay.pointee.handler)))
}
let day = try? createDay(thread, prevDay)
return day
}

internal func getNextSession(after session: ScheduleSession, filter: SessionFilter ) throws -> ScheduleSession? {
let qdValue = filter.toQDValue()
let thread = currentThread()
let filter = try ErrorCheck.nativeCall(thread, dxfg_SessionFilter_getInstance(thread, qdValue))
defer {
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(filter.pointee.handler)))
}
let currentSession = session.native.native
let nextSession = try ErrorCheck.nativeCall(thread,
dxfg_Session_getNextSession(thread, currentSession, filter))
let session = try createSession(thread, session: nextSession)
return session
}

internal func getPrevtSession(before session: ScheduleSession, filter: SessionFilter ) throws -> ScheduleSession? {
let qdValue = filter.toQDValue()
let thread = currentThread()
let filter = try ErrorCheck.nativeCall(thread, dxfg_SessionFilter_getInstance(thread, qdValue))
defer {
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(filter.pointee.handler)))
}
let currentSession = session.native.native
let nextSession = try ErrorCheck.nativeCall(thread,
dxfg_Session_getPrevSession(thread, currentSession, filter))
let session = try createSession(thread, session: nextSession)
return session
}
}
22 changes: 22 additions & 0 deletions DXFeedFramework/Native/Schedule/NativeSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// NativeSession.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 18.09.23.
//

import Foundation
@_implementationOnly import graal_api

class NativeSession {
let native: UnsafeMutablePointer<dxfg_session_t>

init(native: UnsafeMutablePointer<dxfg_session_t>) {
self.native = native
}

deinit {
let thread = currentThread()
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(native.pointee.handler)))
}
}
51 changes: 51 additions & 0 deletions DXFeedFramework/Native/Schedule/SessionFilter+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// SessionFilter+Ext.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 18.09.23.
//

import Foundation
@_implementationOnly import graal_api

extension SessionFilter {
init(value: dxfg_session_filter_prepare_t) {
switch value {
case DXFG_SESSION_FILTER_ANY:
self = .any
case DXFG_SESSION_FILTER_TRADING:
self = .trading
case DXFG_SESSION_FILTER_NON_TRADING:
self = .nonTrading
case DXFG_SESSION_FILTER_NO_TRADING:
self = .noTrading
case DXFG_SESSION_FILTER_PRE_MARKET:
self = .preMarket
case DXFG_SESSION_FILTER_REGULAR:
self = .regular
case DXFG_SESSION_FILTER_AFTER_MARKET:
self = .afterMarket
default:
fatalError("Wrong qd-value \(value) for DayFilter")
}
}

func toQDValue() -> dxfg_session_filter_prepare_t {
switch self {
case .any:
return DXFG_SESSION_FILTER_ANY
case .trading:
return DXFG_SESSION_FILTER_TRADING
case .nonTrading:
return DXFG_SESSION_FILTER_NON_TRADING
case .noTrading:
return DXFG_SESSION_FILTER_NO_TRADING
case .preMarket:
return DXFG_SESSION_FILTER_PRE_MARKET
case .regular:
return DXFG_SESSION_FILTER_REGULAR
case .afterMarket:
return DXFG_SESSION_FILTER_AFTER_MARKET
}
}
}
Loading

0 comments on commit 8bfbc95

Please sign in to comment.