Skip to content

Commit

Permalink
add integration test for order
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 12, 2023
1 parent ded428c commit f2f071e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 23 deletions.
1 change: 1 addition & 0 deletions DXFeedFramework/Events/EventCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum EventCode: CaseIterable {
case timeAndSale
/// **Doesn't need to be implemented. Abstract class**
case orderBase
/// See ``AnalyticOrder``
case order
/// See ``AnalyticOrder``
case analyticOrder
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Events/Market/Extra/OrderBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ extension OrderBase {
"""
\(eventSymbol), \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
source=\(eventSource), \
source=\(eventSource.name), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
index=0x\(String(format: "%02X", index)), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
Expand Down
50 changes: 49 additions & 1 deletion DXFeedFramework/Events/Market/Extra/OrderSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class OrderSource: IndexedEventSource {
///
/// It is a synthetic source.
/// The subscription on composite ``Quote`` event is observed when this source is subscribed to.
public static let compsoiteBid = try? OrderSource(1, "DEFAULT", pubOrder | pubAnalyticOrder | pubSpreadOrder | fullOrderBook)
public static let compsoiteBid = try? OrderSource(1, "COMPOSITE_BID", pubOrder | pubAnalyticOrder | pubSpreadOrder | fullOrderBook)
/// Ask side of a composite ``Quote``.
/// It is a synthetic source.
/// The subscription on composite ``Quote`` event is observed when this source is subscribed to.
Expand Down Expand Up @@ -160,6 +160,46 @@ public class OrderSource: IndexedEventSource {
/// Members Exchange. Record for price level book.
public static let memx = try? OrderSource("memx", pubOrder)

/// Don't use it. Just for initialization all static variable.
/// static let - is always lazy initialized
fileprivate static let allValues = [OrderSource.defaultOrderSource,
OrderSource.compsoiteBid,
OrderSource.compsoiteAsk,
OrderSource.regionalBid,
OrderSource.regionalAsk,
OrderSource.agregateBid,
OrderSource.agregateAsk,
OrderSource.NTV,
OrderSource.ntv,
OrderSource.NFX,
OrderSource.ESPD,
OrderSource.XNFI,
OrderSource.ICE,
OrderSource.ISE,
OrderSource.DEA,
OrderSource.DEX,
OrderSource.BYX,
OrderSource.BZX,
OrderSource.BATE,
OrderSource.CHIX,
OrderSource.CEUX,
OrderSource.BXTR,
OrderSource.IST,
OrderSource.BI20,
OrderSource.ABE,
OrderSource.FAIR,
OrderSource.GLBX,
OrderSource.glbx,
OrderSource.ERIS,
OrderSource.XEUR,
OrderSource.xeur,
OrderSource.CFE,
OrderSource.C2OX,
OrderSource.SMFE,
OrderSource.smfe,
OrderSource.iex,
OrderSource.MEMX,
OrderSource.memx]

override init(_ identifier: Int, _ name: String) {
self.pubFlags = 0
Expand Down Expand Up @@ -306,3 +346,11 @@ public class OrderSource: IndexedEventSource {
}

}

extension OrderSource {
/// Don't use it. Just for initialization all static variable.
/// static let - is always lazy initialized
internal static func initAllValues() {
_ = OrderSource.allValues
}
}
2 changes: 2 additions & 0 deletions DXFeedFramework/Native/Graal/Isolate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Isolate {
let errorMessage = "!!!Isolate init failed: Unexpected error \(error)"
fatalError(errorMessage)
}

OrderSource.initAllValues()
}

// only for testing
Expand Down
6 changes: 5 additions & 1 deletion DXFeedFramework/Utils/ConcurrentDict.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class ConcurrentDict<Key: Hashable, Value>: CustomStringConvertible {

public func tryInsert(key: Key, value: Value) -> Bool {
return accessQueue.sync {
return set.updateValue(value, forKey: key) == nil
if set[key] == nil {
set[key] = value
return true
}
return false
}
}

Expand Down
23 changes: 3 additions & 20 deletions DXFeedFrameworkTests/OrderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ final class OrderTest: XCTestCase {
try receiveOrder(code: .order)
}

func testAnalyticOrder() throws {
try receiveOrder(code: .analyticOrder)
}

func testSpreadOrder() throws {
try receiveOrder(code: .spreadOrder)
}

private func receiveOrder(code: EventCode) throws {
let endpoint = try DXEndpoint.builder().withRole(.feed).withProperty("test", "value").build()
try endpoint.connect("demo.dxfeed.com:7300")
Expand All @@ -38,26 +30,17 @@ final class OrderTest: XCTestCase {
receivedEventExp.assertForOverFulfill = false
let listener = AnonymousClass { anonymCl in
anonymCl.callback = { events in
events.forEach { event in
if event.type == .order {
print(event.order.toString())
}

}
if events.count > 0 {
let event = events.first
if FeedTest.checkType(code, event) {
if event?.type == .order {
print(event?.order.toString())
}
// receivedEventExp.fulfill()
if FeedTest.checkType(code, event) {
receivedEventExp.fulfill()
}
}
}
return anonymCl
}
try subscription?.add(observer: listener)
try subscription?.addSymbols(["IBM"])
wait(for: [receivedEventExp], timeout: 10)
wait(for: [receivedEventExp], timeout: 2)
}
}

0 comments on commit f2f071e

Please sign in to comment.