alpacahq / alpacahq/Alpaca-API

Stop loss order seems to not work when the delta is small

未关闭
#166 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
没有语言数据
星标
173
派生
17
PR 合并指标
30 天内没有已合并 PR

描述

**Describe the bug**
When the stop loss order is created with small delta from the market price, I am getting the error: "stop price must be less than base_price - 0.01", even though I am taking care to send < base_price-0.01 value. See the code and response below:

code:
ticker = 'OCGN'
quantity = 1
symbol_price = api.get_last_trade(ticker).price
print(symbol_price)
k = min(round(symbol_price - 0.04,2), round(symbol_price * 0.998, 2))
print(round(symbol_price - 0.04,2))
print(round(symbol_price * 0.998, 2))
print(k)
api.submit_order(
symbol=ticker,
qty=quantity,
side='buy',
type='market',
time_in_force='day',
order_class='oto',
stop_loss={'stop_price': k} # stop loss
)

Response:
Connected to pydev debugger (build 193.6494.30)
13.969
13.93
13.94
13.93
Traceback (most recent call last):
File "C:\Users\xxxxx\.virtualenvs\Git_level_python-l32kb49C\lib\site-packages\alpaca_trade_api\rest.py", line 146, in _one_request
resp.raise_for_status()
File "C:\Users\xxxxx\.virtualenvs\Git_level_python-l32kb49C\lib\site-packages\requests\models.py", line 943, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://paper-api.alpaca.markets/v2/orders

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\xxxxx\.virtualenvs\Git_level_python-l32kb49C\lib\site-packages\alpaca_trade_api\rest.py", line 125, in _request
return self._one_request(method, url, opts, retry)
File "C:\Users\xxxxx\.virtualenvs\Git_level_python-l32kb49C\lib\site-packages\alpaca_trade_api\rest.py", line 154, in _one_request
raise APIError(error, http_error)
alpaca_trade_api.rest.APIError: stop price must be less than base_price - 0.01

Process finished with exit code 1

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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