예제 #1
0
 def purchaseStockLimit(self, ticker, shares, price):
     result = Order()
     if (ticker != "" and shares > 0):
         order = equity_buy_limit(ticker, shares, price).set_duration(
             Duration.FILL_OR_KILL).build()
         result = self._placeOrder(order)
         print("Purchase Real: " + ticker)
     return result
예제 #2
0
    def place_buy_limit(self, symbol: str, quantity: int,
                        limit: Decimal) -> str:
        order = (equity_buy_limit(symbol, quantity, limit).set_duration(
            Duration.GOOD_TILL_CANCEL)).build()

        r = self.c.place_order(self.account_id, order)
        if not r.ok:
            raise BrokerException(r)

        order_id = Utils(self.c, self.account_id).extract_order_id(r)
        return order_id
예제 #3
0
def trader(request):
    form = StartTradeForm(request.POST or None)

    if request.method == "POST":
        if form.is_valid():
            builder = equity_buy_limit("REKR", 2, 2)
            res = c.place_order(config.ACCOUNT_ID, builder.build())
            orders = Standing_Orders
            filename = 'data/orders/order.txt'
            f = open(filename, 'w+')
            f.write(str(orders))
            print(res)
            return redirect("home")
    else:
        print('failed')
        return render(request, "trader/start_trade.html", {"form": form})
예제 #4
0
 def _submitBuy(self, event):
     '''
     Takes OrderEvent and submits a BUY order to the TDA account
     '''
     if event.trade_type == 'MARKET':
         self.client.place_order(
             self.ACC_ID,
             equities.equity_buy_market(
                 event.ticker,
                 event.quantity,
             ),
         )
     elif event.trade_type == 'LIMIT' and event.limit:
         self.client.place_order(
             self.ACC_ID,
             equities.equity_buy_limit(event.ticker, event.quantity,
                                       event.limit),
         )
     else:
         raise Exception('Invalid BUY order.')
예제 #5
0
def create_order(client, symbol, entry_price, qty, order_type):
    """ Takes client, symbol, entry_price, qty, and order_type ('long' or 'short') """
    if order_type == "short":
        try:
            client.place_order(account_id=ACCOUNT_ID,
                               order_spec=equity_sell_short_limit(
                                   symbol, qty,
                                   entry_price).set_order_type(OrderType.STOP).
                               clear_price().set_stop_price(entry_price))
        except:
            print(
                f"something went wrong creating short sell order: {sys.exc_info()}"
            )
            pass
    elif order_type == "long":
        try:
            client.place_order(account_id=ACCOUNT_ID,
                               order_spec=equity_buy_limit(
                                   symbol, qty,
                                   entry_price).set_order_type(OrderType.STOP).
                               clear_price().set_stop_price(entry_price))
        except:
            print(f"something went wrong creating order: {sys.exc_info()}")
            pass
button.click()

time.sleep(2)

tickers = driver.find_elements_by_tag_name("td")
i = 0
while i < 20:
    print(tickers[i].text)

client = ... # See "Authentication and Client Creation"

client.place_order(
    1000,  # account_id
    equity_buy_limit('GOOG', 1, 1250.0)
        .set_duration(Duration.GOOD_TILL_CANCEL)
        .set_session(Session.SEAMLESS)
        .build())

    i+=10
# for ticker in tickers:
#     print(ticker.text)
    # print(ticker.tag_name)
    # print(ticker.parent)
    # print(ticker.location)
    # print(ticker.size)
# time.sleep(2)

driver.quit()

# [0]: Ticker, [1]: Price, [2]: Rating, [3]: Score, [4]:Rating Change Date, [5]:Price Change %
# SVM