alpacahq / alpacahq/Alpaca-API

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

Abierto
#166 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Sin datos de lenguaje
Estrellas
173
Forks
17
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.