alpacahq / alpacahq/Alpaca-API

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

オープン
#166 コメント 1 件 リアクション 0 件 担当者 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 を短くまとめたダイジェスト。