Skip to content

Commit

Permalink
feat: Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Feb 15, 2024
1 parent ef93c81 commit 0858a4a
Show file tree
Hide file tree
Showing 10 changed files with 943 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Fetch dep
run: gradle fetchDependencies
Expand All @@ -30,7 +30,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Fetch dep
run: gradle fetchDependencies
Expand Down
36 changes: 36 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,15 @@
64E342502AAB083700457994 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6469F8D22A3B401700846831 /* Colors.swift */; };
64E342522AAB29CF00457994 /* InstrumentProfileType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64E342512AAB29CF00457994 /* InstrumentProfileType.swift */; };
64E3637B2AD83459002E2B0D /* SeriesMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64E3637A2AD83459002E2B0D /* SeriesMapper.swift */; };
64EAA1A22B7A38F8005087BC /* DXPromiseTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64EAA1A12B7A38F8005087BC /* DXPromiseTest.swift */; };
64EAA1A42B7B4DA1005087BC /* IndexedEventSource+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64EAA1A32B7B4DA1005087BC /* IndexedEventSource+Ext.swift */; };
64ECD67F2A9CF4CB00B36935 /* IPFTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD67E2A9CF4CB00B36935 /* IPFTests.swift */; };
64ECD6822A9DDC2800B36935 /* DXInstrumentProfileReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6812A9DDC2800B36935 /* DXInstrumentProfileReader.swift */; };
64ECD6852A9DDF6200B36935 /* DXInstrumentProfileCollector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6842A9DDF6200B36935 /* DXInstrumentProfileCollector.swift */; };
64ECD6872A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6862A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift */; };
64F73B9F2B6788B00088EC37 /* Promise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64F73B9E2B6788B00088EC37 /* Promise.swift */; };
64F73BA42B67B28B0088EC37 /* NativePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64F73BA32B67B28B0088EC37 /* NativePromise.swift */; };
64F73BA62B67CD5B0088EC37 /* GraalException+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64F73BA52B67CD5B0088EC37 /* GraalException+Ext.swift */; };
64FCAF902A572D4600971F4E /* libDxFeedGraalNativeSdk.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 64125E352A1F689A00FB32BA /* libDxFeedGraalNativeSdk.dylib */; platformFilters = (macos, ); settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
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, ); }; };
Expand Down Expand Up @@ -850,10 +855,15 @@
64DA26BF2AA224EB005B1757 /* NativeIPFConnectionListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeIPFConnectionListener.swift; sourceTree = "<group>"; };
64E342512AAB29CF00457994 /* InstrumentProfileType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfileType.swift; sourceTree = "<group>"; };
64E3637A2AD83459002E2B0D /* SeriesMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeriesMapper.swift; sourceTree = "<group>"; };
64EAA1A12B7A38F8005087BC /* DXPromiseTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXPromiseTest.swift; sourceTree = "<group>"; };
64EAA1A32B7B4DA1005087BC /* IndexedEventSource+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IndexedEventSource+Ext.swift"; sourceTree = "<group>"; };
64ECD67E2A9CF4CB00B36935 /* IPFTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPFTests.swift; sourceTree = "<group>"; };
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>"; };
64F73B9E2B6788B00088EC37 /* Promise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Promise.swift; sourceTree = "<group>"; };
64F73BA32B67B28B0088EC37 /* NativePromise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativePromise.swift; sourceTree = "<group>"; };
64F73BA52B67CD5B0088EC37 /* GraalException+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "GraalException+Ext.swift"; sourceTree = "<group>"; };
64F9C6C12B4BFD8F003ED014 /* DXFeedconnect.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = DXFeedconnect.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
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>"; };
Expand Down Expand Up @@ -1101,6 +1111,7 @@
64ABC1022AD9294C00904D78 /* OptionSaleMapper.swift */,
64AF04422AE6AA230091F6F1 /* TradeETH+Ext.swift */,
64AF04402AE6A9E90091F6F1 /* TradeETHMapper.swift */,
64EAA1A32B7B4DA1005087BC /* IndexedEventSource+Ext.swift */,
);
path = Markets;
sourceTree = "<group>";
Expand Down Expand Up @@ -1490,6 +1501,22 @@
path = Live;
sourceTree = "<group>";
};
64F73B9D2B67863B0088EC37 /* Promise */ = {
isa = PBXGroup;
children = (
64F73B9E2B6788B00088EC37 /* Promise.swift */,
);
path = Promise;
sourceTree = "<group>";
};
64F73BA22B67B2750088EC37 /* Promise */ = {
isa = PBXGroup;
children = (
64F73BA32B67B28B0088EC37 /* NativePromise.swift */,
);
path = Promise;
sourceTree = "<group>";
};
803BAC0329BFA50700FFAB1C = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1529,6 +1556,7 @@
8088D77A29C5D8AD00F240CB /* Native */,
64656F552A1B6A07006A0B19 /* Utils */,
64ECD6802A9DD80000B36935 /* Ipf */,
64F73B9D2B67863B0088EC37 /* Promise */,
64C771FD2A9504D7009868C2 /* Extra */,
6498E6B02AB1D40C0093A065 /* Schedule */,
8088D77029C3A25D00F240CB /* SystemProperty.swift */,
Expand Down Expand Up @@ -1564,6 +1592,7 @@
641C64B32B347C430023CFAD /* DXObservableSubscriptionTest.swift */,
6423E4682B457000006B208D /* DXTimeSeriesSubscriptionTest.swift */,
646064E92B4D8973009201E2 /* DXLastEventTest.swift */,
64EAA1A12B7A38F8005087BC /* DXPromiseTest.swift */,
);
path = DXFeedFrameworkTests;
sourceTree = "<group>";
Expand All @@ -1590,6 +1619,7 @@
64104FCA2A2629C400D1FC41 /* Subscription */,
64437A902A9DF1C4005929B2 /* Ipf */,
6498E6B32AB1D43A0093A065 /* Schedule */,
64F73BA22B67B2750088EC37 /* Promise */,
64ACBCE42A28AEE200032C53 /* SymbolMappers */,
64A42F432B0B9320001C3ACC /* Utils */,
);
Expand All @@ -1604,6 +1634,7 @@
8088D77C29C8DAF800F240CB /* GraalErrorCode.swift */,
64656F612A1B9FF7006A0B19 /* EnumException.swift */,
640C3FCB2A616B6200555161 /* ArgumentException.swift */,
64F73BA52B67CD5B0088EC37 /* GraalException+Ext.swift */,
);
path = ErrorHandling;
sourceTree = "<group>";
Expand Down Expand Up @@ -2291,6 +2322,7 @@
files = (
64BDDB322AD7E5A600694210 /* SpreadOrderMapper.swift in Sources */,
64ACBCE32A289A0700032C53 /* TimeSeriesSubscriptionSymbol.swift in Sources */,
64F73B9F2B6788B00088EC37 /* Promise.swift in Sources */,
645A34952A937C7200709F29 /* BinaryInteger+Ext.swift in Sources */,
641C64B22B346A2E0023CFAD /* DXObservableSubscription.swift in Sources */,
64A42F502B0BA668001C3ACC /* DXTimeFormat.swift in Sources */,
Expand Down Expand Up @@ -2337,6 +2369,7 @@
6486B9732AD045C800D8D5FA /* TheoPrice.swift in Sources */,
64ACBCDF2A2897EA00032C53 /* String+Symbol.swift in Sources */,
64B4363A2AB86D1A0003919E /* DayFilter.swift in Sources */,
64EAA1A42B7B4DA1005087BC /* IndexedEventSource+Ext.swift in Sources */,
64A42F3B2B07A7A3001C3ACC /* SymbolParser.swift in Sources */,
64ECD6872A9DDFBE00B36935 /* DXInstrumentProfileConnection.swift in Sources */,
6406F2572AD9820700B58C42 /* NativePublisher.swift in Sources */,
Expand Down Expand Up @@ -2367,6 +2400,7 @@
6498E6BD2AB1E0510093A065 /* ScheduleSession.swift in Sources */,
64BDDB262AD6F6B500694210 /* IcebergType.swift in Sources */,
8088D76529C0FBCE00F240CB /* ThreadManager.swift in Sources */,
64F73BA62B67CD5B0088EC37 /* GraalException+Ext.swift in Sources */,
64DA26BE2AA20EDB005B1757 /* DXInstrumentProfileConnectionListener.swift in Sources */,
64656F732A1D0A84006A0B19 /* EndpointListener.swift in Sources */,
64BDDB282AD7D8D300694210 /* Order+Ext.swift in Sources */,
Expand Down Expand Up @@ -2468,6 +2502,7 @@
64BDDB1E2AD6CC6A00694210 /* Order.swift in Sources */,
64437A8F2A9DEE6F005929B2 /* InstrumentProfile.swift in Sources */,
64C771FA2A94D692009868C2 /* ShortSaleRestriction.swift in Sources */,
64F73BA42B67B28B0088EC37 /* NativePromise.swift in Sources */,
64656F5E2A1B97F2006A0B19 /* NativeFeed.swift in Sources */,
6486B97D2AD057F200D8D5FA /* OrderSource.swift in Sources */,
64656F6F2A1CFC12006A0B19 /* WeakBox.swift in Sources */,
Expand Down Expand Up @@ -2502,6 +2537,7 @@
6498E6B72AB1DACE0093A065 /* ScheduleTest.swift in Sources */,
649282ED2AD593F3008F0F04 /* OrderSourceTest.swift in Sources */,
6426C8932A531AB500236784 /* ThreadsTest.swift in Sources */,
64EAA1A22B7A38F8005087BC /* DXPromiseTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Connect demo.dxfeed.com:7300 TimeAndSale &quot;ipf[https://demo:[email protected]/ipf?TYPE=STOCK&amp;compression=zip],APPL&quot; -p monitoring.stat=1s"
isEnabled = "NO">
argument = "Connect demo.dxfeed.com:7300 TRADE ETH/USD:GDAX"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "qds connect demo.dxfeed.com:7300 Quote AAPL,IBM"
Expand All @@ -89,7 +89,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "Dump tapeK2.tape[speed=max] all all -t ios_tapeK2.tape -q"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "DuMp tapeK2.tape[speed=max] -t ios_tapeK2.tape -q"
Expand Down
28 changes: 28 additions & 0 deletions DXFeedFramework/Api/DXFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,31 @@ public extension DXFeed {
return try native.getLastEvents(types: types)
}
}

public extension DXFeed {
func getLastEventPromise(type: IEventType.Type, symbol: Symbol) throws -> Promise? {
let nativePromise = try native.getLastEventPromise(type: type, symbol: symbol)
return Promise(native: nativePromise)
}

func getLastEventPromises(type: IEventType.Type, symbols: [Symbol]) throws -> [Promise]? {
let nativePromises = try native.getLastEventPromises(type: type, symbols: symbols)
return nativePromises?.map({ promise in
Promise(native: promise)
})
}

func getIndexedEventsPromise(type: IEventType.Type, symbol: Symbol, source: IndexedEventSource) throws -> Promise? {
let nativePromise = try native.getIndexedEventsPromise(type: type, symbol: symbol, source: source)
return Promise(native: nativePromise)
}

func getTimeSeriesPromise(type: IEventType.Type, symbol: Symbol, fromTime: Long, toTime: Long) throws -> Promise? {
let nativePromise = try native.getTimeSeriesPromise(type: type,
symbol: symbol,
fromTime: fromTime,
toTime: toTime)
return Promise(native: nativePromise)

}
}
37 changes: 37 additions & 0 deletions DXFeedFramework/Native/ErrorHandling/GraalException+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
//
// Copyright (C) 2024 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public 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

internal extension GraalException {
static func createNew(native: UnsafeMutablePointer<dxfg_exception_t>) -> GraalException {
let pointee = native.pointee
let message = String(pointee: pointee.message, default: "Graall Exception")
let className = String(pointee: pointee.class_name, default: "")
let stackTrace = String(pointee: pointee.print_stack_trace, default: "")
let gException = GraalException.fail(message: message,
className: className,
stack: stackTrace)
return gException
}

func toNative() -> UnsafeMutablePointer<dxfg_exception_t>? {
switch self {
case .fail(message: let message, className: let className, stack: let stack):
let exception = UnsafeMutablePointer<dxfg_exception_t>.allocate(capacity: 1)
var pointee = exception.pointee
pointee.class_name = className.toCStringRef()
pointee.message = message.toCStringRef()
pointee.print_stack_trace = stack.toCStringRef()
exception.pointee = pointee
return exception
default:
return nil
}
}
}
24 changes: 24 additions & 0 deletions DXFeedFramework/Native/Events/Markets/IndexedEventSource+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
//
// Copyright (C) 2024 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public 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

extension IndexedEventSource {
func toNative() -> UnsafeMutablePointer<dxfg_indexed_event_source_t>? {
let nativeSource = UnsafeMutablePointer<dxfg_indexed_event_source_t>.allocate(capacity: 1)
nativeSource.pointee.id = Int32(identifier)
nativeSource.pointee.name = name.toCStringRef()
switch self {
case _ as OrderSource:
nativeSource.pointee.type = ORDER_SOURCE
default:
nativeSource.pointee.type = INDEXED_EVENT_SOURCE
}
return nativeSource
}
}
73 changes: 73 additions & 0 deletions DXFeedFramework/Native/Feed/NativeFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,77 @@ class NativeFeed {
}
return results
}

func getLastEventPromise(type: IEventType.Type, symbol: Symbol) throws -> NativePromise {
let thread = currentThread()
let converted = SymbolMapper.newNative(symbol)
let native = try ErrorCheck.nativeCall(thread,
dxfg_DXFeed_getLastEventPromise(thread,
feed,
type.type.nativeCode(),
converted))
return NativePromise(promise: &native.pointee.handler)

}

func getLastEventPromises(type: IEventType.Type, symbols: [Symbol]) throws -> [NativePromise]? {
let nativeSymbols = symbols.compactMap { SymbolMapper.newNative($0) }
let elements = ListNative(pointers: nativeSymbols)
let listPointer = elements.newList()
defer {
listPointer.deinitialize(count: 1)
listPointer.deallocate()
nativeSymbols.forEach { SymbolMapper.clearNative(symbol: $0) }
}
let thread = currentThread()
let native = try ErrorCheck.nativeCall(thread,
dxfg_DXFeed_getLastEventsPromises(thread,
feed,
type.type.nativeCode(),
listPointer))
var result = [NativePromise]()
for index in 0..<Int(native.pointee.list.size) {
let promise = native.pointee.list.elements[index]
promise?.withMemoryRebound(to: dxfg_promise_t.self, capacity: 1, { pointer in
result.append(NativePromise(promise: pointer))
})
}
return result
}

func getIndexedEventsPromise(type: IEventType.Type,
symbol: Symbol,
source: IndexedEventSource) throws -> NativePromise {
let thread = currentThread()
let converted = SymbolMapper.newNative(symbol)
let nativeSource = source.toNative()
defer {
nativeSource?.deinitialize(count: 1)
nativeSource?.deallocate()
}
let native = try ErrorCheck.nativeCall(thread,
dxfg_DXFeed_getIndexedEventsPromise(thread,
feed,
type.type.nativeCode(),
converted,
nativeSource))

return NativePromise(promise: &native.pointee.base)
}

func getTimeSeriesPromise(type: IEventType.Type,
symbol: Symbol,
fromTime: Long,
toTime: Long) throws -> NativePromise {
let thread = currentThread()
let converted = SymbolMapper.newNative(symbol)
let native = try ErrorCheck.nativeCall(thread,
dxfg_DXFeed_getTimeSeriesPromise(thread,
feed,
type.type.nativeCode(),
converted,
fromTime,
toTime))
return NativePromise(promise: &native.pointee.base)
}
}
Loading

0 comments on commit 0858a4a

Please sign in to comment.