def _get_gtt_payload(self, trigger_type, tradingsymbol, exchange, trigger_values, last_price, orders): """Get GTT payload""" if type(trigger_values) != list: raise ex.InputException("invalid type for `trigger_values`") if trigger_type == self.GTT_TYPE_SINGLE and len(trigger_values) != 1: raise ex.InputException( "invalid `trigger_values` for single leg order type") elif trigger_type == self.GTT_TYPE_OCO and len(trigger_values) != 2: raise ex.InputException( "invalid `trigger_values` for OCO order type") condition = { "exchange": exchange, "tradingsymbol": tradingsymbol, "trigger_values": trigger_values, "last_price": last_price, } gtt_orders = [] for o in orders: # Assert required keys inside gtt order. for req in [ "transaction_type", "quantity", "order_type", "product", "price" ]: if req not in o: raise ex.InputException( "`{req}` missing inside orders".format(req=req)) gtt_orders.append({ "exchange": exchange, "tradingsymbol": tradingsymbol, "transaction_type": o["transaction_type"], "quantity": int(o["quantity"]), "order_type": o["order_type"], "product": o["product"], "price": float(o["price"]), }) return condition, gtt_orders
def order_modify(self, order_id, parent_order_id=None, exchange=None, tradingsymbol=None, transaction_type=None, quantity=None, price=None, order_type=None, product=None, trigger_price=0, validity="DAY", disclosed_quantity=0, variety="regular"): """Modify an open order.""" params = locals() del (params["self"]) for k in params: if k is None: del (params[k]) if ((product.lower() == "bo" or product.lower() == "co") and variety.lower() != product.lower()): raise ex.InputException("Invalid variety. It should be: {}".format( product.lower())) # Check for variety by product or variety if variety.lower() == "bo" and product.lower() == "bo": return self._put( "orders.modify", { "order_id": order_id, "quantity": quantity, "price": price, "trigger_price": trigger_price, "disclosed_quantity": disclosed_quantity, "variety": variety, "parent_order_id": parent_order_id })["order_id"] elif variety.lower() == "co" and product.lower() == "co": return self._put( "orders.modify", { "order_id": order_id, "trigger_price": trigger_price, "variety": variety, "parent_order_id": parent_order_id })["order_id"] else: return self._put("orders.modify", params)["order_id"]