-
Notifications
You must be signed in to change notification settings - Fork 74
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
"unknown time format" error while unmarshalling kite order object #111
Comments
can you please provide the code where you called the UnmarshalJSON function? |
After receiving json from redis, I use below code to unmarshall where I am getting "unknown time format" error. json.Unmarshal([]byte(jsonData), &result) |
I tried it out myself using redis and there was no error, the code i wrote is below: var (
ctx = context.Background()
RDB *redis.Client
)
func init() {
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
RDB = rdb
data, err := os.ReadFile("./data.json")
if err != nil {
panic("error reading file: " + err.Error())
}
if err := rdb.Set(ctx, "key", data, 0).Err(); err != nil {
panic("error while setting: " + err.Error())
}
}
func main() {
res, err := RDB.Get(ctx, "key").Result()
if err != nil {
panic("error while getting: " + err.Error())
}
result := kiteconnect.Order{}
err = json.Unmarshal([]byte(res), &result)
if err != nil {
panic(err.Error())
}
fmt.Println(result.OrderTimestamp)
} The data.json file contains the sample response provided. The above code produced the following output: go run main.go
2025-02-07 10:28:51 +0530 IST I think the issue is with the type of the result variable in your code. Can you please check it and let me know if the issue persists. |
Thanks, probably it's happening due to use of generics in my code. Anyways, I did a workaround in my code to avoid null i.e. if the timestamp is null, I am adding current time before saving to redis. Below is my code which I use to get an object from redis. I had to use generics so that I can retrieve any object passing it's type. `func GetJSON[T any](key string) (T, error) {
}` |
Use case: Save kite orders in redis and get it back.
Issue: While retrieving back from redis, the unmarshal of JSON fails with error as "unknown time format"
Root cause: If the order is rejected due to insufficient margin, we get exchange_update_timestamp and exchange_timestamp as null which throws error in the custom marshal written in models.Time package. Following is a sample response which caused the unmarshal error.
{ "status_message": "Insufficient funds. xxxx", "status_message_raw": "RMS:Margin Exceeds,Required:xxxx", "order_timestamp": "2025-02-07 10:28:51", "exchange_update_timestamp": null, "exchange_timestamp": null, "variety": "regular", "modified": false, "exchange": "BFO", "tradingsymbol": "SENSEX2521177800CE", "instrument_token": 215541253, "order_type": "LIMIT", "transaction_type": "SELL", "validity": "DAY", "validity_ttl": 0, "product": "NRML", "quantity": 940, "disclosed_quantity": 0, "price": 417, "trigger_price": 0, "average_price": 0, "filled_quantity": 0, "pending_quantity": 0, "cancelled_quantity": 0, "market_protection": 0, "meta": {}, "tag": "D8VxR", "tags": ["D8VxR"], "guid": "31654X5Rml1rmZcqK1" },
Please check and let me know if you need further details.
The text was updated successfully, but these errors were encountered: