Skip to content

Commit

Permalink
change format for hex values in toString
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 13, 2023
1 parent 065e137 commit add0b33
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 29 deletions.
3 changes: 2 additions & 1 deletion DXFeedFramework/Events/Market/Candles/Candle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ extension Candle {
return """
\(eventSymbol), \
eventTime=" + \(TimeUtil.toLocalDateString(millis: eventTime)), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
eventFlags=\(eventFlags.toHexString()), \
index=\(index.toHexString()), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
sequence=\(getSequence()), \
count=\(count), \
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Events/Market/Extra/OrderBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ extension OrderBase {
\(eventSymbol), \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
source=\(eventSource.name), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
index=0x\(String(format: "%02X", index)), \
eventFlags=\(eventFlags.toHexString()), \
index=\(index.toHexString()), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
sequence=\(getSequence()), \
timeNanoPart=\(timeNanoPart), \
Expand Down
3 changes: 2 additions & 1 deletion DXFeedFramework/Events/Market/Greeks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ extension Greeks {
return """
Greeks{\(eventSymbol), \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
eventFlags=\(eventFlags.toHexString()), \
index=\(index.toHexString()), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
sequence=\(self.getSequence()), \
price=\(price), \
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Events/Market/OptionSale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ extension OptionSale {
return """
OptionSale{\(eventSymbol), \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
index=0x\(String(format: "%02X", index)), \
eventFlags=\(eventFlags.toHexString()), \
index=\(index.toHexString()), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
timeNanoPart=\(timeNanoPart), \
sequence=\(getSequence()), \
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Events/Market/Series.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ extension Series {
"""
Series{\(eventSymbol), \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
index=0x\(String(format: "%02X", index)), \
eventFlags=\(eventFlags.toHexString()), \
index=\(index.toHexString()), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
sequence=\(self.getSequence()), \
expiration=\(DayUtil.getYearMonthDayByDayId(Int(expiration))), \
Expand Down
3 changes: 2 additions & 1 deletion DXFeedFramework/Events/Market/TheoPrice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ extension TheoPrice {
return """
TheoPrice{\(eventSymbol) \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
eventFlags=\(eventFlags.toHexString()), \
index=\(index.toHexString()), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
sequence=\(self.getSequence()), \
price=\(price) \
Expand Down
3 changes: 2 additions & 1 deletion DXFeedFramework/Events/Market/TimeAndSale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ extension TimeAndSale {
return """
TimeAndSale{\(eventSymbol), \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
eventFlags=\(eventFlags.toHexString()), \
index=\(index.toHexString()), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
timeNanoPart=\(timeNanoPart), \
sequence=\(getSequence()), \
Expand Down
3 changes: 2 additions & 1 deletion DXFeedFramework/Events/Market/Underlying.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ extension Underlying {
return """
Underlying{"\(eventSymbol) \
eventTime=\(TimeUtil.toLocalDateString(millis: eventTime)), \
eventFlags=0x\(String(format: "%02X", eventFlags)), \
eventFlags=\(eventFlags.toHexString()), \
index=\(index.toHexString()), \
time=\(TimeUtil.toLocalDateString(millis: time)), \
sequence=\(self.getSequence()), \
volatility=\(volatility), \
Expand Down
36 changes: 20 additions & 16 deletions DXFeedFramework/Utils/BinaryInteger+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@
import Foundation

extension BinaryInteger {
func roundedTowardZero(toMultipleOf multiplier: Self) -> Self {
return self - (self % multiplier)
}
func roundedTowardZero(toMultipleOf multiplier: Self) -> Self {
return self - (self % multiplier)
}

func roundedAwayFromZero(toMultipleOf multiplier: Self) -> Self {
let xValue = self.roundedTowardZero(toMultipleOf: multiplier)
if xValue == self { return xValue }
return (multiplier.signum() == self.signum()) ? (xValue + multiplier) : (xValue - multiplier)
}
func roundedAwayFromZero(toMultipleOf multiplier: Self) -> Self {
let xValue = self.roundedTowardZero(toMultipleOf: multiplier)
if xValue == self { return xValue }
return (multiplier.signum() == self.signum()) ? (xValue + multiplier) : (xValue - multiplier)
}

func roundedDown(toMultipleOf multiplier: Self) -> Self {
return (self < 0) ? self.roundedAwayFromZero(toMultipleOf: multiplier)
: self.roundedTowardZero(toMultipleOf: multiplier)
}
func roundedDown(toMultipleOf multiplier: Self) -> Self {
return (self < 0) ? self.roundedAwayFromZero(toMultipleOf: multiplier)
: self.roundedTowardZero(toMultipleOf: multiplier)
}

func roundedUp(toMultipleOf multiplier: Self) -> Self {
return (self > 0) ? self.roundedAwayFromZero(toMultipleOf: multiplier)
: self.roundedTowardZero(toMultipleOf: multiplier)
}
func roundedUp(toMultipleOf multiplier: Self) -> Self {
return (self > 0) ? self.roundedAwayFromZero(toMultipleOf: multiplier)
: self.roundedTowardZero(toMultipleOf: multiplier)
}

func toHexString() -> String {
return "0x\(String(format: "%01X", Int(self)))"
}
}
3 changes: 2 additions & 1 deletion DXFeedFramework/Utils/StringUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class StringUtil {
return String(UnicodeScalar(UInt8(char)))
}
let value = (String(format: "%02X", Int(char) + 65536).substring(fromIndex: 1))
return char == 0 ? "\0" : "\\u" + value
let res = char == 0 ? "\\0" : "\\u" + value
return res
}

static func checkChar(char: Character, mask: Int, name: String) throws {
Expand Down
1 change: 0 additions & 1 deletion Samples/PerfTestCL/ConnectCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Where:

func execute() {
var arguments: [String]!

do {
arguments = try ArgumentParser().parse(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 4)
} catch {
Expand Down

0 comments on commit add0b33

Please sign in to comment.