Skip to content

Commit

Permalink
add test for normalize symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Apr 12, 2024
1 parent d620b7c commit b738303
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions DXFeedFramework/Events/Market/Candles/CandleSymbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public class CandleSymbol: CustomStringConvertible {
public static func valueOf(_ symbol: String, _ properties: [ICandleSymbolProperty]) -> CandleSymbol {
return CandleSymbol(symbol, properties)
}

/// Converts the given string symbol into the candle symbol object with the specified attribute set.
///
/// - Parameters:
/// - symbol:The string symbol.
/// - attributes: The attributes variadic.
/// - Throws: ArgumentException/invalidOperationException(_:)
public static func valueOf(_ symbol: String, _ properties: ICandleSymbolProperty...) -> CandleSymbol {
return CandleSymbol(symbol, properties)
}
}

extension CandleSymbol: Equatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ public class MarketEventSymbols {
symbol[0..<index] +
"\(key)\(Separtors.value.rawValue)\(value)" +
symbol[jindex-1..<symbol.length]
added = true
index += key.length + value.length + 2
}
} else {
if current > key && !added {
Expand All @@ -306,6 +308,8 @@ public class MarketEventSymbols {
index = jindex
}
}
} else {
print("NULLL")
}
}
return added ? symbol : (symbol[0..<index-1] +
Expand Down
20 changes: 20 additions & 0 deletions DXFeedFrameworkTests/CandleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,26 @@ final class CandleTests: XCTestCase {
XCTAssert(testSymbol?.period?.type == .day && testSymbol?.period?.value == 12)
XCTAssert(testSymbol == CandleSymbol.valueOf("TEST123", [CandlePeriod.valueOf(value: 12, type: .day)]))
XCTAssert(CandleSymbol.valueOf("TEST1", [CandlePrice.ask]).toString() == "TEST1{price=ask}")


}

func testNormalize() {
XCTAssertEqual("IBM&E", CandleSymbol.valueOf("IBM", CandleExchange.valueOf("E")).toString())
XCTAssertEqual("IBM", CandleSymbol.valueOf("IBM", CandleExchange.composite).toString())

XCTAssertEqual("IBM{=d}", CandleSymbol.valueOf("IBM", CandlePeriod.day).toString())
XCTAssertEqual("IBM", CandleSymbol.valueOf("IBM", CandlePeriod.tick).toString())

XCTAssertEqual("IBM{price=ask}", CandleSymbol.valueOf("IBM", [CandlePrice.ask]).toString())
XCTAssertEqual("IBM", CandleSymbol.valueOf("IBM", [CandlePrice.last]).toString())

XCTAssertEqual("EUR/USD{=2h,price=bid,source=bank}",
CandleSymbol.valueOf("EUR/USD{source=bank}",
[CandlePrice.bid, CandlePeriod.valueOf(value: 2, type: CandleType.hour)]).toString())
XCTAssertEqual("IBM{=15m,aa=zz,price=bid}",
CandleSymbol.valueOf("IBM{aa=zz,price=b}",
[CandlePeriod.valueOf(value: 15, type: CandleType.minute)]).toString())
}
}

Expand Down

0 comments on commit b738303

Please sign in to comment.