Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Order filled status is not displayed #509

Open
2 tasks done
avrenli2 opened this issue Sep 28, 2024 · 1 comment
Open
2 tasks done

[Bug]: Order filled status is not displayed #509

avrenli2 opened this issue Sep 28, 2024 · 1 comment

Comments

@avrenli2
Copy link

avrenli2 commented Sep 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When I place a sell order, I would like to check if the sell order is filled or not.
But when paper trading, the filled_at attribute of the order remains None and is not updated.
For instance, I place an order for buying Bitcoin:

CLIENT = TradingClient( api_key='  ', secret_key='  ', paper=True)

BITCOIN_MONEY  = 2000

from alpaca.trading.requests import MarketOrderRequest

from alpaca.trading.enums import OrderSide, TimeInForce

BITCOIN_BUY_DATA = MarketOrderRequest( symbol="BTC/USD" , notional=BITCOIN_MONEY , side=OrderSide.BUY , 
                                      time_in_force=TimeInForce.GTC)

BUY_BITCOIN = CLIENT.submit_order(order_data=BITCOIN_BUY_DATA)

After buying the asset, I submit a sell order:

for X in CLIENT.get_all_positions():
 
  if X.symbol == "BTCUSD" :

     BITCOIN_QTY = float(X.qty)

     print( BITCOIN_QTY)

BITCOIN_SELL_DATA = MarketOrderRequest( symbol="BTCUSD" , qty=BITCOIN_QTY, side=OrderSide.SELL , 
                                      time_in_force=TimeInForce.GTC)

SELL_BITCOIN = CLIENT.submit_order(order_data=BITCOIN_SELL_DATA)

from datetime import sleep

sleep(5)

print(SELL_BITCOIN)

As seen, this prints the filled_at attribute as:

filled_at': None

How do we check if an order is filled or not?

Expected Behavior

When you run the following code with your API keys, the filled_at attribute of SELL_BITCOIN must differ from None. However, it remains None even after the order is filled. How do we trace if the order is filled or not?

CLIENT = TradingClient( api_key='  ', secret_key='  ', paper=True)

BITCOIN_MONEY  = 2000

from alpaca.trading.requests import MarketOrderRequest

from alpaca.trading.enums import OrderSide, TimeInForce

BITCOIN_BUY_DATA = MarketOrderRequest( symbol="BTC/USD" , notional=BITCOIN_MONEY , side=OrderSide.BUY , 
                                      time_in_force=TimeInForce.GTC)

BUY_BITCOIN = CLIENT.submit_order(order_data=BITCOIN_BUY_DATA)

from datetime import sleep

sleep(10)

for X in CLIENT.get_all_positions():
 
  if X.symbol == "BTCUSD" :

     BITCOIN_QTY = float(X.qty)

     print( BITCOIN_QTY)

BITCOIN_SELL_DATA = MarketOrderRequest( symbol="BTCUSD" , qty=BITCOIN_QTY, side=OrderSide.SELL , 
                                      time_in_force=TimeInForce.GTC)

SELL_BITCOIN = CLIENT.submit_order(order_data=BITCOIN_SELL_DATA)

from datetime import sleep

sleep(5)

print(SELL_BITCOIN)

Why is the filled_at attribute of SELL_BITCOIN None?

SDK Version I encountered this issue in

alpaca-py 0.30.1

Steps To Reproduce

Run the following code with your API keys:

CLIENT = TradingClient( api_key=' ', secret_key=' ', paper=True)
BITCOIN_MONEY  = 2000
from alpaca.trading.requests import MarketOrderRequest
from alpaca.trading.enums import OrderSide, TimeInForce
BITCOIN_BUY_DATA = MarketOrderRequest( symbol="BTC/USD" , notional=BITCOIN_MONEY , side=OrderSide.BUY , 
                                      time_in_force=TimeInForce.GTC)
BUY_BITCOIN = CLIENT.submit_order(order_data=BITCOIN_BUY_DATA)
from datetime import sleep
sleep(10)
for X in CLIENT.get_all_positions():
  if X.symbol == "BTCUSD" :
     BITCOIN_QTY = float(X.qty)
     print( BITCOIN_QTY)
BITCOIN_SELL_DATA = MarketOrderRequest( symbol="BTCUSD" , qty=BITCOIN_QTY, side=OrderSide.SELL , 
                                      time_in_force=TimeInForce.GTC)
SELL_BITCOIN = CLIENT.submit_order(order_data=BITCOIN_SELL_DATA)
sleep(10)
print(SELL_BITCOIN)

Why is the filled_at attribute of the sell order None?

Filled out the Steps to Reproduce section?

  • I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

No response

@hiohiohio
Copy link
Contributor

@avrenli2 to check the latest status of an order after submitting, could you please use CLIENT.get_order_by_id(order_id= SELL_BITCOIN .id) [1] to fetch the latest order info from server?

*1 https://alpaca.markets/sdks/python/api_reference/trading/orders.html#get-order-by-id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants