SHARE
TWEET

Untitled

a guest Sep 20th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     async def exchange_open_orders(self):
  2.         open_orders = {}
  3.         retorno = {}
  4.         dados = []
  5.         active = []
  6.         target = []
  7.         stop = []
  8.         all_data = []
  9.         executa = True
  10.  
  11.         while executa:
  12.             try:
  13.                 open_orders = await self.exchange.fetch_open_orders()
  14.                 executa = False
  15.             except Exception as error:
  16.                 if await self.trata_erro_exchange(error=error, name=sys._getframe().f_code.co_name):
  17.                     break
  18.             except:
  19.                 print('Error exception on', sys._getframe().f_code.co_name, sys.exc_info()[0], sys.exc_info()[1])
  20.                 break
  21.  
  22.         if open_orders:
  23.             for x in open_orders:
  24.                 dados.append(x['info'])
  25.  
  26.             df = pd.DataFrame(data=dados)
  27.             df = df.sort_values(['symbol'], ascending=True)
  28.  
  29.             for index, x in df.iterrows():
  30.  
  31.                 text = x['text']
  32.  
  33.                 if len(text.split('\n')) > 1:
  34.                     text = text.split('\n')[1]
  35.  
  36.  
  37.                 if x['ordType'] not in ('StopLimit', 'stop_loss') and not x['execInst']:
  38.                     all_data.append({'symbol': x['symbol'], 'side': x['side'], 'price': x['price'], 'qty': x['orderQty'], 'type_order': 'active', 'id_telegram': self.dados_user['id_telegram'], 'id_account': self.dados_user['id'], 'exchange': self.dados_user['exchange'], 'obs':text, 'order_id':x['orderID']})
  39.                 elif x['execInst'] == 'Close' and x['ordType'] not in ('StopLimit', 'stop_loss', 'Stop'):
  40.                     all_data.append({'symbol': x['symbol'], 'side': x['side'], 'price': x['price'], 'qty': x['orderQty'], 'type_order': 'target', 'id_telegram': self.dados_user['id_telegram'], 'id_account': self.dados_user['id'], 'exchange': self.dados_user['exchange'], 'obs':text, 'order_id':x['orderID']})
  41.                 elif x['ordType'] in ('StopLimit', 'stop_loss', 'Stop'):
  42.                     all_data.append({'symbol': x['symbol'], 'side': x['side'], 'price': x['stopPx'], 'qty': x['orderQty'], 'type_order': 'stop', 'id_telegram': self.dados_user['id_telegram'], 'id_account': self.dados_user['id'], 'exchange': self.dados_user['exchange'], 'obs':text, 'order_id':x['orderID']})
  43.  
  44.             retorno = {'active': active, 'target': target, 'stop': stop}
  45.  
  46.  
  47.         return {'dados_user':self.dados_user, 'retorno': all_data, 'error':executa}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top