Exemple #1
0
 def set_keys_exchange_file(self,keys_filename=standard_apikeys_file,exchanges=None):
     apikeys = parse_toml(keys_filename)
     self.logger.info("set keys %s"%apikeys.keys())
     if exchanges:
         for e in exchanges:
             #eid = exc.get_id(e)
             name = exc.NAMES[e]
             try:
                 self.set_keys_exchange(e, apikeys[name])
             except Exception as err:
                 self.logger.error("could not set %s"%err)
     else:            
         try:            
             if not self.active_exchanges:                
                 for k,v in apikeys.items():
                     eid = exc.get_id(k)
                     if eid >= 0:
                         try:
                             self.set_keys_exchange(eid, apikeys[k])
                             self.active_exchanges.append(eid)
                         except Exception as err:
                             self.logger.error("could not set %s"%err)
                     else:
                         self.logger.error ("exchange not supported or not set")
                 self.logger.info("active exchanges %s"%self.active_exchanges)
             else:
                 self.logger.error("active exchanages already set")
                 
         except Exception as err: 
             self.logger.error("error parsing apikeys file %s"%(err))
Exemple #2
0
    def set_keys_exchange_file(self,
                               keys_filename=standard_apikeys_file,
                               exchanges=None):
        wdir = self.get_workingdir()
        path_file_apikeys = wdir + "/" + keys_filename
        if not os.path.exists(path_file_apikeys):
            self.logger.error("no %s file. expected path %s" %
                              (keys_filename, str(path_file_apikeys)))
        apikeys = parse_toml(path_file_apikeys)
        self.logger.info("set keys %s" % apikeys.keys())
        if exchanges:
            for e in exchanges:
                #eid = exc.get_id(e)
                name = exc.NAMES[e]
                try:
                    self.set_keys_exchange(e, apikeys[name])
                except Exception as err:
                    self.logger.error("could not set %s" % err)
        else:
            try:
                for k, v in apikeys.items():
                    eid = exc.get_id(k)
                    if eid >= 0:
                        try:
                            self.set_keys_exchange(eid, apikeys[k])
                        except Exception as err:
                            self.logger.error("could not set %s" % err)
                    else:
                        self.logger.error("exchange not supported or not set")
                #self.logger.info("active exchanges %s"%self.active_exchanges)

            except Exception as err:
                self.logger.error("error parsing apikeys file %s" % (err))
Exemple #3
0
 def __old_cancel_order(self, oid): 
     self.logger.debug("cancel %s"%str(oid))
     #TODO check order exists             
     order = self.get_by_id(oid)
     #oid, otype=None,exchange=None,symbol=None):
     oid, otype,exchange, market = order['oid'],order['otype'],order['exchange'],order['market']
     exchange = exc.get_id(exchange)
     self.afacade.cancel_id(oid, otype, market, exchange)
Exemple #4
0
    def cancel(self, order):
        """ cancel by order """
        #if exchange is None: exchange=self.s_exchange
        e = order['exchange']
        exchange = exc.get_id(e)
        result = None
        oid = order['oid']
        market = order['market']
        otype = order['otype']       
        #self.logger.info("cancel " + str(order)) 
        self.logger.info("cancel " + str(oid) + " " + str(e) + " " + str(otype) + " " + str(market))
        
        client = self.clients[exchange]

        if exchange==exc.CRYPTOPIA:            
            result,err = client.cancel_trade_id(oid)
            
        elif exchange==exc.BITTREX:
            result = client.cancel(oid)
            self.logger.info("bitrex " + str(result))

        elif exchange==exc.KUCOIN:
            symbol = models.conv_markets_to(market, exchange)
            if otype == 'bid':                
                f = "BUY"
            else:
                f = "SELL"   
            self.logger.info("cancel ",symbol,oid,f)
            result = client.cancel_order(oid,f,symbol)      
            self.canceled_orders +=1
            return result                  
                        
        elif exchange==exc.HITBTC:
            result = client.cancel_order(oid)
            self.canceled_orders +=1

        elif exchange==exc.BINANCE:
            self.logger.error("not implemented. cancel by id")

        elif exchange==exc.BITMEX:
            result = client.cancel_order(oid)
        
                    
        self.logger.debug("result " + str(result))
        return result
Exemple #5
0
 def set_active_exchanges_name(self, exchanges_names):
     ne = list()
     for n in exchanges_names:
         eid = exc.get_id(n)
         ne.append(eid)
     self.active_exchanges = ne