Skip to content

Commit

Permalink
Pull request #5: Feature/MDAPI-72 swift migrate to graal sdk v1.1.21
Browse files Browse the repository at this point in the history
Merge in MDAPI/dxfeed-graal-swift-api from feature/MDAPI-72-swift-migrate-to-graal-sdk-v1.1.21 to main

Squashed commit of the following:

commit 3397d6e900d023abc4a49da0cfb081d6cd9e8e5b
Author: Aleksey Kosylo <[email protected]>
Date:   Tue Jul 23 13:40:35 2024 +0200

    [MDAPI-72] use millis instead of DXTimePeriod

commit 5772ecc0ac8c140e087e73ea2e4c540218f12625
Author: Aleksey Kosylo <[email protected]>
Date:   Wed Jul 17 13:19:29 2024 +0200

    fix typo

commit ece9526915650a058801f4bceaa5ef43b1531200
Author: Aleksey Kosylo <[email protected]>
Date:   Mon Jul 15 12:02:55 2024 +0200

    [MDAPI-72] add test for ProfileReader

commit 603e281753eceacfe444b89b1886d66436c624f1
Author: Aleksey Kosylo <[email protected]>
Date:   Mon Jul 15 10:04:29 2024 +0200

    [MDAPI-72] fix warnings

commit 3dc04fee033d014de205f265a33a2959a057caab
Author: Aleksey Kosylo <[email protected]>
Date:   Mon Jul 15 09:47:52 2024 +0200

    [MDAPI-72] add InstrumentProfileReader read with token

commit e914f5cd2804959f5349d12f93866dbfbb28e6a9
Author: Aleksey Kosylo <[email protected]>
Date:   Fri Jul 12 16:15:47 2024 +0200

    [MDAPI-72] add AuthToken

commit 348a7f2f37b8794b7593be90e6d785f9c940e5d2
Author: Aleksey Kosylo <[email protected]>
Date:   Fri Jul 12 15:04:24 2024 +0200

    [MDAPI-72] add aggregation period and batch limit

commit dca5fb0a20ad2bda8c764955224f611b6d4af9cc
Author: Aleksey Kosylo <[email protected]>
Date:   Fri Jul 12 13:26:33 2024 +0200

    [MDAPI-72] add new sources
  • Loading branch information
