Пример #1
0
def whole_balance(request):
    CurList = Currency.objects.all()

    CurrencyConsist = []

    cursor = connection.cursor()
    #<td> {{ item.currency }}</td>
    #<td>{{ item.balance_in }} </td>
    #<td> {{ item.balance_out }}</td>
    #<td> {{ item.balance_orders }}</td>
    #<td> {{ item.balance_acc }}</td>
    #<td>{{ item.balance_corr }}</td>
    #<td> {{ item.consist }} </td>
    #<td> {{ item.delta }} </td>
    fields = ('balance_out', 'balance_corr')

    for cur in CurList:
        item = {'currency': cur.title}
        for field in fields:
            Name_Field = field + "_" + cur.title
            obj = None
            try:
                obj = VolatileConsts.objects.get(Name=Name_Field)
            except VolatileConsts.DoesNotExist:
                obj = VolatileConsts(Name=Name_Field, Value="0.0")
                obj.save()
            item[field] = obj.Value

        item['balance_orders'] = OrdersMem.objects.filter(
            status="processing",
            currency1=cur.id).aggregate(orders_sum=Sum('sum1'))["orders_sum"]
        if item['balance_orders'] is None:
            item['balance_orders'] = Decimal("0.0")
        item['balance_acc'] = get_acc_in(cur)

        item['balance_out_in'] = Accounts.objects.filter(
            currency=cur,
            balance__lte=0).aggregate(acc_sum=Sum('balance'))["acc_sum"]

        item['balance_in'] = (item['balance_orders'] + item['balance_acc'])

        item['consist'] = item['balance_in'] + item['balance_out_in']
        item['delta'] = Decimal(item['balance_out']) + Decimal(
            item["balance_corr"]) - item['balance_in']
        CurrencyConsist.append(item)

    return render_to_response('admin/main/whole_balance.html',
                              {'balance': CurrencyConsist},
                              context_instance=RequestContext(request))
Пример #2
0
def process_in_crypto(CurrencyTitle):
    List = None
    crypto_acc = "trade_stock"
    if CurrencyTitle in ("ZEC"):
        crypto_acc = ""
    Crypton = CryptoAccount(CurrencyTitle, crypto_acc)
    print "process %s" % CurrencyTitle
    TimeLastBlock = None
    TopBlock = int(Crypton.getblockcount())
    print "top block %i" % TopBlock
    try:
        TimeLastBlock = VolatileConsts.objects.get(
            Name="last_process_block_%s" % CurrencyTitle)
        TimeLastBlock.Value = int(TimeLastBlock.Value)

    except VolatileConsts.DoesNotExist:
        count = TopBlock - 100
        TimeLastBlock = VolatileConsts(Name="last_process_block_%s" %
                                       CurrencyTitle,
                                       Value=str(count))
        TimeLastBlock.save()

    Time = int(TimeLastBlock.Value)
    print "start process block %i " % Time

    user_system = User.objects.get(id=1)
    CurrencyInstance = Currency.objects.get(title=CurrencyTitle)
    getcontext().prec = crypton.settings.TRANS_PREC
    block_hash = Crypton.getblockhash(Time - 200)
    print "block %s" % block_hash
    List = Crypton.listsinceblock(block_hash)
    List = List["transactions"]
    process_in_crypto_low(List, user_system, CurrencyInstance)
    TimeLastBlock.Value = str(TopBlock)
    TimeLastBlock.save()
Пример #3
0
 def handle(self, *args, **options):
     print "top prices"
     print "============================================="
     cursor = connection.cursor()
     for item in  TradePairs.objects.filter(status = "processing"):
             Query =  cursor.execute("SELECT  min(main_orders.price) as top_price \n\
                                         FROM  main_orders, main_tradepairs\n\
                                         WHERE main_orders.status='processing'\n\
                                         AND main_orders.trade_pair_id = %i \n\
                                         AND  main_tradepairs.id = %i \n\
                                         AND main_orders.currency1_id =  main_tradepairs.currency_on_id \n\
                                         \n\
                                         " % ( item.id, item.id ))
             List = dictfetchall(cursor, Query)
             CurrentName  = item.url_title + "_top_price"
             CurrentPrice = None
             try :
                     CurrentPrice  = VolatileConsts.objects.get(Name = CurrentName)
             except :
                     CurrentPrice  = VolatileConsts(Name = CurrentName, 
                                                     Value = "None" )
                     CurrentPrice.save()
                     
             if List[0]["top_price"] is not None and List[0]["top_price"]>0:
                     top_price = List[0]["top_price"] 
                     print top_price
                     
                     if top_price>=0.1:
                             CurrentPrice.Value =  format_numbers(top_price)
                             
                     if top_price<0.1 and top_price > 0.001:
                             CurrentPrice.Value =  format_numbers(top_price)        
                             
                     if top_price<0.00001 :
                             CurrentPrice.Value =  format_numbers10(top_price)        
                     print " to "
                     print CurrentPrice.Value
                     
                     CurrentPrice.save()
             else:
                     CurrentPrice.Value = "No deals" 
                     CurrentPrice.save()
Пример #4
0
def lock_global(Desc):
    lock = VolatileConsts(Name="global_lock", Value=Desc)
    lock.save(using="security")
Пример #5
0
def lock_user(User):
    lock = VolatileConsts(Name="user_lock", Value=User.username)
    lock.save(using="security")
Пример #6
0
def save_var(name, value):
    var = VolatileConsts(Name=name, Value=value)
    var.save(using="security")
Пример #7
0
def lock_global(Desc):
    lock = VolatileConsts(Name="global_lock", Value=Desc)
    lock.save(using="security")
Пример #8
0
def approve_trans(obj):
    approve = VolatileConsts(Name="approve_trans", Value=str(obj.id))
    approve.save(using="security")