alpacahq / alpaca-py

The Official Python SDK for Alpaca API
https://alpaca.markets/sdks/python/getting_started.html
Apache License 2.0
537 stars 134 forks source link

[Bug]: Paper API - quantity in opened position is not the same as requested in market order #374

Closed mihaiprecupetu closed 10 months ago

mihaiprecupetu commented 10 months ago

Is there an existing issue for this?

Current Behavior

When I open an order, the filled quantity is slightly less then the one requested. This issue also happens when performing a HTTP rest call directly.

For example, opening BUY 0.1 BTCUSD will result in 0.09975 quantity.

Expected Behavior

After opening order, quantity on position should be exact as requested. After opening BUY 0.1 BTCUSD, the position should have exactly 0.1 quantity.

SDK Version I encountered this issue in

alpaca-py==0.13.1

Steps To Reproduce

1. trigger a market order BUY with 0.1 qty 
2. verify quantity in account position

Code: 

import alpaca.trading.client
import alpaca.trading.requests
import alpaca.trading.enums

trading_client = alpaca.trading.client.TradingClient(
    'xxxx', 'yyyyyyy', paper=True)

# preparing market order
market_order_data = alpaca.trading.requests.MarketOrderRequest(
    symbol="BTCUSD",
    qty=0.1,
    side=alpaca.trading.enums.OrderSide.BUY,
    time_in_force=alpaca.trading.enums.TimeInForce.GTC
)

# Market order
market_order = trading_client.submit_order(
    order_data=market_order_data
)

Filled out the Steps to Reproduce section?

Anything else?

image

hiohiohio commented 10 months ago

@mihaiprecupetu Please check crypto fees in the doc

Buy ETH/USD, you receive ETH, the fee is denominated in ETH

The example in the doc is ETH though, the 0.00025 BTC seems the fee of the trade. 0.25% == 0.0025 0.1 BTC * 0.0025 = 0.00025 BTC 0.1 BTC - 0.00025 BTC = 0.09975