Cannot place a trade with fractional quantities of shares

Hello,

I have a problem with creating an order with fractional amounts of shares for S&P500 companies(which are available for fractional trading). Everytime I place an order with my script it says that everything is correct and then there is no order on the dashboard. Even though there is no problem with making the same order with manual trader for paper account. The script even executes block of code responsible for buying stocks, so I think that the function itself is accepting input with floating point numbers, but not executing it properly. Here are troublesome blocks of code in Python:

Example Code

    try:
        price = si.get_live_price(stock)
        amount = round(one_company_cap/price, 2)
        create_order(stock, amount, 'buy', 'market', 'gtc')
        print("Buying {} of {} for {}".format(amount, stock, price))
    except:
        print('Exception made. Probably lacking data for {}'.format(stock))
        pass   ```
and create order() looks like this:

def create_order(symbol, qty, side, type, time_in_force):
    data = {
        'symbol':symbol,
        'qty':qty,
        'side':side,
        'type':type,
        'time_in_force':time_in_force
    }

I’m not sure but according to documentation fractional values in the qty field allowed only for the market/day order type and time-in-force combination.

Oh, I didn’t notice that, thank you very much. I’ll try changing it.

Just tried it, and it worked perfectly. Thank you again, my friend

I also add this around my code to make sure Alpaca allows fractions for symbols I am trading. Item is my stock ticker

if item in fractionable:
order = api.submit_order(symbol=item, notional=amt_to_sell, side=“sell”)

And this is how I set fractionable in my code
apca_assets = api.list_assets()
fractionable = [asset.symbol for asset in apca_assets if asset.fractionable]

Hello, I’m having an issue with fractional share orders — tried to implement the solution from @oleg.rakhmatulin but am getting an error.

Here is my code:

When I use qty with a fractional amount:

alpaca.submit_order(symbol=‘SPY’, qty=1.5, side=‘buy’, type=‘market’, time_in_force=‘day’)
alpaca_trade_api.rest.APIError: qty must be integer

When I use notional:

alpaca.submit_order(symbol=‘SPY’, notional=600, side=‘buy’, type=‘market’, time_in_force=‘day’)
alpaca_trade_api.rest.APIError: qty is required

Any ideas for what I might do differently to get this to work?

try notional like this ===> alpaca.submit_order(symbol=‘SPY’, notional=600, side=‘buy’)

@Sanjay_Jadhav thanks, I tried it and here is what I get:

alpaca_trade_api.rest.APIError: qty is required

any other ideas, I’m open to trying them.

Hi, I’m getting the error as you. I think it might be because fractional shares are only available for ‘market’ orders with a time in force of ‘day’ and I’ve been trying when the market is closed.

I’m going to try tomorrow when the market is open and report back.

I was able to resolve the issue before market open. Based on this article:

By default all Alpaca accounts are allowed to trade fractional shares in both live and paper environments. Please make sure you reset your paper account if you run into any issues dealing with fractional shares.

I reset my paper account and now fractional shares API orders are working both through the Python SDK and the Rest API (via Postman). I’ve copied the curl command I’m using below (with API keys removed):

curl --location --request POST 'https://paper-api.alpaca.markets/v2/orders' \
--header 'APCA-API-KEY-ID: APCA-API-KEY-ID_VARIABLE' \
--header 'APCA-API-SECRET-KEY: APCA-API-KEY-ID_VARIABLE' \
--header 'Content-Type: application/json' \
--data-raw '{
    "symbol": "AAPL",
    "notional": 100,
    "side": "buy",
    "type": "market",
    "time_in_force": "day"
}'
2 Likes

Hi, thanks for posting. Apologies for my delayed response, I’ve been away for several weeks.

I’m going to reset my account like you did…hopefully this will work for me too.

Happy 2022!