Hello there:
I wrote a code in order to use a particular ticker at a particular price, with a particular number of shares, this code send a limit order together with a take profit order, and also fetches the data so that if the stocks goes bellow my risk level , a market order is sent in order to cut loses, this is the code:
def initialize(context):
context.flag = False
context.flag1 = False
context.ticker = str(input("Enter the ticker:"))
context.shares = int(input("Enter the number of shares:"))
context.price = float (input("Enter price:"))
context.security = superSymbol(secType='STK', symbol=context.ticker , currency='USD', exchange='SMART')
def handle_data(context, data):
position = get_position(context.security)
if (context.flag1==False and position.amount == 0):
place_order_with_takeprofit(context.security, context.shares, takeProfitPrice = 1.04context.price, style = LimitOrder(limit_price=context.price))
context.flag1 = True
position = get_position(context.security)
print ('Stock:',position.amount, '; Entry:',position.cost_basis,', Last:',data.current(context.security,'price'))
if (context.flag==False and position.amount != 0):
if data.current(context.security,'price') <= 0.965(position.price):
order(context.security,-1*position.amount , style=MarketOrder(), outsideRth=True)
context.flag = True
end
Now, I get an error message that says "errorCode:110 errorId:851 errorMessage=The price does not conform to the minimum price variation for this contract."
I tried to trade 500 shares of ticker PIX at the enter price of "3.29". Could anyone help me with this??
Hi Ghery,
It seems like "3.29" is not a valid price for PIX. The price does not confirm the minimum price variation of the contract. What it means is every contract has the smallest price moment for a contract, for example, if the minimum price variation of the PIX is 0.05 you can only place an order that is LTP + (x * 0.05) or LTP - (x * 0.05).
To put it more simple if the LTP of PIX is 3.05 then the following are the valid prices for PIX
…
2.95
3.00
3.05 - LTP
3.10
3.15
…
You can not place an order at 3.06.
I recommend you check the last traded prices of PIX and from that, you can figure out the minimum price variation for PIX. And from that, you can get a valid price for the same.
I hope this helps
Thanks