Skip to content

Commit

Permalink
add tests for marketdepth
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed May 24, 2024
1 parent 35c56b9 commit 9b01b16
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 11 deletions.
4 changes: 4 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
642C9A292BFDEAF20074864A /* CandlePickerType+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642C9A282BFDEAF20074864A /* CandlePickerType+Ext.swift */; };
642C9A2A2BFDEAF20074864A /* CandlePickerType+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642C9A282BFDEAF20074864A /* CandlePickerType+Ext.swift */; };
642C9A2B2BFDEAF20074864A /* CandlePickerType+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642C9A282BFDEAF20074864A /* CandlePickerType+Ext.swift */; };
642C9A2D2BFE2FFE0074864A /* DXMarketDepthTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642C9A2C2BFE2FFE0074864A /* DXMarketDepthTest.swift */; };
642DC9282AAA21C000974F5C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642DC9272AAA21C000974F5C /* AppDelegate.swift */; };
642DC92A2AAA21C000974F5C /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642DC9292AAA21C000974F5C /* SceneDelegate.swift */; };
642DC92C2AAA21C000974F5C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642DC92B2AAA21C000974F5C /* ViewController.swift */; };
Expand Down Expand Up @@ -727,6 +728,7 @@
642C9A202BFDE71C0074864A /* Array+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Ext.swift"; sourceTree = "<group>"; };
642C9A242BFDE9F00074864A /* CandleChartModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleChartModel.swift; sourceTree = "<group>"; };
642C9A282BFDEAF20074864A /* CandlePickerType+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CandlePickerType+Ext.swift"; sourceTree = "<group>"; };
642C9A2C2BFE2FFE0074864A /* DXMarketDepthTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXMarketDepthTest.swift; sourceTree = "<group>"; };
642DC9252AAA21C000974F5C /* DXIpfTableApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DXIpfTableApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
642DC9272AAA21C000974F5C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
642DC9292AAA21C000974F5C /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1829,6 +1831,7 @@
64820AAE2BB2E26100BDFD0B /* DXOtcMarketOrderTest.swift */,
644B95E62BC542F600E95CB7 /* DXAttachTest.swift */,
64048A5A2BD7E5BF00902590 /* DXOnDemandServiceTest.swift */,
642C9A2C2BFE2FFE0074864A /* DXMarketDepthTest.swift */,
);
path = DXFeedFrameworkTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -2891,6 +2894,7 @@
648C72492B19CA5A00E2FEF3 /* DXExceptionTest.swift in Sources */,
649813C42ADD5CB2003CE3B3 /* TestEndpoointStateListener.swift in Sources */,
641C64B42B347C430023CFAD /* DXObservableSubscriptionTest.swift in Sources */,
642C9A2D2BFE2FFE0074864A /* DXMarketDepthTest.swift in Sources */,
64ACBCEC2A29FE2300032C53 /* XCTestCase+Utils.swift in Sources */,
6433B1322BCFC01F004EFED7 /* DXLastEventsSubscribedTest.swift in Sources */,
6423E4692B457000006B208D /* DXTimeSeriesSubscriptionTest.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Extra/MarketDepthListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
public class OrderBook {
public let buyOrders: [Order]
public let sellOrders: [Order]

public let name = "ASDas"
init(buyOrders: [Order], sellOrders: [Order]) {
self.buyOrders = buyOrders
self.sellOrders = sellOrders
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Native/Feed/NativePublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NativePublisher {
let thread = currentThread()
_ = try ErrorCheck.nativeCall(thread, dxfg_DXPublisher_publishEvents(thread,
publisher,
listPointer))
listPointer))
}
}

Expand Down
1 change: 1 addition & 0 deletions DXFeedFrameworkTests/DXExceptPublisherTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"DXConnectionStateTests",
"DXConnectionTest",
"DXExceptionTest",
"DXMarketDepthTest",
"DXObservableSubscriptionTest",
"DXSnapshotProcessorTest",
"EndpointTest\/testGetInstance()",
Expand Down
367 changes: 367 additions & 0 deletions DXFeedFrameworkTests/DXMarketDepthTest.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion DXFeedFrameworkTests/DXOnDemandServiceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import XCTest
import DXFeedFramework
@testable import DXFeedFramework

final class DXOnDemandServiceTest: XCTestCase {
func testCreateService() throws {
Expand Down
25 changes: 17 additions & 8 deletions DXFeedFrameworkTests/PublisherTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ final class PublisherTest: XCTestCase {
.build()
try endpoint?.connect(":7400")

let testQuote = Quote("AAPL")
testQuote.bidSize = 100
testQuote.askPrice = 666
try? testQuote.setSequence(10)
let order = Order("AAPL")
order.index = 0

order.orderSide = .buy
order.eventSource = OrderSource.ntv!
order.eventFlags = 0
order.size = 100
order.price = 666
let feedEndpoint = try DXEndpoint
.builder()
.withRole(.feed)
Expand All @@ -49,28 +53,33 @@ final class PublisherTest: XCTestCase {
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 0.3) {
print("\(pthread_mach_thread_np(pthread_self()))")
print(Thread.current.threadName)
try? publisher?.publish(events: [testQuote])
try? publisher?.publish(events: [order])
}
}
}
return listener
}

feedEndpoint.add(listener: stateListener!)
let subscription = try feedEndpoint.getFeed()?.createSubscription(Quote.self)
let subscription = try feedEndpoint.getFeed()?.createSubscription(Order.self)
try feedEndpoint.connect("localhost:7400")
let receivedEventExp = expectation(description: "Received events \(EventCode.quote)")
receivedEventExp.assertForOverFulfill = false

let listener = AnonymousClass { anonymCl in
anonymCl.callback = { _ in
anonymCl.callback = { events in
events.forEach { event in
print(event.toString())
}
receivedEventExp.fulfill()
}
return anonymCl
}

try subscription?.add(listener: listener)
try subscription?.addSymbols(["AAPL"])
let symbol = IndexedEventSubscriptionSymbol(symbol: "AAPL", source: OrderSource.ntv!)

try subscription?.addSymbols([symbol])
wait(for: [connectedExpectation], timeout: 1)
wait(for: [receivedEventExp], timeout: 20)
} catch {
Expand Down
6 changes: 6 additions & 0 deletions DXFeedFrameworkTests/XCTestCase+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ extension XCTestCase {
_ = XCTWaiter.wait(for: [expectation(description: "\(seconds) seconds waiting")],
timeout: TimeInterval(seconds))
}

func wait(millis: Float) {
let seconds = millis / 1000
_ = XCTWaiter.wait(for: [expectation(description: "\(millis) millis waiting")],
timeout: TimeInterval(seconds))
}
}
2 changes: 2 additions & 0 deletions Samples/QuoteTableApp/MarketDepthViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ extension MarketDepthViewController: MarketDepthListener {
func modelChanged(changes: DXFeedFramework.OrderBook) {
var maxValue: Double = 0
changes.buyOrders.forEach { order in
print(order.eventSource.name)
maxValue = max(maxValue, order.size)
}
changes.sellOrders.forEach { order in
print(order.eventSource.name)
maxValue = max(maxValue, order.size)
}

Expand Down

0 comments on commit 9b01b16

Please sign in to comment.