Skip to content

Commit

Permalink
refactoring using date in millis cases
Browse files Browse the repository at this point in the history
remove unused tests
  • Loading branch information
kosyloa committed Jun 12, 2024
1 parent cdae424 commit 2f4e2cb
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions DXFeedFramework/Api/Osub/TimeSeriesSubscriptionSymbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class TimeSeriesSubscriptionSymbol: GenericIndexedEventSubscriptionSymbol
/// - symbol: The event symbol.
/// - date: Date. Just for easing initialization with date object
convenience public init(symbol: AnyHashable, date: Date) {
self.init(symbol: symbol, fromTime: Long(date.timeIntervalSince1970) * 1000)
self.init(symbol: symbol, fromTime: date.millisecondsSince1970)
}

/// Initializes a new instance of the ``TimeSeriesSubscriptionSymbol`` class
Expand All @@ -43,7 +43,7 @@ public class TimeSeriesSubscriptionSymbol: GenericIndexedEventSubscriptionSymbol
/// - symbol: The event ``Symbol``
/// - date: Date. Just for easing initialization with date object
convenience public init(symbol: Symbol, date: Date) {
self.init(symbol: symbol.stringValue, fromTime: Long(date.timeIntervalSince1970) * 1000)
self.init(symbol: symbol.stringValue, fromTime: date.millisecondsSince1970)
}

static func == (lhs: TimeSeriesSubscriptionSymbol, rhs: TimeSeriesSubscriptionSymbol) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Events/Market/Candles/Candle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class Candle: MarketEvent, ITimeSeriesEvent, ILastingEvent, CustomStringC
"""
DXFG_CANDLE_T \
eventSymbol: \(eventSymbol) \
eventTime: \(Date(timeIntervalSince1970: TimeInterval(Double(time/1000)))) \
eventTime: \(Date(millisecondsSince1970: time))) \
eventSymbol: \(eventSymbol), \
eventTime: \(eventTime), \
eventFlags: \(eventFlags), \
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Ipf/InstrumentProfileField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ extension InstrumentProfileField {
guard let date = dateFormatter.date(from: value) else {
return 0
}
parsedDates[value] = Entry(text: value, binary: date.millisecondsSince1970() / TimeUtil.day)
parsedDates[value] = Entry(text: value, binary: date.millisecondsSince1970 / TimeUtil.day)
return parsedDates[value]?.binary ?? 0
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ class NativeOnDemandService {
try ErrorCheck.nativeCall(thread,
dxfg_OnDemandService_replay(thread,
native,
date.millisecondsSince1970()))
date.millisecondsSince1970))
}

func replay(date: Date, speed: Double) throws {
let thread = currentThread()
try ErrorCheck.nativeCall(thread,
dxfg_OnDemandService_replay2(thread,
native,
date.millisecondsSince1970(),
date.millisecondsSince1970,
speed))
}

Expand Down
11 changes: 5 additions & 6 deletions DXFeedFramework/Utils/Date+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import Foundation

public extension Date {
func millisecondsSince1970() -> TimeInterval {
return timeIntervalSince1970 * 1000
}

func millisecondsSince1970() -> Long {
return Int64(timeIntervalSince1970 * 1000)
}
public var millisecondsSince1970: Long { Long(timeIntervalSince1970 * 1000) }

// func millisecondsSince1970 -> Long {
// return Int64(timeIntervalSince1970 * 1000)
// }

init(millisecondsSince1970: Long) {
self.init(timeIntervalSince1970: Double(millisecondsSince1970) / 1000)
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFrameworkTests/DXAsyncLastTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class DXAsyncLastTest: XCTestCase {
let date = Calendar.current.date(byAdding: .month, value: -1, to: Date())!
guard let task = feed?.getTimeSeries(type: Candle.self,
symbol: "AAPL{=1d}",
fromTime: date.millisecondsSince1970(),
fromTime: date.millisecondsSince1970,
toTime: Long.max) else {
XCTAssert(false, "Async task is nil")
return
Expand Down
12 changes: 9 additions & 3 deletions DXFeedFrameworkTests/DXConnectionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ final class DXConnectionTest: XCTestCase {
}

func testDXLinkConnectionTheoPrice() throws {
throw XCTSkip("Just for reflection testing")

// For token-based authorization, use the following address format:
// "dxlink:wss://demo.dxfeed.com/dxlink-ws[login=dxlink:token]"
let endpoint = try DXEndpoint.builder()
Expand All @@ -70,15 +72,19 @@ final class DXConnectionTest: XCTestCase {
let receivedEventsExpectation = expectation(description: "Received events")
let eventListener = DXConnectionListener(expectation: receivedEventsExpectation)
try subscription?.add(listener: eventListener)
try subscription?.addSymbols(".AAPL240524C110")
try subscription?.addSymbols(
TimeSeriesSubscriptionSymbol(symbol: ".AAPL240524C110", fromTime: 10)
)
try endpoint.connect("dxlink:wss://demo.dxfeed.com/dxlink-ws")
defer {
try? endpoint.closeAndAwaitTermination()
}
wait(for: [receivedEventsExpectation], timeout: 4)
wait(for: [receivedEventsExpectation], timeout: 10)
}

func testDXLinkConnectionGreeks() throws {
throw XCTSkip("Just for reflection testing")

// For token-based authorization, use the following address format:
// "dxlink:wss://demo.dxfeed.com/dxlink-ws[login=dxlink:token]"
let endpoint = try DXEndpoint.builder()
Expand All @@ -93,7 +99,7 @@ final class DXConnectionTest: XCTestCase {
defer {
try? endpoint.closeAndAwaitTermination()
}
wait(for: [receivedEventsExpectation], timeout: 4)
wait(for: [receivedEventsExpectation], timeout: 10)
}

func testConnection() throws {
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFrameworkTests/DXPromiseTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ final class DXPromiseTest: XCTestCase {

guard let promise = try feed?.getTimeSeriesPromise(type: Candle.self,
symbol: "AAPL{=1d}",
fromTime: date.millisecondsSince1970(),
fromTime: date.millisecondsSince1970,
toTime: Long.max) else {
XCTAssert(false, "Empty promise")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import DXFeedFramework
// await couldn't use directly in Playground(this is accompanied by errors like: execution stopped with unexpected state)
Task {
let baseSymbol = CandleSymbol.valueOf("AAPL", [CandlePeriod.day])
var toTime: Long = Long(Date.now.timeIntervalSince1970 * 1000)
let fromFime: Long = Long(Calendar.current.date(byAdding: .day,
var toTime: Long = Date.now.millisecondsSince1970
let fromFime: Long = Calendar.current.date(byAdding: .day,
value: -20,
to: Date())!.timeIntervalSince1970 * 1000)
to: Date())!.millisecondsSince1970
let endpoint = try DXEndpoint.getInstance().connect("demo.dxfeed.com:7300")
let feed = endpoint.getFeed()
guard let task = feed?.getTimeSeries(type: Candle.self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ do {

//// replaying events until end time reached
while (onDemand.getTime ?? Date.init(timeIntervalSince1970: 0)) < toDate {
if let time: Long = onDemand.getTime?.millisecondsSince1970() {
if let time: Long = onDemand.getTime?.millisecondsSince1970 {
let timeStr = (try? defaultTimeFormat.format(value: time)) ?? "empty string"
let connectedState = (try? onDemand.getEndpoint()?.getState()) ?? .notConnected
print("Current state is \(connectedState), on-demand time is \(timeStr)")
Expand Down

0 comments on commit 2f4e2cb

Please sign in to comment.