ibstockcli
ibstockcli copied to clipboard
realtimebar command causing panic: assignment to entry in nil map
I am trying to run the realtime command but I run into the following error no matter the symbol.
panic: assignment to entry in nil map
goroutine 1 [running]:
panic(0x5850e0, 0xc82009e0c0)
/usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
main.doRequestRealTimeBars(0xc820058300, 0xc82009e0bc, 0x3)
/root/gopath/src/github.com/dsouzae/ibstockcli/ibstockcli.go:276 +0x1e6
main.main.func21(0xc820058300, 0x0, 0x0)
/root/gopath/src/github.com/dsouzae/ibstockcli/ibstockcli.go:946 +0x6e
main.applyFunc(0xc82009e000, 0xc82000a840, 0x2, 0xc820024038, 0x1, 0x1, 0xc820045d68)
/root/gopath/src/github.com/dsouzae/ibstockcli/ibstockcli.go:498 +0x20d
main.main()
/root/gopath/src/github.com/dsouzae/ibstockcli/ibstockcli.go:948 +0x3a8b
exit status 2
Any help on this would be really helpful. Thanks
Thanks. I push the previous change without testing the response.
I have pushed a new change #(feb97b6) that initializes the map.
Let me know if it works for you.
Thanks for your prompt fix. I am still not sure if I am getting anything in the output.
pr > realtimebar ROG
17:28:30.971487 pr: Sending RealTime Bars For ROG
pr > 17:28:31.629562 pr ID: -1 Code:2106 Message:'HMDS data farm connection is OK:demohmds'
pr > realtimebar USD.JPY
17:30:38.954572 pr: Sending RealTime Bars For USD.JPY
pr > 17:30:38.964540 pr ID: 2 Code:200 Message:'No security definition has been found for the request'
I was expecting an output in the following manner:
log.Printf("%10s: %v - Open: %10.2f Close: %10.2f Low %10.2f High %10.2f Volume %10.2f Count %10v WAP %10.2f\n",symbol, time.Unix(r.Time, 0).Format("15:04:05"), r.Open, r.Close, r.Low, r.High, r.Volume, r.Count, r.WAP)
Am I missing anything ?
It looks like you are using a demo account. From what I read, demo account is limited, and doesn't support realtimebars.
Switching to the main account fixed it, but now I am getting the following error:
pr > realtimebar FB
10:03:06.074028 pr: Sending RealTime Bars For FB
pr > 10:03:06.320603 pr ID: 3 Code:420 Message:'Invalid Real-time Query:No market data permissions for ISLAND STK'
which I suppose means I don't have access to the NASDAQ but I am subscribed to the exchange on the account.
Also I am still getting the old message for the forex symbols.
pr > realtimebar USD.JPY
17:30:38.954572 pr: Sending RealTime Bars For USD.JPY
pr > 17:30:38.964540 pr ID: 2 Code:200 Message:'No security definition has been found for the request'
Not sure what needs to done here to see realtimebars of forex symbols. Do we need to toggle some setting too ?
Forex symbols are not handled right now in the code, just stocks.
You need to create a new contract to support forex symbols, see here: IB TWS API Contracts
Thanks for the heads up. I added the following to the main code to support forex symbols.
func NewForexContract(symbol string, currency string) ib.Contract {
return ib.Contract{
Symbol: symbol,
SecurityType: "CASH",
Exchange: "IDEALPRO",
Currency: currency,
}
}
func doRequestRealTimeBarsForex(mgr *IBManager, symbol string, currency string) {
request := ib.RequestRealTimeBars{
Contract: NewForexContract(symbol, currency),
BarSize: 5,
WhatToShow: ib.RealTimeMidpoint,
UseRTH: true,
}
id := mgr.NextOrderID()
request.SetID(id)
mgr.realtimeMap[id] = symbol
mgr.engine.Send(&request)
log.Printf("%s: Sending RealTime Bars For %s", mgr.label, symbol)
}
and an extra case
case command == "realtimebarf":
if len(strs) != 3 {
fmt.Printf("realtimebarf <symbol> <currency>\n")
continue
}
applyFunc(false, acctselect, acct, func(ac *IBManager) error {
doRequestRealTimeBarsForex(ac, strs[1], strs[2] )
return nil
})
The updated version worked perfect for just one time. After that I stopped getting any responses. On enabling the log on line 345(libstockcli.go) I finally got some output.
pr > realtimebarf USD JPY
23:23:05.617658 pr: Sending RealTime Bars For USD
pr > 23:23:06.746561 pr - RECEIVE *ib.ErrorMessage
23:23:06.746576 pr ID: -1 Code:2106 Message:'HMDS data farm connection is OK:cashhmds'
Please note that the above code worked for the first time but mysteriously stopped working thereafter when I tried to extract the main parts for a demo. Any ideas on what might be causing this issue. Also If I send repeated requests, I stop getting any response at all, not even the error or anything else For ex, here is my console output:
> select pr
pr > realtimebarf USD JPY
23:23:05.617658 pr: Sending RealTime Bars For USD
pr > 23:23:06.746561 pr - RECEIVE *ib.ErrorMessage
23:23:06.746576 pr ID: -1 Code:2106 Message:'HMDS data farm connection is OK:cashhmds'
pr > realtimebar fb
23:23:47.305542 pr: Sending RealTime Bars For fb
pr > 23:23:47.552300 pr - RECEIVE *ib.ErrorMessage
23:23:47.552363 pr ID: 3 Code:420 Message:'Invalid Real-time Query:No market data permissions for ISLAND STK'
pr > 23:30:06.758356 pr - RECEIVE *ib.ErrorMessage
23:30:06.758390 pr ID: -1 Code:2107 Message:'HMDS data farm connection is inactive but should be available upon demand.cashhmds'
23:30:36.178427 pr - RECEIVE *ib.ErrorMessage
23:30:36.178451 pr ID: -1 Code:2107 Message:'HMDS data farm connection is inactive but should be available upon demand.ushmds'
pr > realtimebarf USD JPY 23:33:07.679979 pr: Sending RealTime Bars For USD
pr > realtimebarf USD JPY
pr > realtimebarf USD JPY
pr > realtimebarf USD JPY
Not sure if the issue still belongs to this repo but would really appreciate if you can look into this. Thanks I also get a series of reconnect messages too, if I leave the cli for long time.Ex:
23:56:48.026088 pr - RECEIVE *ib.ErrorMessage
23:56:48.026103 pr ID: -1 Code:1102 Message:'Connectivity between IB and Trader Workstation has been restored - data maintained.'
The issue was the permission got toggled somehow. Thanks for all the help. The above code is working fine except I am getting -1 for "Volume" ,"WAP","Count" from TWS in return. Any idea on what might be causing it.