Ejemplo n.º 1
0
    def handle(self, *args, **options):

        Crypton = CryptoAccount("BTC", "trade_stock")
        with open("/home/bogdan/crypton/my_accounts.csv") as f:
            L = f.readlines()
            Sum = 0
            Dict = {}
            for address in L:
                addresses = address.replace("\n", "")

                Res = addresses.split(",")
                print "%s,%s,%s" % ( Res[0], Crypton.dumpprivkey(Res[0]), Res[1] )
                if Dict.has_key(Res[0]):
                    print "repeated "
                    continue
                else:
                    Dict[Res[0]] = 1

                try:
                    Bal = Balances.objects.get(account=Res[0])
                    Bal.balance = sato2Dec(Res[1])
                    Bal.save()
                except:

                    Bal = Balances(account=Res[0], currency_id=2)
                    Bal.balance = sato2Dec(Res[1])
                    Bal.save()
Ejemplo n.º 2
0
 def handle(self, *args, **options):
     CurrencyTitle = args[0]    
     Crypton = CryptoAccount(CurrencyTitle, "trade_stock")
     CurrencyInstance = Currency.objects.get(title = CurrencyTitle)
     getcontext().prec = crypton.settings.TRANS_PREC
     BalanceDictionary = {}
     
     for item in Accounts.objects.filter(currency = CurrencyInstance) :
          if item.reference is not None and  item.reference!="":
             print "process account "     
             print item.reference
             try :
                     item = Balances.objects.get(account = item.reference)   
                     
                     BalanceDictionary[item.account] = Decimal("0.0")
             except:
                     NewBalance = Balances(account = item.reference, balance = Decimal("0.0"), currency = CurrencyInstance)   
                     NewBalance.save()
                     BalanceDictionary[NewBalance.account] = Decimal("0.0")
                     
     for item in Balances.objects.filter(currency = CurrencyInstance) :
           BalanceDictionary[item.account] = Decimal("0.0")         
     
     
     List = Crypton.listunspent()
     for trans in List :
            
             Address = trans["address"]
             Amount = Decimal(trans["amount"])
             print " unspent inputs in %s of %s " % (Address, Amount)
             if BalanceDictionary.has_key(Address) :
                     PreBalance = BalanceDictionary[Address]
                     BalanceDictionary[Address] = PreBalance +  Amount
             else: 
                     BalanceDictionary[Address] = Amount
                     NewBalance = Balances(account = Address, balance = Decimal("0.0"), currency = CurrencyInstance)   
                     NewBalance.save()
     WholeSum = Decimal("0.0")                
     for trans in Balances.objects.filter(currency = CurrencyInstance) :              
         trans.balance = BalanceDictionary[trans.account]
         WholeSum = WholeSum + trans.balance
         trans.save()
         
     try :
                     item = Balances.objects.get(account = "whole", currency = CurrencyInstance)   
                     item.balance = WholeSum
                     item.save()
     except:
                     NewBalance = Balances(account = "whole", currency = CurrencyInstance, balance = WholeSum )   
                     NewBalance.save()