def get_position(self, summary: bool = True, trimempty: bool = True): """ Get current position for SYMBOL. - summary(True), if False show all """ position = self.bto.position(self.symbol) if summary: keys = [ "account", "symbol", "currency", "underlying", "quoteCurrency", "commission", "initMarginReq", "maintMarginReq", "riskLimit", "leverage", "prevRealisedPnl", "prevClosePrice", "openingTimestamp", "currentTimestamp", "timestamp", "avgEntryPrice", "lastPrice", "currentCost", "currentQty", "liquidationPrice", "breakEvenPrice", ] return {k: position[k] for k in keys} else: return trim_dic(position) if trimempty else position
def get_openO(self, full=False): """Return open orders.""" if full: self.openO = DataFrame( [trim_dic(o) for o in self.bto.open_orders()]) else: self.openO = DataFrame( [self.get_Os(o) for o in self.bto.open_orders()]) return self.openO
def get_execO(self, full=False): """Return exec orders.""" if full: data = [trim_dic(o) for o in self.bto.open_orders()] self.execO = DataFrame(data) else: self.execO = DataFrame( [self.get_Os(o) for o in self.bto.exec_orders()]) return self.execO
def placeM(self, side: sideT, qty=None, trim_: bool = True, **opts) -> None: """Place side at market.""" _qty = qty if qty else self.qty reply = place_at_market(self.brg, _qty, side, **opts) oPlace = [trim_dic(o) for o in reply][0] if trim_ else reply self.Ods[f'{oPlace["orderID"]}'] = oPlace return None
def placeS(self, side: sideT, offset, qty=None, trim_: bool = True, **opts) -> None: """Place stop at side with offset.""" _qty = qty if qty else self.qty opts["execInst"] = opts.get("execInst", self.priceType) reply = place_stop(self.brg, side, _qty, self.brg.prices(self.priceType) + offset, **opts) self.OplaceS = [trim_dic(o) for o in reply] if trim_ else reply return None
def placeMIT(self, side: sideT, stopoffset, qty=None, trim_: bool = True, **opts): """Place stop at side with offset.""" _qty = qty if qty else self.qty offsetStop = self.set_offset(side, stopoffset, offsettype="Limit") stopPx = self.brg.prices(self.priceType) + offsetStop opts["execInst"] = opts.get("execInst", self.priceType) reply = place_MIT(self.brg, side, _qty, stopPx, **opts) self.OplaceMIT = [trim_dic(o) for o in reply] if trim_ else reply return self.OplaceMIT
def placeL(self, side: sideT, offset_=None, qty=None, trim_: bool = True, **opts) -> None: """Place Limite on side with offset.""" _qty = qty if qty else self.qty _offset = self.set_offset(side, offset_, offsettype="Limit") _price = self.brg.prices(self.priceType) + _offset self.logger.info( f"place signature: {self.brg, side, _qty, _price, opts}") reply = place(self.brg, side, _qty, price=_price, **opts) oPlace = [trim_dic(o) for o in reply][0] if trim_ else reply self.Ods[f'{oPlace["orderID"]}'] = oPlace return None