def exercise_4(): """ :return: nothing, it resolves the exercise 4 """ fridges = [Fridge(1, "haceb"), Fridge(2, "lg"), Fridge(3, "ibm"), Fridge(4, "haceb"), Fridge(5, "lg"), Fridge(6, "ibm"), Fridge(7, "haceb"), Fridge(8, "lg"), Fridge(9, "ibm"), Fridge(8, "lg"), Fridge(9, "ibm")] orders = [Order("eafit", 10), Order("la14", 2), Order("olimpica", 4), Order("exito", 1)] manage_fridges(fridges, orders)
def from_xml_to_order(root): order = { 'order_name': root.attrib['order_name'], 'order_price': root.attrib['order_price'], 'order_country': root.attrib['order_country'], 'delivery_time': root.attrib['delivery_time'], 'goods': [{ 'good_country': el.attrib['good_country'], 'good_name': el.attrib['good_name'], 'good_price': el.attrib['good_price'], 'good_production_date': el.attrib['good_production_date'] } for el in root.find('goods').iter('good')] } new_order = Order(order['order_name'], order['order_country'], datetime.strptime(order['delivery_time'], '%Y-%m-%dT%H:%M:%S')) new_order.price_of_order = order['order_price'] new_order.goods = order['goods'] return new_order
def initialize(self): self.dishes_list = [] for row in db.fetch(): self.dishes_list.append(Dish(row[0],row[1],row[2],row[3])) self.order_list = [] self.order_no = [] for row in db.fetchorder(): self.order_list.append(Order(row[0],row[1],row[2],row[3],row[4],row[5])) self.order_no.append(str(row[0]))
def add_g_to_o(params): print "adding" g_path = STORAGE_ROOT+'/good-'+params['name']+'_'+params['country']+'_'+params['g_id']+'.json' t_good = json.load(open(g_path, 'r')) t_good = dict_to_good(t_good) print t_good o_path = STORAGE_ROOT+'/order-'+params['to']+'_'+params['ord_c']+'_'+params['o_id']+'.json' t_order = json.load(open(o_path, 'r')) #print t_good, t_order new_order = Order(t_order['name'], t_order['country'], datetime.strptime(t_order['delivery_time'], '%d.%m.%Y').strftime('%d.%m.%Y')) new_order.goods = dict_to_goods(t_order['goods']) new_order.price_of_order = int(t_order['price']) + int(t_good.good_price) new_order.goods.append(t_good) obj = new_order.to_dict() full_path = "%s\%s-%s_%s_%s.json" % (STORAGE_ROOT, 'order', new_order.order_name, new_order.delivery_country, params['o_id']) wfile = open(full_path, 'w') json.dump(obj, wfile) wfile.close()
class MyTest(unittest.TestCase): item = Item() order = Order() def test_add_item(self): result = self.item.add_item('test_item', 'test_type', 100) self.assertTrue(result) def test_add_item_view1(self): result = self.item.add_item('', '', 100) self.assertFalse(result) def test_add_item_view2(self): result = self.item.add_item('test', 'type', 'asd') self.assertFalse(result) def test_add_item_view3(self): result = self.item.add_item('', '', -100) self.assertFalse(result) def test_show_items(self): data = self.item.show_item() actual_result = len(data) expected_result = 9 self.assertEqual(expected_result, actual_result) def test_search_item(self): data = self.item.search_item('momo') actual_result = len(data) expected_result = 2 self.assertEqual(expected_result, actual_result) def test_search_items1(self): data = self.item.search_item('noodle') actual_result = len(data) expected_result = 0 self.assertEqual(expected_result, actual_result) def test_update_item(self): result = self.item.update_item(4, "khana", "non-veg", 220) self.assertTrue(result) def test_update_item1(self): result=self.item.update_item(4, "khana", "veg", 200) self.assertFalse(result) def test_delete_item(self): result=self.item.delete_item(4) self.assertFalse(result) def test_add_order(self): result=self.order.add_order(4[]) self.assertTrue(result)
class MyTest(unittest.TestCase): item = Item() order = Order() def test_add_item(self): result = self.item.add_item('test_item', 'test_type', 100) self.assertTrue(result) def test_add_item_view(self): result = self.item.add_item('', '', 100) self.assertFalse(result) def test_add_item_view_1(self): result = self.item.add_item('test', 'type', 'asd') self.assertFalse(result) def test_add_item_view_2(self): result = self.item.add_item('', '', -100) self.assertFalse(result) def test_show_items(self): data = self.item.show_item() actual_result = len(data) expected_result = 9 self.assertEqual(expected_result, actual_result) def test_search_item(self): data = self.item.search_item('momo') actual_result = len(data) expected_result = 2 self.assertEqual(expected_result, actual_result) def test_search_items1(self): data = self.item.search_item('noodle') actual_result = len(data) expected_result = 0 self.assertEqual(expected_result, actual_result) def test_update_item(self): result = self.item.update_item(5, "Masu", "veg", 600) self.assertTrue(result) def test_delete_item(self): result = self.item.delete_item(5) self.assertTrue(result) def test_delete_item_1(self): result = self.item.delete_item("aa") self.assertFalse(result) def test_add_order(self): result = self.order.add_order(5, ("burger", "chicken", "150")) self.assertTrue(result)
def main(): rows, cols, n_drones, deadline, max_load = input_ints() """Products""" number_of_product_types = input_int() product_weights = input_ints() """Warehouses""" number_of_warehouses = input_int() warehouses = [] for _ in range(number_of_warehouses): position = input_intpair() product_stock = input_ints() warehouses.append(Warehouse(position, product_stock)) """Drones""" drones = [Drone(warehouses[0].pos) for _ in range(n_drones)] Drone.capacity = max_load """Customer orders""" number_of_orders = input_int() orders = [] for _ in range(number_of_orders): position = input_intpair() number_of_products_ordered = input_int() products_ordered = input_ints() orders.append(Order(position, products_ordered)) try: print(input()) except EOFError: pass else: print("There was something left in the input data, exiting") exit(1) print("Warehouses: {}, Drones: {}, Orders: {}".format( len(warehouses), n_drones, len(orders))) print("Drone capacity: {}".format(Drone.capacity)) def get_first_available_drone(): return sorted(drones, key=lambda d: d.turn)[0] def get_closest_order(pos): return sorted(orders, key=lambda o: distance_to(o.pos, pos)) print("First available drone: {}".format(get_first_available_drone())) min_turn = 0 while len(orders) > 0 or deadline < min_turn: get_first_available_drone().load()
def create_order_dictionary(orders_file): line_number = 0 orders_dict = {} for line in orders_file: line_number += 1 pieces = line.split(",") if len(pieces) != 2: raise FormatException(line_number, orders_file.name, line) elif pieces[0] != "id": try: id = int(pieces[0]) name = pieces[1] if name[-1] == "\n": name = name[:-1] orders_dict[id] = Order(id, name) except: raise FormatException(line_number, orders_file.name, line) return orders_dict
def checkForMorningBreakoutStrategy(tickers, item, orderQueue, ORDERS, price, time, currentInvested, DTBP, candleTime): #checks for 'morning breakout' strategy if (tickers[item].currentCandle.closePrice > tickers[item].morningHigh and tickers[item].currentCandle.closePrice < tickers[item].morningHigh * 1.003 and time <= '7:30:00' and tickers[item].canTrade and not tickers[item].havePosition): #[test] print(time + '\t' + 'morning breakout in ' + item) #[test] size = round(10000 / price) #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : size, 'price' : price}}) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'morning breakout breakout' #add order to list order = Order(item, candleTime, price, 'morning breakout', size, 'long') ORDERS.append(order) #[test] print('DTBP not exceeded') #[test]
def checkForBearish3BarReversalStrategy(tickers, item, orderQueue, ORDERS, size, price, time, currentInvested, DTBP, candleTime): #checks for 'bullish 3-bar reversal' strategy if (checkLowOfDay(tickers, item, 'bearish') and checkTrend(tickers, item, 'bearish') and checkLastTwoBars(tickers, item, 'bearish') and checkReversalBar(tickers, item, 'bearish') and tickers[item].canTrade == True and tickers[item].havePosition == False): #[test] print(time + '\t' + 'bearish 3-bar reversal in' + item) #[test] #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): print('DTBP not exceeded') #[test] orderQueue.append({ item: { 'action': 'SELL_SHORT', 'symbol': item, 'size': size, 'price': price } }) #update ticker info tickers[item].direction = "short" tickers[item].strategy = 'bearish 3-bar reversal' tickers[item].breakoutBarHigh = tickers[item].priceHistory[-2].high #add order to list order = Order(item, candleTime, price, 'bearish 3-bar reversal', size, 'short') ORDERS.append(order) return True #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): #[test] print('Using smaller size') #[test] smallerSize = DTBP - 1000 - currentInvested / price #[test] orderQueue.append({ item: { 'action': 'SELL_SHORT', 'symbol': item, 'size': smallerSize, 'price': price } }) #update ticker info tickers[item].direction = "short" tickers[item].strategy = 'bearish 3-bar reversal' tickers[item].breakoutBarHigh = tickers[item].priceHistory[-2].high #add order to list order = Order(item, candleTime, price, 'bearish 3-bar reversal', smallerSize, 'short') ORDERS.append(order) return True else: return False
import my_sorting import services from datetime import datetime good_1 = Good('shovel', 'Germany', 50000, datetime(2013, 12, 11)) good_2 = Good('steel', 'Italy', 25000, datetime(2013, 8, 4)) good_3 = Good('snow', 'Russia', 5000, datetime(2012, 10, 12)) good_4 = Good('kola', 'Nigeria', 9000, datetime(2012, 12, 14)) good_5 = Good('ananases', "USA", 80000, datetime(2012, 11, 15)) good_6 = Good('coffee', "Africa", 75600, datetime(2011, 10, 24)) good_7 = Good('meat', "Mexico", 35200, datetime(2013, 9, 8)) good_8 = Good('bread', "Japan", 3200, datetime(2013, 10, 6)) good_9 = Good('bad', "UK", 76580, datetime(2013, 11, 10)) all_goods = [good_1, good_2, good_3, good_4, good_5, good_6, good_7, good_8, good_9] order_1 = Order("'Avangard'", 'USA', datetime(2013, 10, 24)) order_1.goods = [good_1, good_2, good_3] order_1.price_of_order = Order.total_price(order_1) order_2 = Order("'Azazaza'", 'RUS', datetime(2013, 11, 14)) order_2.goods = [good_4, good_5, good_6] order_2.price_of_order = Order.total_price(order_2) order_3 = Order("'Trust'", 'UK', datetime(2014, 2, 8)) order_3.goods = [good_7, good_8, good_9] order_3.price_of_order = Order.total_price(order_3) all_orders = [order_1, order_2, order_3] new_dict = {'orders': []} new_dict['orders'].append(Order.to_dict(order_1))
from classes import Order, Good import filtration from datetime import datetime import random good_1 = Good('shovel', 'Germany', 50000, datetime(2013, 12, 11)) good_2 = Good('steel', 'Italy', 25000, datetime(2013, 8, 4)) good_3 = Good('snow', 'Russia', 5000, datetime(2012, 10, 12)) good_4 = Good('kola', 'Nigeria', 9000, datetime(2012, 12, 14)) good_5 = Good('ananases', "USA", 80000, datetime(2012, 11, 15)) good_6 = Good('coffee', "Africa", 75600, datetime(2011, 10, 24)) good_7 = Good('meat', "Mexico", 35200, datetime(2013, 9, 8)) good_8 = Good('bread', "Japan", 3200, datetime(2013, 10, 6)) good_9 = Good('bad', "UK", 76580, datetime(2013, 11, 10)) order_1 = Order("'Avangard'", 'USA', datetime(2013, 10, 24)) order_1.goods = [good_1, good_2, good_3] order_1.price_of_order = Order.total_price(order_1) order_2 = Order("'Azazaza'", 'RUS', datetime(2013, 11, 14)) order_2.goods = [good_4, good_5, good_6] order_2.price_of_order = Order.total_price(order_2) order_3 = Order("'Trust'", 'UK', datetime(2014, 2, 8)) order_3.goods = [good_7, good_8, good_9] order_3.price_of_order = Order.total_price(order_3) order_4 = Order("'Just'", 'URUR', datetime(2013, 2, 18)) order_4.goods = [good_2, good_5, good_8] order_4.price_of_order = Order.total_price(order_4)
def checkForHighTightFlagStrategy(tickers, item, orderQueue, ORDERS, size, price, time, currentInvested, DTBP, candleTime): conditionsForHighTightFlagMet = False #checks for 'high tight flag' strategy with 1 down bar if (tickers[item].isInSteepUptrend(1) == True and tickers[item].priceHistory[-2].volume < tickers[item].priceHistory[-3].volume and tickers[item].priceHistory[-2].high <= tickers[item].priceHistory[-3].closePrice + 0.04 and ((tickers[item].priceHistory[-2].high - tickers[item].priceHistory[-2].low) <= 0.8 * (tickers[item].priceHistory[-3].high - tickers[item].priceHistory[-3].low) or (tickers[item].priceHistory[-2].high - tickers[item].priceHistory[-2].low) <= 0.05) and tickers[item].priceHistory[-2].low >= tickers[item].priceHistory[-2].EMA5 - 0.02 and tickers[item].priceHistory[-2].closePrice <= tickers[item].priceHistory[-2].openPrice and tickers[item].priceHistory[-1].closePrice > tickers[item].priceHistory[-2].high and tickers[item].priceHistory[-1].closePrice > tickers[item].priceHistory[-3].closePrice and (tickers[item].priceHistory[-1].closePrice <= tickers[item].priceHistory[-3].closePrice + 0.08 or tickers[item].priceHistory[-1].closePrice <= tickers[item].priceHistory[-2].high + 0.08) and tickers[item].priceHistory[-1].closePrice >= (tickers[item].priceHistory[-1].low + (0.8 * (tickers[item].priceHistory[-1].high - tickers[item].priceHistory[-1].low))) and tickers[item].priceHistory[-3].closePrice >= (tickers[item].priceHistory[-3].low + (0.7 * (tickers[item].priceHistory[-3].high - tickers[item].priceHistory[-3].low))) and tickers[item].canTrade == True and tickers[item].havePosition == False): #[test] print(time + '\t' + 'high tight flag with 1 down bar in ' + item) #[test] conditionsForHighTightFlagMet = True if (item == 'M'): size = 1500 if (item == 'AMAT' or item == 'MU'): size = 800 if (item == 'C'): size = 1000 if (item == 'INTC'): size = 700 #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): #[test] print('DTBP not exceeded') #[test] orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : size, 'price' : price}}) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'high tight flag' tickers[item].breakoutBarLow = tickers[item].currentCandle.low #add order to list order = Order(item, candleTime, price, 'high tight flag', size, 'long') ORDERS.append(order) #checks for 'high tight flag' strategy with 2 down bars elif (tickers[item].isInSteepUptrend(2) == True and tickers[item].priceHistory[-3].volume < tickers[item].priceHistory[-4].volume and tickers[item].priceHistory[-3].high <= tickers[item].priceHistory[-4].closePrice + 0.04 and (tickers[item].priceHistory[-3].high - tickers[item].priceHistory[-3].low) <= 0.8 * (tickers[item].priceHistory[-4].high - tickers[item].priceHistory[-4].low) and tickers[item].priceHistory[-3].low >= tickers[item].priceHistory[-3].EMA5 - 0.02 and tickers[item].priceHistory[-2].volume < tickers[item].priceHistory[-4].volume and tickers[item].priceHistory[-2].volume < 2 * tickers[item].priceHistory[-3].volume and (tickers[item].priceHistory[-2].high - tickers[item].priceHistory[-2].low) <= 1.2 * (tickers[item].priceHistory[-3].high - tickers[item].priceHistory[-3].low) and tickers[item].priceHistory[-2].high <= tickers[item].priceHistory[-3].high and tickers[item].priceHistory[-2].high <= tickers[item].priceHistory[-4].high and tickers[item].priceHistory[-2].low >= tickers[item].priceHistory[-2].EMA5 - 0.03 and tickers[item].priceHistory[-2].closePrice < tickers[item].priceHistory[-2].openPrice and tickers[item].priceHistory[-3].closePrice < tickers[item].priceHistory[-3].openPrice and tickers[item].priceHistory[-1].closePrice > tickers[item].priceHistory[-2].high and tickers[item].priceHistory[-1].closePrice > tickers[item].priceHistory[-3].high and tickers[item].priceHistory[-1].closePrice > tickers[item].priceHistory[-4].closePrice and (tickers[item].priceHistory[-1].closePrice <= tickers[item].priceHistory[-4].closePrice + 0.07 or tickers[item].priceHistory[-1].closePrice <= tickers[item].priceHistory[-3].high + 0.07) and tickers[item].priceHistory[-1].closePrice >= (tickers[item].priceHistory[-1].low + (0.8 * (tickers[item].priceHistory[-1].high - tickers[item].priceHistory[-1].low))) and tickers[item].priceHistory[-4].closePrice >= (tickers[item].priceHistory[-4].low + (0.7 * (tickers[item].priceHistory[-4].high - tickers[item].priceHistory[-4].low))) and tickers[item].canTrade == True and tickers[item].havePosition == False): #[test] print(time + '\t' + 'high tight flag with 2 down bars in ' + item) #[test] conditionsForHighTightFlagMet = True if (item == 'M'): size = 1500 if (item == 'AMAT' or item == 'MU'): size = 800 if (item == 'C'): size = 1000 if (item == 'INTC'): size = 700 #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): #[test] print('DTBP not exceeded') #[test] orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : size, 'price' : price}}) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'high tight flag' tickers[item].breakoutBarLow = tickers[item].currentCandle.low #add order to list order = Order(item, candleTime, price, 'high tight flag', size, 'long') ORDERS.append(order) return conditionsForHighTightFlagMet
class MyTest(unittest.TestCase): item = Item() order = Order() def test_add(self): abc = Operations() actual_result = abc.add(5, 6) expected_result = 11 self.assertEqual(expected_result, actual_result) def test_check_even_no(self): op = Operations() actual_result = op.check_even_no(6) # expected_result = True # self.assertEqual(expected_result, actual_result) self.assertTrue(actual_result) def test_check_even_no(self): op = Operations() actual_result = op.check_even_no(5) self.assertFalse(actual_result) def test_add_item(self): result = self.item.add_item('test_item', 'test_type', 100) self.assertTrue(result) def test_add_item_view(self): result = self.item.add_item('', '', 100) self.assertFalse(result) def test_add_item_view(self): result = self.item.add_item('test', 'type', 'asd') self.assertFalse(result) def test_add_item_view(self): result = self.item.add_item('', '', -100) self.assertFalse(result) def test_show_items(self): data = self.item.show_item() actual_result = len(data) expected_result = 9 self.assertEqual(expected_result, actual_result) def test_search_item(self): data = self.item.search_item('momo') actual_result = len(data) expected_result = 2 self.assertEqual(expected_result, actual_result) def test_search_items1(self): data = self.item.search_item('noodle') actual_result = len(data) expected_result = 0 self.assertEqual(expected_result, actual_result) def test_order_items(self): listdata = [(1, 5)] data = self.order.add_order(5, listdata) self.assertTrue(data) def test_order_items(self): listdata = [(1, 5)] data = self.order.add_order("five", listdata) self.assertFalse(data) def test_order_items(self): listdata = [("", "")] data = self.order.add_order(5, listdata) self.assertFalse(data) def test_order_items(self): listdata = [(1, 5)] data = self.order.add_order("", listdata) self.assertFalse(data) def test_ordershow_items(self): data = self.order.show_orders_by_order_id(3) actual_result = len(data) expected_result = 3 self.assertEqual(expected_result, actual_result) def test_showallorder(self): data = self.order.show_all_orders() actual_result = len(data) expected_result = 44 self.assertEqual(expected_result, actual_result) def test_showallorder(self): data = self.order.show_all_orders() actual_result = len(data) expected_result = 42 self.assertNotEqual(expected_result, actual_result)
class OrderView: def __init__(self): self.window = Tk() self.window.title('Orders') self.window.geometry('503x500+0+0') self.item = Item() self.order = Order() self.all_items = self.item.show_item() self.ordered_item_list = [] self.label_item = Label(self.window, text='Item') self.label_item.grid(row=0, column=0) self.combo_item = ttk.Combobox(self.window, state='readonly', width=27) self.combo_item.grid(row=0, column=1) # self.combo_item['values'] = self.all_items self.label_qty = Label(self.window, text='Qty') self.label_qty.grid(row=1, column=0) self.entry_qty = Entry(self.window, width=30) self.entry_qty.grid(row=1, column=1) self.btn_add_item = Button(self.window, text='Add >>', command=self.on_add_item) self.btn_add_item.grid(row=2, column=0) self.label_tbl = Label(self.window, text='Table No.') self.label_tbl.grid(row=3, column=0) self.entry_tbl = Entry(self.window, width=30) self.entry_tbl.grid(row=3, column=1) self.btn_add_order = Button(self.window, text='Submit Order', command=self.on_submit_order) self.btn_add_order.grid(row=4, column=0) self.btn_reset = Button(self.window, text='Reset', command=self.on_reset) self.btn_reset.grid(row=4, column=1) self.combo_order = ttk.Combobox(self.window) self.combo_order.grid(row=5, column=0) self.btn_show_order = Button(self.window, text='Show Order', command=self.show_orders_in_tree) self.btn_show_order.grid(row=5, column=1) self.order_tree = ttk.Treeview(self.window, column=('tbl', 'name', 'type', 'price', 'qty')) self.order_tree.grid(row=6, column=0, columnspan=2) self.order_tree['show'] = 'headings' self.order_tree.column('tbl', width=100, anchor='center') self.order_tree.column('name', width=100, anchor='center') self.order_tree.column('type', width=100, anchor='center') self.order_tree.column('price', width=100, anchor='center') self.order_tree.column('qty', width=100, anchor='center') self.order_tree.heading('tbl', text='Table No.') self.order_tree.heading('name', text='Name') self.order_tree.heading('type', text='Type') self.order_tree.heading('price', text='Price') self.order_tree.heading('qty', text='Qty') self.btn_bill = Button(self.window, text='Generate Bill', command=self.generate_bill) self.btn_bill.grid(row=7, column=0) self.show_items_in_combo() self.show_orders_in_combo() self.window.mainloop() def show_items_in_combo(self): show_items = [] for i in self.all_items: show_items.append((i[1], i[2])) self.combo_item['values'] = show_items def on_add_item(self): # item_id = self.combo_item.get()[0] item_index = self.combo_item.current() # item_id = self.all_items[item_index][0] item = self.all_items[item_index] qty = self.entry_qty.get() self.ordered_item_list.append((item[0], qty)) self.order_tree.insert('', 'end', text='', value=('', item[1], item[2], item[3], qty)) def on_submit_order(self): if self.combo_order.get() == '': tbl = self.entry_tbl.get() if self.order.add_order(tbl, self.ordered_item_list): messagebox.showinfo('Order', 'Order added') self.show_orders_in_combo() else: messagebox.showerror('Error', 'Order can not added') else: order_id = self.combo_order.get() if self.order.add_order_to_prev_customer(self.ordered_item_list, order_id): messagebox.showinfo('Order', 'Order added') self.show_orders_in_combo() else: messagebox.showerror('Error', 'Order can not added') self.ordered_item_list.clear() def show_orders_in_combo(self): self.combo_order['values'] = self.order.show_all_orders() def show_orders_in_tree(self): order_id = self.combo_order.get() if order_id == '': messagebox.showerror('Error', 'Select Order number First') else: orders = self.order.show_orders_by_order_id(order_id) self.order_tree.delete(*self.order_tree.get_children()) for i in orders: self.order_tree.insert('', 'end', text='', value=i) def on_reset(self): self.combo_order.set('') self.entry_qty.delete(0, END) self.entry_tbl.delete(0, END) self.order_tree.delete(*self.order_tree.get_children()) self.ordered_item_list.clear() def generate_bill(self): if self.combo_order.get() == '': messagebox.showerror('Error', 'Select Order number First') else: orders = self.order_tree.get_children() if len(orders) == 0: messagebox.showerror('Error', 'Show order first') else: total = 0 bill_list = [] tbl_no = self.order_tree.item(orders[0], 'values')[0] for i in orders: order = self.order_tree.item(i, 'values') amt = float(order[3]) * float(order[4]) total += amt bill_list.append( (order[1], order[2], order[3], order[4], amt)) # tbl_no = order[0] BillView(bill_list, total, tbl_no)
def __init__(self): self.window = Tk() self.window.title('Orders') self.window.geometry('503x500+0+0') self.item = Item() self.order = Order() self.all_items = self.item.show_item() self.ordered_item_list = [] self.label_item = Label(self.window, text='Item') self.label_item.grid(row=0, column=0) self.combo_item = ttk.Combobox(self.window, state='readonly', width=27) self.combo_item.grid(row=0, column=1) # self.combo_item['values'] = self.all_items self.label_qty = Label(self.window, text='Qty') self.label_qty.grid(row=1, column=0) self.entry_qty = Entry(self.window, width=30) self.entry_qty.grid(row=1, column=1) self.btn_add_item = Button(self.window, text='Add >>', command=self.on_add_item) self.btn_add_item.grid(row=2, column=0) self.label_tbl = Label(self.window, text='Table No.') self.label_tbl.grid(row=3, column=0) self.entry_tbl = Entry(self.window, width=30) self.entry_tbl.grid(row=3, column=1) self.btn_add_order = Button(self.window, text='Submit Order', command=self.on_submit_order) self.btn_add_order.grid(row=4, column=0) self.btn_reset = Button(self.window, text='Reset', command=self.on_reset) self.btn_reset.grid(row=4, column=1) self.combo_order = ttk.Combobox(self.window) self.combo_order.grid(row=5, column=0) self.btn_show_order = Button(self.window, text='Show Order', command=self.show_orders_in_tree) self.btn_show_order.grid(row=5, column=1) self.order_tree = ttk.Treeview(self.window, column=('tbl', 'name', 'type', 'price', 'qty')) self.order_tree.grid(row=6, column=0, columnspan=2) self.order_tree['show'] = 'headings' self.order_tree.column('tbl', width=100, anchor='center') self.order_tree.column('name', width=100, anchor='center') self.order_tree.column('type', width=100, anchor='center') self.order_tree.column('price', width=100, anchor='center') self.order_tree.column('qty', width=100, anchor='center') self.order_tree.heading('tbl', text='Table No.') self.order_tree.heading('name', text='Name') self.order_tree.heading('type', text='Type') self.order_tree.heading('price', text='Price') self.order_tree.heading('qty', text='Qty') self.btn_bill = Button(self.window, text='Generate Bill', command=self.generate_bill) self.btn_bill.grid(row=7, column=0) self.show_items_in_combo() self.show_orders_in_combo() self.window.mainloop()
def checkForReversalStrategy(tickers, item, orderQueue, ORDERS, size, price, time, currentInvested, DTBP, candleTime): #checks for 'reversal' strategy without climactic volume if (tickers[item].numberOfBarsBelowEMAs >= 9 and tickers[item].currentCandle.openPrice < round(tickers[item].EMA5, 2) and tickers[item].currentCandle.closePrice > round(tickers[item].EMA5, 2) and tickers[item].trend == 'downtrend' and tickers[item].percentageOfDownBarsInDowntrend >= 50 and tickers[item].priceHistory[-2].closePrice < tickers[item].priceHistory[-2].openPrice and tickers[item].currentCandle.closePrice >= (0.75 * (tickers[item].currentCandle.high - tickers[item].currentCandle.low) + tickers[item].currentCandle.low) and tickers[item].canTrade == True and tickers[item].havePosition == False and tickers[item].currentCandle.closePrice >= tickers[item].priceHistory[-2].high - 0.01 and tickers[item].priceHistory[-2].openPrice <= tickers[item].priceHistory[-2].EMA5 + 0.02 and (tickers[item].priceHistory[-2].high - tickers[item].priceHistory[-2].openPrice) <= 0.4 * (tickers[item].priceHistory[-2].high - tickers[item].priceHistory[-2].low)): #[test] print(time + '\t' + 'reversal without climactic volume in' + item ) if (item == 'M'): size = 1500 if (item == 'AMAT' or item == 'MU'): size = 800 if (item == 'C'): size = 1000 if (item == 'INTC'): size = 700 #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): print('DTBP not exceeded') #[test] orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : size, 'price' : price}}) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'reversal' tickers[item].breakoutBarLow = tickers[item].currentCandle.low #add order to list order = Order(item, candleTime, price, 'reversal', size, 'long') ORDERS.append(order) #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): #[test] print('Using smaller size') #[test] smallerSize = DTBP - 1000 - currentInvested / price #[test] orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : smallerSize, 'price' : price}}) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'reversal' tickers[item].breakoutBarLow = tickers[item].currentCandle.low #add order to list order = Order(item, candleTime, price, 'reversal', smallerSize, 'long') ORDERS.append(order) #checks for 'reversal' strategy with several consecutive down bars elif (tickers[item].numberOfBarsBelowEMAs >= 9 and tickers[item].trend == 'downtrend' and tickers[item].percentageOfDownBarsInDowntrend >= 50 and tickers[item].numberOfConsecutiveBars >= 6 and tickers[item].currentCandle.closePrice >= (0.75 * (tickers[item].currentCandle.high - tickers[item].currentCandle.low) + tickers[item].currentCandle.low) and tickers[item].canTrade == True and tickers[item].havePosition == False and tickers[item].currentCandle.closePrice >= tickers[item].priceHistory[-2].high - 0.01 and tickers[item].priceHistory[-2].closePrice < tickers[item].priceHistory[-2].openPrice and tickers[item].priceHistory[-2].openPrice <= tickers[item].priceHistory[-2].EMA5 + 0.02 and (tickers[item].priceHistory[-2].high - tickers[item].priceHistory[-2].openPrice) <= 0.4 * (tickers[item].priceHistory[-2].high - tickers[item].priceHistory[-2].low)): #[test] print(time + '\t' + 'reversal with several consecutive down bars in' + item ) if (item == 'M'): size = 1500 if (item == 'AMAT' or item == 'MU'): size = 800 if (item == 'C'): size = 1000 if (item == 'INTC'): size = 700 #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): #[test] print('DTBP not exceeded') #[test] orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : size, 'price' : price}}) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'reversal' tickers[item].breakoutBarLow = tickers[item].currentCandle.low #add order to list order = Order(item, candleTime, price, 'reversal', size, 'long') ORDERS.append(order) #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): #[test] print('Using smaller size') #[test] smallerSize = DTBP - 1000 - currentInvested / price #[test] orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : smallerSize, 'price' : price}}) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'reversal' tickers[item].breakoutBarLow = tickers[item].currentCandle.low #add order to list order = Order(item, candleTime, price, 'reversal', smallerSize, 'long') ORDERS.append(order)
def dict_to_order(order): new_order = Order(order['name'], order['country'], order['delivery_time']) new_order.price_of_order = order['price'] new_order.goods = dict_to_good(order['goods']) return new_order
def checkForFlatTopBreakoutStrategy(tickers, item, orderQueue, ORDERS, size, price, time, currentInvested, DTBP, candleTime): #checks for 'flat top breakout' strategy if (tickers[item].sizeOfFlatTopBreakoutPattern >= 3 and tickers[item].withinFlatTopBreakoutPattern and tickers[item].currentCandle.closePrice > tickers[item].intervalUnderConsideration and tickers[item].currentCandle.closePrice < (tickers[item].intervalUnderConsideration + 0.1) and tickers[item].canTrade and not tickers[item].havePosition and tickers[item].currentCandle.closePrice >= (0.7 * (tickers[item].currentCandle.high - tickers[item].currentCandle.low) + tickers[item].currentCandle.low and tickers[item].currentCandle.openPrice <= tickers[item].intervalUnderConsideration) and tickers[item].currentCandle.openPrice <= tickers[item].intervalUnderConsideration): #[test] print(time + '\t' + 'flat top breakout in ' + item) #[test] #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): #[test] #orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : size, 'price' : price}}) #[test] #[test] #tickers[item].havePosition = True #[test] #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'flat top breakout' tickers[item].withinFlatTopBreakoutPattern = False tickers[item].closedBelow10EMA = False tickers[item].sizeOfFlatTopBreakoutPattern = 0 tickers[item].nextInterval = tickers[ item].intervalUnderConsideration + 0.25 tickers[item].stopLossInterval = 0 #add order to list order = Order(item, candleTime, price, 'flat top breakout', size, 'long') ORDERS.append(order) #[test] print('The next interval is: ' + str(tickers[item].nextInterval)) #[test] #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): #[test] print('Using smaller size') #[test] smallerSize = DTBP - 1000 - currentInvested / price #[test] #orderQueue.append({item : {'action' : 'BUY', 'symbol' : item, 'size' : smallerSize, 'price' : price}}) #[test] #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'flat top breakout' tickers[item].withinFlatTopBreakoutPattern = False tickers[item].closedBelow10EMA = False tickers[item].sizeOfFlatTopBreakoutPattern = 0 tickers[item].nextInterval = tickers[ item].intervalUnderConsideration + 0.25 tickers[item].stopLossInterval = 0 #add order to list order = Order(item, candleTime, price, 'flat top breakout', smallerSize, 'long') ORDERS.append(order) #[test] print('The next interval is: ' + str(tickers[item].nextInterval)) #[test] elif (tickers[item].withinFlatTopBreakoutPattern and tickers[item].currentCandle.high > tickers[item].intervalUnderConsideration): #[test] print("Flat top breakout in " + item + " no longer considered") #[test] tickers[item].withinFlatTopBreakoutPattern = False tickers[item].closedBelow10EMA = False tickers[item].sizeOfFlatTopBreakoutPattern = 0 tickers[item].nextInterval = 0 tickers[item].stopLossInterval = 0
def checkForOversoldReversalStrategy(tickers, item, orderQueue, ORDERS, size, price, time, currentInvested, DTBP, candleTime): #checks for 'oversold reversal' strategy if (determineOversold(tickers, item) and checkLowOfDay(tickers, item) and checkReversalBar(tickers, item) and tickers[item].trend == 'downtrend' and tickers[item].percentageOfDownBarsInDowntrend >= 50 and tickers[item].canTrade == True and tickers[item].havePosition == False): #[test] print(time + '\t' + 'oversold reversal in' + item) #[test] #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): print('DTBP not exceeded') #[test] orderQueue.append({ item: { 'action': 'BUY', 'symbol': item, 'size': size, 'price': price } }) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'oversold reversal' tickers[item].breakoutBarLow = tickers[item].priceHistory[-2].low #add order to list order = Order(item, candleTime, price, 'oversold reversal', size, 'long') ORDERS.append(order) return True #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): #[test] print('Using smaller size') #[test] smallerSize = DTBP - 1000 - currentInvested / price #[test] orderQueue.append({ item: { 'action': 'BUY', 'symbol': item, 'size': smallerSize, 'price': price } }) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'oversold reversal' tickers[item].breakoutBarLow = tickers[item].priceHistory[-2].low #add order to list order = Order(item, candleTime, price, 'oversold reversal', smallerSize, 'long') ORDERS.append(order) return True else: return False
def checkForEMAStrategy(tickers, item, orderQueue, ORDERS, size, price, time, currentInvested, DTBP, candleTime): conditionsForEMAStrategyMet = False #checks for 'break above 20EMA' strategy if (tickers[item].currentCandle.openPrice < round(tickers[item].EMA20, 2) and tickers[item].currentCandle.closePrice > round( tickers[item].EMA20, 2) and ((tickers[item].priceHistory[-1].volume > 1.7 * tickers[item].priceHistory[-2].volume and tickers[item].priceHistory[-1].volume < 3 * tickers[item].priceHistory[-2].volume) or tickers[item].priceHistory[-1].volume > 4 * tickers[item].priceHistory[-2].volume) and tickers[item].canUseEMAStrategy == True and tickers[item].havePosition == False and tickers[item].tradedEMAStrategy == False and tickers[item].isInSidewaysTrend == False and tickers[item].canTrade == True): #[test] print(time + '\t' + 'break above 20EMA in' + item) #[test] conditionsForEMAStrategyMet = True if (item == 'M'): size = 1500 if (item == 'AMAT' or item == 'MU'): size = 800 if (item == 'C'): size = 1000 if (item == 'INTC'): size = 700 #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): orderQueue.append({ item: { 'action': 'BUY', 'symbol': item, 'size': size, 'price': price } }) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'break above 20EMA' tickers[item].tradedEMAStrategy = True #add order to list order = Order(item, candleTime, price, 'break above 20EMA', size, 'long') ORDERS.append(order) #[test] print('DTBP not exceeded') #[test] #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): smallerSize = DTBP - 1000 - currentInvested / price orderQueue.append({ item: { 'action': 'BUY', 'symbol': item, 'size': smallerSize, 'price': price } }) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'break above 20EMA' tickers[item].tradedEMAStrategy = True #add order to list order = Order(item, candleTime, price, 'break above 20EMA', smallerSize, 'long') ORDERS.append(order) #[test] print('Using smaller position size') #[test] #checks for 'break below 20EMA' strategy elif (tickers[item].currentCandle.openPrice > round( tickers[item].EMA20, 2) and tickers[item].currentCandle.closePrice < round( tickers[item].EMA20, 2) and ((tickers[item].priceHistory[-1].volume > 1.7 * tickers[item].priceHistory[-2].volume and tickers[item].priceHistory[-1].volume < 3 * tickers[item].priceHistory[-2].volume) or tickers[item].priceHistory[-1].volume > 4 * tickers[item].priceHistory[-2].volume) and tickers[item].canUseEMAStrategy == True and tickers[item].havePosition == False and tickers[item].tradedEMAStrategy == False and tickers[item].isInSidewaysTrend == False and tickers[item].canTrade == True): #[test] print(time + '\t' + 'break below 20EMA in' + item) #[test] conditionsForEMAStrategyMet = True if (item == 'M'): size = 1500 if (item == 'AMAT' or item == 'MU'): size = 800 if (item == 'C'): size = 1000 if (item == 'INTC'): size = 700 #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): #[test] print('DTBP not exceeded') #[test] if (item not in data.HARD_TO_BORROW): orderQueue.append({ item: { 'action': 'SELL_SHORT', 'symbol': item, 'size': size, 'price': price } }) #update ticker info tickers[item].direction = "short" tickers[item].strategy = 'break below 20EMA' tickers[item].tradedEMAStrategy = True #add order to list order = Order(item, candleTime, price, 'break below 20EMA', size, 'short') ORDERS.append(order) #[test] print('stock can be shorted') #[test] #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): #[test] print('Using smaller position size') #[test] smallerSize = DTBP - 1000 - currentInvested / price if (item not in data.HARD_TO_BORROW): orderQueue.append({ item: { 'action': 'SELL_SHORT', 'symbol': item, 'size': smallerSize, 'price': price } }) #update ticker info tickers[item].direction = "short" tickers[item].strategy = 'bounce lower off 20EMA' tickers[item].tradedEMAStrategy = True #add order to list order = Order(item, candleTime, price, 'bounce lower off 20EMA', smallerSize, 'short') ORDERS.append(order) #[test] print('stock can be shorted') #[test] #checks for 'bounce lower off 20EMA' strategy elif (tickers[item].currentCandle.openPrice < round( tickers[item].EMA20, 2) and tickers[item].currentCandle.high == round( tickers[item].EMA20, 2) and ((tickers[item].priceHistory[-1].volume > 1.7 * tickers[item].priceHistory[-2].volume and tickers[item].priceHistory[-1].volume < 3 * tickers[item].priceHistory[-2].volume) or tickers[item].priceHistory[-1].volume > 4 * tickers[item].priceHistory[-2].volume) and tickers[item].currentCandle.closePrice < tickers[item].currentCandle.openPrice and tickers[item].canUseEMAStrategy == True and tickers[item].havePosition == False and tickers[item].tradedEMAStrategy == False and tickers[item].isInSidewaysTrend == False and tickers[item].canTrade == True): #[test] print(time + '\t' + 'bounce lower off 20EMA in' + item) #[test] conditionsForEMAStrategyMet = True if (item == 'M'): size = 1500 if (item == 'AMAT' or item == 'MU'): size = 800 if (item == 'C'): size = 1000 if (item == 'INTC'): size = 700 #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): #[test] print('DTBP not exceeded') #[test] if (item not in data.HARD_TO_BORROW): orderQueue.append({ item: { 'action': 'SELL_SHORT', 'symbol': item, 'size': size, 'price': price } }) #update ticker info tickers[item].direction = "short" tickers[item].strategy = 'bounce lower off 20EMA' tickers[item].tradedEMAStrategy = True #add order to list order = Order(item, candleTime, price, 'bounce lower off 20EMA', size, 'short') ORDERS.append(order) #[test] print('stock can be shorted') #[test] #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): #[test] print('Using smaller position size') #[test] smallerSize = DTBP - 1000 - currentInvested / price if (item not in data.HARD_TO_BORROW): orderQueue.append({ item: { 'action': 'SELL_SHORT', 'symbol': item, 'size': smallerSize, 'price': price } }) #update ticker info tickers[item].direction = "short" tickers[item].strategy = 'bounce lower off 20EMA' tickers[item].tradedEMAStrategy = True #add order to list order = Order(item, candleTime, price, 'bounce lower off 20EMA', smallerSize, 'short') ORDERS.append(order) #[test] print('stock can be shorted') #[test] #checks for 'bounce higher off 20EMA' strategy elif (tickers[item].currentCandle.openPrice > round( tickers[item].EMA20, 2) and tickers[item].currentCandle.low == round(tickers[item].EMA20, 2) and ((tickers[item].priceHistory[-1].volume > 1.7 * tickers[item].priceHistory[-2].volume and tickers[item].priceHistory[-1].volume < 3 * tickers[item].priceHistory[-2].volume) or tickers[item].priceHistory[-1].volume > 4 * tickers[item].priceHistory[-2].volume) and tickers[item].currentCandle.closePrice > tickers[item].currentCandle.openPrice and tickers[item].canUseEMAStrategy == True and tickers[item].havePosition == False and tickers[item].tradedEMAStrategy == False and tickers[item].isInSidewaysTrend == False and tickers[item].canTrade == True): #[test] print(time + '\t' + 'bounce higher off 20EMA in' + item) #[test] conditionsForEMAStrategyMet = True if (item == 'M'): size = 1500 if (item == 'AMAT' or item == 'MU'): size = 800 if (item == 'C'): size = 1000 if (item == 'INTC'): size = 700 #checks if DTBP is exceeded if (currentInvested + (price * size) < DTBP - 1000): #[test] print('DTBP not exceeded') #[test] orderQueue.append({ item: { 'action': 'BUY', 'symbol': item, 'size': size, 'price': price } }) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'bounce higher off 20EMA' tickers[item].tradedEMAStrategy = True #add order to list order = Order(item, candleTime, price, 'bounce higher off 20EMA', size, 'long') ORDERS.append(order) #use smaller position size if DTBP would otherwise be exceeded elif ((DTBP - 1000 - currentInvested) / price >= 300): smallerSize = DTBP - 1000 - currentInvested / price orderQueue.append({ item: { 'action': 'BUY', 'symbol': item, 'size': smallerSize, 'price': price } }) #update ticker info tickers[item].direction = "long" tickers[item].strategy = 'break above 20EMA' tickers[item].tradedEMAStrategy = True #add order to list order = Order(item, candleTime, price, 'break above 20EMA', smallerSize, 'long') ORDERS.append(order) #[test] print('Using smaller position size') #[test] return conditionsForEMAStrategyMet