kosyloa committed Jul 23, 2024
1 parent 576ec1b commit 0370c74
Show file tree
Hide file tree
Showing 16 changed files with 524 additions and 13 deletions.
16 changes: 16 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@
649282E72AD54919008F0F04 /* ScheduleUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649282E62AD54919008F0F04 /* ScheduleUtils.swift */; };
649282E82AD54919008F0F04 /* ScheduleUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649282E62AD54919008F0F04 /* ScheduleUtils.swift */; };
649282ED2AD593F3008F0F04 /* OrderSourceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649282EC2AD593F3008F0F04 /* OrderSourceTest.swift */; };
64933D9B2C4161F8004E296C /* DXAuthToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64933D9A2C4161F8004E296C /* DXAuthToken.swift */; };
64933D9D2C416229004E296C /* NativeAuthToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64933D9C2C416229004E296C /* NativeAuthToken.swift */; };
64933D9F2C416AE3004E296C /* DXAuthTokenTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64933D9E2C416AE3004E296C /* DXAuthTokenTest.swift */; };
64933DA12C4517FA004E296C /* ipf.txt in Resources */ = {isa = PBXBuildFile; fileRef = 64933DA02C4517FA004E296C /* ipf.txt */; };
64963B6A2A8E545C001E40F7 /* IEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64963B692A8E545C001E40F7 /* IEventType.swift */; };
649706842AD82B070068FF88 /* Series.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649706832AD82B070068FF88 /* Series.swift */; };
649706862AD832860068FF88 /* Series+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649706852AD832860068FF88 /* Series+Ext.swift */; };
Expand Down Expand Up @@ -937,6 +941,10 @@
648E98A92AAF625800BFD219 /* IIndexedEvent+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IIndexedEvent+Ext.swift"; sourceTree = "<group>"; };
649282E62AD54919008F0F04 /* ScheduleUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleUtils.swift; sourceTree = "<group>"; };
649282EC2AD593F3008F0F04 /* OrderSourceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderSourceTest.swift; sourceTree = "<group>"; };
64933D9A2C4161F8004E296C /* DXAuthToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXAuthToken.swift; sourceTree = "<group>"; };
64933D9C2C416229004E296C /* NativeAuthToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeAuthToken.swift; sourceTree = "<group>"; };
64933D9E2C416AE3004E296C /* DXAuthTokenTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXAuthTokenTest.swift; sourceTree = "<group>"; };
64933DA02C4517FA004E296C /* ipf.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ipf.txt; sourceTree = "<group>"; };
64963B692A8E545C001E40F7 /* IEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IEventType.swift; sourceTree = "<group>"; };
649706832AD82B070068FF88 /* Series.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Series.swift; sourceTree = "<group>"; };
649706852AD832860068FF88 /* Series+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Series+Ext.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1536,6 +1544,7 @@
640885C92B1F7EE700E6CF88 /* QdsUtils.swift */,
643A329A2BD0137000F6F790 /* Optional+Ext.swift */,
6421FFE42BEA755700AC4657 /* Dictionary+Ext.swift */,
64933D9A2C4161F8004E296C /* DXAuthToken.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1685,6 +1694,7 @@
64A42F482B0B9683001C3ACC /* NativeTimeFormat.swift */,
64A42F4A2B0B96EF001C3ACC /* NativeTimePeriod.swift */,
640885CB2B1F7F0100E6CF88 /* NativeQdsUtils.swift */,
64933D9C2C416229004E296C /* NativeAuthToken.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1982,6 +1992,8 @@
64048A5A2BD7E5BF00902590 /* DXOnDemandServiceTest.swift */,
642C9A2C2BFE2FFE0074864A /* DXMarketDepthTest.swift */,
641E7A9C2C29A372009C8CE9 /* DXOptionChainTest.swift */,
64933D9E2C416AE3004E296C /* DXAuthTokenTest.swift */,
64933DA02C4517FA004E296C /* ipf.txt */,
);
path = DXFeedFrameworkTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -2639,6 +2651,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
64933DA12C4517FA004E296C /* ipf.txt in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2916,6 +2929,7 @@
64BDDB322AD7E5A600694210 /* SpreadOrderMapper.swift in Sources */,
64ACBCE32A289A0700032C53 /* TimeSeriesSubscriptionSymbol.swift in Sources */,
64F73B9F2B6788B00088EC37 /* Promise.swift in Sources */,
64933D9B2C4161F8004E296C /* DXAuthToken.swift in Sources */,
645A34952A937C7200709F29 /* BinaryInteger+Ext.swift in Sources */,
641C64B22B346A2E0023CFAD /* DXObservableSubscription.swift in Sources */,
64A42F502B0BA668001C3ACC /* DXTimeFormat.swift in Sources */,
Expand Down Expand Up @@ -2976,6 +2990,7 @@
64A42F3B2B07A7A3001C3ACC /* SymbolParser.swift in Sources */,
64ECD6872A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift in Sources */,
6406F2572AD9820700B58C42 /* NativePublisher.swift in Sources */,
64933D9D2C416229004E296C /* NativeAuthToken.swift in Sources */,
6486B9772AD04C5800D8D5FA /* TheoPriceMapper.swift in Sources */,
64278C702A602FA00074B5AA /* Candle+Ext.swift in Sources */,
64B4363C2AB86F3C0003919E /* DayFilter+Ext.swift in Sources */,
Expand Down Expand Up @@ -3160,6 +3175,7 @@
64EAA1A62B838ED3005087BC /* DXSnapshotProcessorTest.swift in Sources */,
649282ED2AD593F3008F0F04 /* OrderSourceTest.swift in Sources */,
64048A5B2BD7E5BF00902590 /* DXOnDemandServiceTest.swift in Sources */,
64933D9F2C416AE3004E296C /* DXAuthTokenTest.swift in Sources */,
6426C8932A531AB500236784 /* ThreadsTest.swift in Sources */,
64EAA1A22B7A38F8005087BC /* DXPromiseTest.swift in Sources */,
);
Expand Down
36 changes: 36 additions & 0 deletions DXFeedFramework/Api/DXFeedSubscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,39 @@ public extension DXFeedSubscription {
try native.detach(feed: feed.nativeFeed)
}
}

