Пример #1
0
    def order(self, ticker, direction, amount):
        '''
        下单函数.向blotter中添加order对象。目前默认按照开盘价下单。
        
        Parameters
        ----------
            ticker
                股票代码
            direction
                方向
            amount
                数量,如300股
        '''
        order_price = self.data_provider.current_date_data[ticker][1][
            'open_price']

        if direction == 1:
            if order_price * amount < self.cash:
                order = Order(ticker, direction, amount, order_price)
                self.blotter.current_orders_universe.append(order)
            else:
                pass

        if direction == -1:
            if self.position.position[ticker] >= amount:
                order = Order(ticker, direction, amount, order_price)
                self.blotter.current_orders_universe.append(order)
            else:
                pass
Пример #2
0
    def fromXml(xmlDoc, plant):
        """
		A static method that creates an OrderList instance from an XML tree
		node and returns it.
		"""
        orderList = OrderList()
        for e in xmlDoc.getElementsByTagName("order"):
            orderList.addOrder(Order.fromXml(e, plant))
        return orderList
Пример #3
0
def _create_order_object(customer, date, customer_address, customer_phone,
                         purchase_price, note, order_details):

    int_purchase_price = int(purchase_price)
    order = Order(None, customer or None, date or None, customer_address,
                  customer_phone, int_purchase_price or None, note, list())
    for detail_info in order_details:
        order_details = OrderDetails(None, int(detail_info[0]), detail_info[1],
                                     int(detail_info[2]), None)
        order.order_details.append(order_details)

    return order
    def account_menu(self):
        """
        Provides the different options for the sample application: balance, portfolio, view orders

        :param self: Pass in authenticated session and information on selected account
        """

        if self.account["institutionType"] == "BROKERAGE":
            menu_items = {
                "1": "Balance",
                "2": "Portfolio",
                "3": "Orders",
                "5": "Rebalance",
                "6": "Go Back"
            }

            while True:
                print("")
                options = menu_items.keys()
                for entry in options:
                    print(entry + ")\t" + menu_items[entry])

                selection = input("Please select an option: ")
                if selection == "1":
                    self.balance()
                elif selection == "2":
                    self.portfolio()
                elif selection == "3":
                    order = Order(self.session, self.account, self.base_url)
                    order.view_orders()
                elif selection == "5":
                    rebalancer = Rebalancer(self.holdingsDict)
                    print(rebalancer.rebalance())
                elif selection == "6":
                    break
                else:
                    print("Unknown Option Selected!")
        elif self.account["institutionType"] == "BANK":
            menu_items = {"1": "Balance", "2": "Go Back"}

            while True:
                print("\n")
                options = menu_items.keys()
                for entry in options:
                    print(entry + ")\t" + menu_items[entry])

                selection = input("Please select an option: ")
                if selection == "1":
                    self.balance()
                elif selection == "2":
                    break
                else:
                    print("Unknown Option Selected!")
        else:
            menu_items = {"1": "Go Back"}

            while True:
                print("")
                options = menu_items.keys()
                for entry in options:
                    print(entry + ")\t" + menu_items[entry])

                selection = input("Please select an option: ")
                if selection == "1":
                    break
                else:
                    print("Unknown Option Selected!")
        new_data_point_features = features_final.loc[
            new_data_point.Date].values.reshape(1, -1)

        signal = model.predict(new_data_point_features)

        if signal == 1 or DEBUG_BASE_ONLY:

            print("Long Entry Signal")
            Long_Entry_price = new_data_point.Close
            Long_Stop_Price = new_data_point.Close * 0.99
            Long_Target_Price = new_data_point.Close * 1.02
            Long_Quantity = QTY
            Long_Max_Holding_period = datetime.datetime.now()
            Long_Order = Order(SMA_portfolio, new_data_point.symbol, 'Long',
                               new_data_point.Date, Long_Entry_price,
                               Long_Target_Price, Long_Stop_Price,
                               Long_Quantity, Long_Max_Holding_period, 5)

            if SMA_portfolio.FreeCapital > Long_Order.margin_required:
                SMA_portfolio.add(Long_Order)

        open_trades = SMA_portfolio.Open_Trades

        for trade in open_trades:
            if trade.direction == 'Short':
                trade.max_holding_period = new_data_point.Date

    if prev_data_point.MA_5 > prev_data_point.MA_20 and new_data_point.MA_5 < new_data_point.MA_20:

        new_data_point_features = features_final.loc[
            new_data_point.Date].values.reshape(1, -1)
Пример #6
0
"""Inserting orders to the database."""
from database.db_utils import db_connect, create_order
from order.order import Order

con = db_connect()
# at least 5 orders in the database
ord_1 = Order("Dell XPS 15", 12, 1)
ord_2 = Order("Acer Swift 5", 8, 2)
ord_3 = Order("ASUS ZenBook 14", 3, 2)
ord_4 = Order("Apple MacBook Air 2018", 15, 4)
ord_5 = Order("Lenovo ThinkPad L590", 11, 3)

try:
    for i in range(1, 6):
        order = globals()["ord_" + str(i)]
        create_order(con, order.name, order.amount, order.client_id)
        con.commit()
except:
    con.rollback()
    raise RuntimeError("Could not commit.")
Пример #7
0
def test_create_order():
    o = Order()
    assert hasattr(o, "created_at")
    assert o._created_at == o.created_at
    assert hasattr(o, "id")
    assert len(o.id) == 20
Пример #8
0
def test_compare_orders():
    o1 = Order()
    o2 = Order()
    assert o1 > o2