Hello:
I am getting more and more familiar with python, and in orde to practice I am writing several codes and test them in my paper trading account, now I defined a function, this code I wrote was intended to place a specific limit order or a speciifc symbol, and cancel the order if the status is not filled within an specified ammount of time in seconds, here is the code:
def send_timed_limit_order(symbol, shares, price, time_in_seconds):
t_0 = time.time()
orderid = order( symbol , shares, LimitOrder((limit_price=price))
while (get_order_status(orderId) != 'Filled') :
t_1 = time.time()
diff = t_1 - t_0
if diff > time_in_seconds:
cancel_order(get_order(orderId))
What do you think about this function??, is that good, is that bad??, or maybe is there a way to make it better??? please comment on that
Thanks…
Hi Ghery,
I am glad to know that your python learning journey is going good.
Your code seems that it should work how you say it should but it's hard to judge how the code might perform just by looking at it. I suggest you test your code thoroughly before running it in the live environment.
Thanks for the advice, neverteless… When I used the code I import it from another file using :
import sys
sys.path.append('D:\Trading\Quantitative Trading\IbridgePy\Strategies')
from send_timed_limit_order import send_timed_limit_order
and I get the following error code:
File "D:\Trading\Quantitative Trading\IbridgePy\Strategies\send_timed_limit_order.py", line 18, in send_timed_limit_order
orderid = order( symbol , shares, LimitOrder(limit_price=entry ))
NameError: name 'order' is not defined
Could you help me with that please??
Hi Ghery,
IBridgePy follows a specific folder structure. All the strategies created inside the Strategies folder are run from the RUN_ME file. You have to type the name of the python file that you want to run in the RUN_ME file. In your case the file that you want to run is send_timed_limit_order.py.
The specific folder structure to follow is mentioned in the document in detail.
Hope this helps!