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]: Crypto Demo: Not found for https://paper-api.alpaca.markets/v2/positions/BTC/USD #537

Open
2 tasks done
jmccarey opened this issue Dec 14, 2024 · 0 comments
Open
2 tasks done

Comments

@jmccarey
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

api_key = ""
secret_key = ""
paper = True 
trade_client = TradingClient(api_key=api_key, secret_key=secret_key, paper=paper, url_override=trade_api_url)



symbol = "BTC/USD"

# 404 response. API Error thrown 
position = trade_client.get_open_position(symbol_or_asset_id=symbol) 

# Also 404 response
trade_client.close_position( 
    symbol_or_asset_id = symbol,
    close_options = ClosePositionRequest(
        qty = "0.01",
    )
)

# Change the symbol to drop / and it's okay
symbol = "BTCUSD"

position = trade_client.get_open_position(symbol_or_asset_id=symbol) # 200

trade_client.close_position( # 200
    symbol_or_asset_id = symbol,
    close_options = ClosePositionRequest(
        qty = "0.01",
    )
)

# But the BTCUSD format doesn't work for historical data
# APIError: {"message":"invalid symbol: BTCUSD does not match ^[A-Z]+/[A-Z]+$"}
crypto_historical_data_client = CryptoHistoricalDataClient()

# get historical bars by symbol
# ref. https://docs.alpaca.markets/reference/cryptobars-1
now = datetime.now(ZoneInfo("America/New_York"))
req = CryptoBarsRequest(
    symbol_or_symbols = [symbol],
    timeframe=TimeFrame(amount = 1, unit = TimeFrameUnit.Hour), # specify timeframe
    start = now - timedelta(days = 1),                          # specify start datetime, default=the beginning of the current day.
    # end_date=None,                                        # specify end datetime, default=now
    limit = 2,                                               # specify limit
)
crypto_historical_data_client.get_crypto_bars(req).df

Expected Behavior

Ideally you could use the same symbol string for orders, positions, and historical data. That sounds like it could be an API change, but for now it could be good to update the demo.

SDK Version I encountered this issue in

alpaca-py 0.34.0

Steps To Reproduce

Run the provided code, or:

1. Setup a fresh crypto-trading-basic.ipynb
2. Run the notebook as normal. get_open_position(symbol_or_asset_id=symbol) and trade_client.close_position(symbol_or_asset_id = symbol...) raise API errors
3. Try symbol = "BTCUSD".  The notebook runs all the way until we access historical data. Then we get APIError: {"message":"invalid symbol: BTCUSD does not match ^[A-Z]+/[A-Z]+$"}

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

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

1 participant