def order(self, id, long, qty, limit=0, stop=0, post_only=False, reduce_only=False, allow_amend=True, when=True): """ places an order, works as equivalent to tradingview pine script implementation https://www.tradingview.com/pine-script-reference/#fun_strategy{dot}order :param id: Order id :param long: Long or Short :param qty: Quantity :param limit: Limit price :param stop: Stop limit :param post_only: Post only :param reduce only: Reduce Only means that your existing position cannot be increased only reduced by this order by this order :param allow_amend: Allow amening existing orders :param when: Do you want to execute the order or not - True for live trading :return: """ self.__init_client() if self.get_margin()['excessMargin'] <= 0 or qty <= 0: return if not when: return side = "Buy" if long else "Sell" ord_qty = qty if allow_amend: order = self.get_open_order(id) ord_id = id + ord_suffix() if order is None else order["clOrdID"] if order is None: self.__new_order(ord_id, side, ord_qty, limit, stop, post_only, reduce_only) else: self.__amend_order(ord_id, side, ord_qty, limit, stop, post_only) else: ord_id = id + ord_suffix() self.__new_order(ord_id, side, ord_qty, limit, stop, post_only, reduce_only)
def order(self, id, long, qty, limit=0, stop=0, when=True): """ 注文をする。pineの関数と同等の機能。 https://jp.tradingview.com/study-script-reference/#fun_strategy{dot}order :param id: 注文の番号 :param long: ロング or ショート :param qty: 注文量 :param limit: 指値 :param stop: ストップ指値 :param when: 注文するか :return: """ self.__init_client() if self.get_margin()['excessMargin'] <= 0 or qty <= 0: return if not when: return side = "Buy" if long else "Sell" ord_qty = qty order = self.get_open_order(id) ord_id = id + ord_suffix() if order is None else order["clOrdID"] if order is None: self.__new_order(ord_id, side, ord_qty, limit, stop) else: self.__amend_order(ord_id, side, ord_qty, limit, stop)
def order(self, id, long, qty, limit=0, stop=0, post_only=False, reduce_only=False, trailing_stop=0, activationPrice=0, when=True): """ places an order, works as equivalent to tradingview pine script implementation https://www.tradingview.com/pine-script-reference/#fun_strategy{dot}order :param id: Order id :param long: Long or Short :param qty: Quantity :param limit: Limit price :param stop: Stop limit :param post_only: Post only :param reduce_only: Reduce Only means that your existing position cannot be increased only reduced by this order :param trailing_stop: Binance futures built in implementation of trailing stop in % :param activationPrice: price that triggers Binance futures built in trailing stop :param when: Do you want to execute the order or not - True for live trading :return: """ self.__init_client() # if self.get_margin()['excessMargin'] <= 0 or qty <= 0: # return if not when: return side = "BUY" if long else "SELL" ord_qty = qty order = self.get_open_order(id) ord_id = id + ord_suffix( ) #if order is None else order["clientOrderId"] if order is None: self.__new_order(ord_id, side, ord_qty, limit, stop, post_only, reduce_only, trailing_stop, activationPrice) else: self.__new_order(ord_id, side, ord_qty, limit, stop, post_only, reduce_only, trailing_stop, activationPrice) #self.__amend_order(ord_id, side, ord_qty, limit, stop, post_only) return
def order(self, id, long, qty, limit=0, stop=0, post_only=False, when=True): """ 주문함수. pine언어와 동등 https://kr.tradingview.com/study-script-reference/#fun_strategy{dot}order :param id: 주문번호 :param long: 롱 or 숏 :param qty: 주문수량 :param limit: 제시가 :param stop: 스탑제시가 :param post_only: post only 옵션 :param when: 주문조건 :return: """ self.__init_client() if self.get_margin()['excessMargin'] <= 0 or qty <= 0: return if not when: return side = "Buy" if long else "Sell" ord_qty = qty order = self.get_open_order(id) ord_id = id + ord_suffix() if order is None else order["clOrdID"] if order is None: self.__new_order(ord_id, side, ord_qty, limit, stop, post_only) else: self.__amend_order(ord_id, side, ord_qty, limit, stop, post_only)
def test_order_suffix(self): suffix = ord_suffix() print(suffix) assert len(suffix) > 0