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.
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]
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):