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

Serializing and Deserializing MarketBook to/from JSON loses market_definition #517

Open
vincentmele opened this issue Mar 14, 2023 · 0 comments

Comments

@vincentmele
Copy link

vincentmele commented Mar 14, 2023

I am trying to serialize and deserialize MarketBook objects. I am 1) going from MarketBook to JSON, then 2) JSON back to MarketBook. It appears that when converting JSON to MarketBook, the marketDefinition does not set itself. With a bit of trial and error, I discovered that I can get a correct MarketBook by setting the key "market_definition" instead of the "marketDefinition" in the JSON outputted from first step.

Assuming an existing, populated MarketBook object as "mb1"

Doesn't work, market_definition is not set:

import json
mb_json = mb1.json()
mb_dict = json.loads(mb_json)
new_mb = MarketBook(**mb_dict)
# new_mb.market_definition is None at this point.

Works, market_definition is set:

import json
mb_json = mb1.json()
mb_dict = json.loads(mb_json)
mb_dict['market_definition'] = mb_dict['marketDefinition']
new_mb = MarketBook(**mb_dict)
# new_mb.market_definition has correct output

If this isn't how I should be storing MarketBooks, I'd be more than happy to be corrected :-)

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

1 participant