Skip to content

[Question]: How to Instantiate Bar type #573

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

Open
3 tasks done
kushalj1997 opened this issue Mar 21, 2025 · 0 comments
Open
3 tasks done

[Question]: How to Instantiate Bar type #573

kushalj1997 opened this issue Mar 21, 2025 · 0 comments

Comments

@kushalj1997
Copy link
Contributor

Question form pre-submit checklist.

  • I have searched the existing issues to ensure there isn't already an issue about this question.
  • My question has to do with the Python SDK and isn't a general question about the API. (If it is please open your issue here)
  • My question isn't about how to do a specific algorithm or asking for trade advice (answers to these are outside the scope of this repo).

Question

Hi, I'm trying to instantiate a Bar object as an argument in a function call.

self.insert_into_db(
                    bar=Bar(
                        symbol=symbol,
                        raw_data={
                            "symbol": symbol,
                            "timestamp": trading_minute.timestamp(),
                            "open": np.nan,
                            "high": np.nan,
                            "low": np.nan,
                            "close": np.nan,
                            "volume": np.nan,
                        },
                    )
                )

When I run this code, I get this error

Error generating data for TSLA: 8 validation errors for Bar
timestamp
  Field required [type=missing, input_value={'symbol': 'TSLA'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
open
  Field required [type=missing, input_value={'symbol': 'TSLA'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
high
  Field required [type=missing, input_value={'symbol': 'TSLA'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
low
  Field required [type=missing, input_value={'symbol': 'TSLA'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
close
  Field required [type=missing, input_value={'symbol': 'TSLA'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
volume
  Field required [type=missing, input_value={'symbol': 'TSLA'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
trade_count
  Field required [type=missing, input_value={'symbol': 'TSLA'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
vwap
  Field required [type=missing, input_value={'symbol': 'TSLA'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing
Traceback (most recent call last):
  File "/Users/kushaljaligama/dev/projects/deep-trader-0/deep-trader/alpaca_data_loader.py", line 290, in generate_single_stock_training_set
    self.generate_single_stock_single_day(symbol, trading_day)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kushaljaligama/dev/projects/deep-trader-0/deep-trader/alpaca_data_loader.py", line 270, in generate_single_stock_single_day
    bar=Bar(
        symbol=symbol,
    ...<8 lines>...
        },
    )
  File "/opt/homebrew/lib/python3.13/site-packages/alpaca/data/models/bars.py", line 51, in __init__
    super().__init__(symbol=symbol, **mapped_bar)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.13/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 8 validation errors for Bar
timestamp

Any ideas? Also do you guys have a discord?

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