Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBPriceBar failed to decode double #6

Closed
shial4 opened this issue Apr 25, 2024 · 6 comments
Closed

IBPriceBar failed to decode double #6

shial4 opened this issue Apr 25, 2024 · 6 comments

Comments

@shial4
Copy link
Collaborator

shial4 commented Apr 25, 2024

I've tried to subscribe to ETH, using below method and utilising raw initialiser for your enums from values
marketData("ETH", interval: 5, secType: "CRYPTO", exchange: "PAXOS")

private func historicBarPublisher(
        for contract: IBContract,
        barSize size: IBBarSize = .minute,
        duration: IBDuration = IBDuration.continuousUpdates(60, unit: .second)
    ) throws -> Int {
        let requestID = client.nextRequestID
        try client.requestPriceHistory(
            requestID,
            contract: contract,
            barSize: size, // from raw time interval == 5
            barSource: IBBarSource.trades,
            lookback: duration // IBDuration.continuousUpdates(60, unit: .second)
        )
        return requestID
    }

IBPriceBar fails to decode double

Decoding error: cant unwrap double from , cursor: 5  ["90", "1", "-1", "20240425-06:50:40", "", "", "", "", "0", "-1"]
@stensoosaar
Copy link
Owner

stensoosaar commented Apr 25, 2024

will investigate
as a workaround:

var subscriptions: [AnyCancellable] = []

client.eventFeed.sink (
	receiveCompletion: { completion in
		print(completion)
	}, receiveValue: { anyEvent in	
		switch anyEvent{
		case let event as IBPriceHistory:
			event.prices.forEach{print($0)}
			print(String(repeating: "-", count: 30))
		case let event as IBPriceBarUpdate:
			print("update", event)
		default: break
		}
	}
).store(in: &subscriptions)
	
do {
	let requestID = client.nextRequestID
	let crypto = IBContract.crypto("ETH", currency: "USD", exchange: .PAXOS)
	// 5 minute history + updates
	let lookback = IBDuration.continuousUpdates(300, unit: .second) 
	let resolution = IBBarSize.minute
	let source = IBBarSource.trades
	try client.requestPriceHistory(requestID, contract: crypto, barSize: resolution, barSource: source, lookback: lookback)
} catch {
	print(error.localizedDescription)
}

output:
IBPriceBar(date: 2024-04-25 04:30:00 +0000, open: 3147.45, high: 3148.1, low: 3147.45, close: 3148.05, volume: Optional(0.00270185), wap: Optional(3147.93), count: Optional(4))
IBPriceBar(date: 2024-04-25 04:31:00 +0000, open: 3148.85, high: 3148.85, low: 3148.75, close: 3148.75, volume: Optional(0.02926551), wap: Optional(3148.755), count: Optional(4))
IBPriceBar(date: 2024-04-25 04:32:00 +0000, open: 3148.75, high: 3148.75, low: 3148.75, close: 3148.75, volume: Optional(0.0182358), wap: Optional(3148.75), count: Optional(1))
IBPriceBar(date: 2024-04-25 04:33:00 +0000, open: 3148.75, high: 3149.45, low: 3148.75, close: 3149.45, volume: Optional(0.06193536), wap: Optional(3148.93), count: Optional(2))
IBPriceBar(date: 2024-04-25 04:34:00 +0000, open: 3149.8, high: 3149.8, low: 3147.35, close: 3147.35, volume: Optional(0.04785002), wap: Optional(3147.385), count: Optional(3))
IBPriceBar(date: 2024-04-25 04:35:00 +0000, open: 3147.35, high: 3147.35, low: 3147.35, close: 3147.35, volume: nil, wap: Optional(3147.35), count: nil)
------------------------------
update IBPriceBarUpdate(requestID: 0, bar: IBKit.IBPriceBar(date: 2024-04-25 04:35:00 +0000, open: 3147.35, high: 3147.35, low: 3147.35, close: 3147.35, volume: Optional(3147.35), wap: nil, count: nil))
update IBPriceBarUpdate(requestID: 0, bar: IBKit.IBPriceBar(date: 2024-04-25 04:35:00 +0000, open: 3147.35, high: 3147.35, low: 3147.35, close: 3147.35, volume: Optional(3147.35), wap: nil, count: nil))
´´´
	

@shial4
Copy link
Collaborator Author

shial4 commented Apr 25, 2024

@stensoosaar