public extension DXFeedSubscription {
static let optimalBatchLimit = 0
static let maxBatchLimit = Long.max
/// Returns maximum number of events in the single notification of ``DXEventListener/receiveEvents(_:)``
///
/// Special cases are supported for constants ``optimalBatchLimit`` and ``maxBatchLimit``
func getEventsBatchLimit() -> Int32 {
return native.getEventsBatchLimit()
}

/// Sets maximum number of events in the single notification of ``DXEventListener/receiveEvents(_:)``
///
/// Special cases are supported for constants ``optimalBatchLimit`` and ``maxBatchLimit``
func setEventsBatchLimit(_ value: Int32) throws {
return try native.setEventsBatchLimit(value)
}
/// Returns the aggregation period for data for this subscription instance.
///
/// - Returns: value in millis.
func getAggregationPeriod() throws -> Long? {
return try nativeSubscription.getAggregationPeriod()
}

/// Sets the aggregation period for data.
///
/// This method sets a new aggregation period for data, which will only take effect on the next iteration of
/// data notification. For example, if the current aggregation period is 5 seconds and it is changed
/// to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which
/// the new aggregation period will take effect.
/// - Parameters:
/// - value: value in millis.
func setAggregationPeriod(_ value: Long) throws {
try nativeSubscription.setAggregationPeriod(value)
}
}
18 changes: 17 additions & 1 deletion DXFeedFramework/Events/Market/Extra/OrderSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ public class OrderSource: IndexedEventSource {
/// Pink sheets are listings for stocks that trade over-the-counter (OTC).
public static let pink = try? OrderSource("pink", pubOrder | pubOtcMarketsOrder)

/// NYSE Arca traded securities.
public static let ARCA = try? OrderSource("ARCA", pubOrder)

/// NYSE Arca traded securities.. Record for price level book.
public static let arca = try? OrderSource("arca", pubOrder)

/// Cboe European Derivatives.
public static let CEDX = try? OrderSource("CEDX", pubOrder)

/// Cboe European Derivatives. Record for price level book.
public static let cedx = try? OrderSource("cedx", pubOrder)

private static var publishableViews = [[OrderSource]](repeating: [OrderSource](), count: flagsSize)

/// Don't use it. Just for initialization all static variable.
Expand Down Expand Up @@ -219,7 +231,11 @@ public class OrderSource: IndexedEventSource {
OrderSource.MEMX,
OrderSource.memx,
OrderSource.OCEA,
OrderSource.pink]
OrderSource.pink,
OrderSource.ARCA,
OrderSource.arca,
OrderSource.CEDX,
OrderSource.cedx]

override init(_ identifier: Int, _ name: String) {
self.pubFlags = 0
Expand Down
22 changes: 22 additions & 0 deletions DXFeedFramework/Ipf/DXInstrumentProfileReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ public class DXInstrumentProfileReader {
return try native?.readFromFile(address: address, user: user, password: password)
}

/// Reads and returns instrument profiles from specified address with a specified token credentials.
///
/// This method recognizes data compression formats "zip" and "gzip" automatically.
/// In case of zip the first file entry will be read and parsed as a plain data stream.
/// In case of gzip compressed content will be read and processed.
/// In other cases data considered uncompressed and will be parsed as is.
///
/// Specified token take precedence over authentication information that is supplied to this method
/// as part of URL user info like "http://user:password@host:port/path/file.ipf"
///
///
/// This operation updates ``getLastModified()`` and ``wasComplete()``
///
/// - Parameters:
/// - address: URL of file to read from
/// - token: the token
/// - Returns: List of``InstrumentProfile``
/// - Throws: ``GraalException``. Rethrows exception from Java.
public func readFromFile(address: String, token: DXAuthToken) throws -> [InstrumentProfile]? {
return try native?.readFromFile(address: address, token: token.native)
}

/// Converts a specified string address specification into an URL that will be read by ``read(data:address:)`` using Data
public static func resolveSourceURL(address: String) -> String {
return NativeInstrumentProfileReader.resolveSourceURL(address: address)
Expand Down
13 changes: 13 additions & 0 deletions DXFeedFramework/Native/Ipf/NativeInstrumentProfileReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ class NativeInstrumentProfileReader {
return instruments
}

func readFromFile(address: String, token: NativeAuthToken) throws -> [InstrumentProfile] {
let thread = currentThread()
let result = try ErrorCheck.nativeCall(thread,
dxfg_InstrumentProfileReader_readFromFile3(
thread,
reader,
address.toCStringRef(),
token.native)).value()
let instruments = convertFromNativeList(result)
_ = try ErrorCheck.nativeCall(thread, dxfg_CList_InstrumentProfile_release(thread, result))
return instruments
}

private func convertFromNativeList(_ result:
UnsafeMutablePointer<dxfg_instrument_profile_list>) -> [InstrumentProfile] {
let count = result.pointee.size
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Native/Schedule/NativeSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class NativeSchedule {
scheduleDay.endTime = try ErrorCheck.nativeCall(thread, dxfg_Day_getEndTime(thread, day))
let sessions = try ErrorCheck.nativeCall(thread, dxfg_Day_getSessions(thread, day)).value()
defer {
_ = try? ErrorCheck.nativeCall(thread, dxfg_SessionList_release(thread, sessions))
_ = try? ErrorCheck.nativeCall(thread, dxfg_SessionList_wrapper_release(thread, sessions))
}

let count = sessions.pointee.size
Expand Down
40 changes: 40 additions & 0 deletions DXFeedFramework/Native/Subscription/NativeSubscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,43 @@ extension NativeSubscription {
feed.feed))
}
}

extension NativeSubscription {
func getEventsBatchLimit() -> Int32 {
let thread = currentThread()
if let value = try? ErrorCheck.nativeCall(thread,
dxfg_DXFeedSubscription_getEventsBatchLimit(thread,
subscription)) {
return value
}
return 0
}

func setEventsBatchLimit(_ value: Int32) throws {
let thread = currentThread()
try ErrorCheck.nativeCall(thread,
dxfg_DXFeedSubscription_setEventsBatchLimit(thread,
subscription,
value))
}

func getAggregationPeriod() throws -> Long? {
let thread = currentThread()
if let result = try ErrorCheck.nativeCall(thread,
dxfg_DXFeedSubscription_getAggregationPeriod(thread,
subscription)) {
return try NativeTimePeriod(native: result).getTime()
}
return nil
}

func setAggregationPeriod(_ value: Long) throws {
let thread = currentThread()
let value = try NativeTimePeriod(value: value)
try ErrorCheck.nativeCall(thread,
dxfg_DXFeedSubscription_setAggregationPeriod(thread,
subscription,
value.native))
}

}
105 changes: 105 additions & 0 deletions DXFeedFramework/Native/Utils/NativeAuthToken.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
//
// Copyright (C) 2024 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//

import Foundation
@_implementationOnly import graal_api

class NativeAuthToken: NativeBox<dxfg_auth_token_t> {
deinit {
let thread = currentThread()
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(native.pointee.handler)))
}

static func valueOf(_ value: String) throws -> NativeAuthToken {
let thread = currentThread()
let native = try ErrorCheck.nativeCall(thread, dxfg_AuthToken_valueOf(thread, value.toCStringRef())).value()
return NativeAuthToken(native: native)
}

static func createBasicToken(_ userPassword: String) throws -> NativeAuthToken {
let thread = currentThread()
let native = try ErrorCheck.nativeCall(thread,
dxfg_AuthToken_createBasicToken(thread,
userPassword.toCStringRef())).value()
return NativeAuthToken(native: native)
}

static func createBasicToken(_ user: String, _ password: String) throws -> NativeAuthToken {
let thread = currentThread()
let native = try ErrorCheck.nativeCall(thread,
dxfg_AuthToken_createBasicToken2(thread,
user.toCStringRef(),
password.toCStringRef())).value()
return NativeAuthToken(native: native)
}

static func createBasicToken(_ user: String, _ password: String) throws -> NativeAuthToken? {
let thread = currentThread()
if let native = try ErrorCheck.nativeCall(thread,
dxfg_AuthToken_createBasicTokenOrNull(thread,
user.toCStringRef(),
password.toCStringRef())) {
return NativeAuthToken(native: native)
}
return nil
}

static func createBearerToken(_ token: String) throws -> NativeAuthToken {
let thread = currentThread()
let native = try ErrorCheck.nativeCall(thread, dxfg_AuthToken_createBearerToken(thread,
token.toCStringRef())).value()
return NativeAuthToken(native: native)
}

static func createBearerToken(_ token: String) throws -> NativeAuthToken? {
let thread = currentThread()
if let native = try ErrorCheck.nativeCall(thread,
dxfg_AuthToken_createBearerTokenOrNull(thread,
token.toCStringRef())) {
return NativeAuthToken(native: native)
}
return nil
}

static func createCustomToken(_ scheme: String, _ value: String) throws -> NativeAuthToken {
let thread = currentThread()
let native = try ErrorCheck.nativeCall(thread, dxfg_AuthToken_createCustomToken(thread,
scheme.toCStringRef(),
value.toCStringRef())).value()
return NativeAuthToken(native: native)
}

lazy var user: String? = {
let thread = currentThread()
let nativeValue = try? ErrorCheck.nativeCall(thread, dxfg_AuthToken_getUser(thread, native))
return String(nullable: nativeValue)
}()

lazy var password: String? = {
let thread = currentThread()
let nativeValue = try? ErrorCheck.nativeCall(thread, dxfg_AuthToken_getPassword(thread, native))
return String(nullable: nativeValue)
}()

lazy var httpAuthorization: String? = {
let thread = currentThread()
let nativeValue = try? ErrorCheck.nativeCall(thread, dxfg_AuthToken_getHttpAuthorization(thread, native))
return String(nullable: nativeValue)
}()

lazy var scheme: String? = {
let thread = currentThread()
let nativeValue = try? ErrorCheck.nativeCall(thread, dxfg_AuthToken_getScheme(thread, native))
return String(nullable: nativeValue)
}()

lazy var value: String? = {
let thread = currentThread()
let nativeValue = try? ErrorCheck.nativeCall(thread, dxfg_AuthToken_getValue(thread, native))
return String(nullable: nativeValue)
}()
}
Loading

0 comments on commit 0370c74

Please sign in to comment.