alpacahq / alpacahq/Alpaca-API

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

Ouverte
#166 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Aucune donnée de langage
Étoiles
173
Forks
17
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.