I did run exactly the code you've suggested. with the result as shown below:

IBPriceBar(date: 2024-04-24 23:15:00 +0000, open: 3146.8, high: 3147.55, low: 3145.65, close: 3146.8, volume: Optional(1.01447713), wap: Optional(3146.755), count: Optional(10))
IBPriceBar(date: 2024-04-24 23:16:00 +0000, open: 3146.0, high: 3146.75, low: 3143.95, close: 3143.95, volume: Optional(0.01263599), wap: Optional(3145.365), count: Optional(11))
IBPriceBar(date: 2024-04-24 23:17:00 +0000, open: 3143.5, high: 3143.5, low: 3139.65, close: 3139.65, volume: Optional(0.36111044), wap: Optional(3142.775), count: Optional(8))
IBPriceBar(date: 2024-04-24 23:18:00 +0000, open: 3140.0, high: 3140.0, low: 3138.4, close: 3138.4, volume: Optional(0.17206784), wap: Optional(3139.925), count: Optional(12))
IBPriceBar(date: 2024-04-24 23:19:00 +0000, open: 3138.2, high: 3138.3, low: 3136.5, close: 3137.3, volume: Optional(0.28090953), wap: Optional(3137.19), count: Optional(21))
IBPriceBar(date: 2024-04-24 23:20:00 +0000, open: 3137.3, high: 3141.6, low: 3137.25, close: 3141.6, volume: Optional(0.4254993), wap: Optional(3139.54), count: Optional(18))
------------------------------
Decoding error: cant unwrap double from , cursor: 5  ["90", "1", "-1", "20240425-09:21:00", "", "", "", "", "0", "-1"]
Decoding error: cant unwrap double from , cursor: 5  ["90", "1", "-1", "20240425-09:21:00", "", "", "", "", "0", "-1"]
Decoding error: cant unwrap double from , cursor: 5  ["90", "1", "-1", "20240425-09:21:00", "", "", "", "", "0", "-1"]

@stensoosaar
Copy link
Owner

With the most recent update I included this request into playgrounds market data page. Does it produce the same error?

@shial4
Copy link
Collaborator Author

shial4 commented Apr 25, 2024

yup, I use IB Gateway 10.19 from here
localised for AU

@stensoosaar
Copy link
Owner

I managed to reproduce the error earlier, but after using IBPriceBarHistoryUpdate instead of IBPriceBarUpdate for decoding, it seemed to vanish...

gateway 10.25
set region to Asia, time zone to Australia/Sydney
branch: main
playground page: market data

and the result:

Server version: Optional(175)
IBPriceBar(date: 2024-04-25 11:23:00 +0000, open: 3097.55, high: 3099.45, low: 3097.05, close: 3099.45, volume: Optional(0.49353841), wap: Optional(3098.74), count: Optional(29))
IBPriceBar(date: 2024-04-25 11:24:00 +0000, open: 3099.5, high: 3100.8, low: 3099.5, close: 3100.8, volume: Optional(0.33013874), wap: Optional(3099.94), count: Optional(33))
IBPriceBar(date: 2024-04-25 11:25:00 +0000, open: 3100.8, high: 3101.55, low: 3098.6, close: 3099.4, volume: Optional(0.57270639), wap: Optional(3098.98), count: Optional(26))
IBPriceBar(date: 2024-04-25 11:26:00 +0000, open: 3099.45, high: 3102.05, low: 3099.4, close: 3102.05, volume: Optional(0.03535837), wap: Optional(3101.225), count: Optional(20))
------------------------------
2024-04-25 11:26:52 +0000 update IBPriceBarUpdate(requestID: 0, bar: IBKit.IBPriceBar(date: 2024-04-25 11:26:00 +0000, open: 3099.45, high: 3101.0, low: 3102.05, close: 3099.4, volume: Optional(0.14970534), wap: Optional(3101.053141947041), count: nil))
2024-04-25 11:26:52 +0000 update IBPriceBarUpdate(requestID: 0, bar: IBKit.IBPriceBar(date: 2024-04-25 11:26:00 +0000, open: 3099.45, high: 3101.0, low: 3102.05, close: 3099.4, volume: Optional(0.14970534), wap: Optional(3101.053141947041), count: nil))

@shial4
Copy link
Collaborator Author

shial4 commented May 15, 2024

This issue still persist for the given use case. when using IBDuration.continuousUpdates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants