alpacahq / alpacahq/alpaca-py

[Question]: How to Instantiate Bar type

未关闭
#573 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
1.5k
派生
398
平均合并
1 天 16 小时
30 天内合并 PR
6

描述

### Question form pre-submit checklist.

- [x] I have searched the existing issues to ensure there isn't already an issue about this question.
- [x] 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](https://github.com/alpacahq/Alpaca-API))
- [x] 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?

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。