Ejemplo n.º 1
0
def sell_list(Req, Pair):              
        Current = None
        try:
            Current = TradePairs.objects.get(url_title = Pair)
        except :
            return json_false500(Req)
            
        SellList = Orders.objects.filter(status = "processing",
                                      currency1 = Current.currency_on,
                                      currency2 = Current.currency_from)
        getcontext().prec = 8
        Currency1Title = Current.currency_from.title
        Currency2Title = Current.currency_on.title
        AccumSellSum = 0
        GroupSellDict = {}
        for item in SellList :
             SellSum = item.sum1 ##LTC
             BuySum = item.sum2 ## UAH
             Rate = item.price
             AccumSellSum += SellSum
             if GroupSellDict.has_key(Rate) :
                GroupSellDict[Rate][Currency2Title] = GroupSellDict[Rate][Currency2Title] + SellSum
                GroupSellDict[Rate][Currency1Title] = GroupSellDict[Rate][Currency1Title] + BuySum
             else :
                GroupSellDict[Rate] = {Currency2Title: SellSum, Currency1Title: BuySum }
                
        ResSellList = [] 
        LL = GroupSellDict.keys()
        L = []
        for i in LL:
             Temp = Decimal(i)
             GroupSellDict[Temp] =  GroupSellDict[i]    
             L.append( Temp )   
             
        L.sort()
        
        Price  = 0
        MinPrice = 0
        for i in L:
                Price = format_numbers10(i)
                ResSellList.append( {"price":Price,
                                     "currency_trade":format_numbers10(GroupSellDict[i][Currency2Title]),
                                     "currency_base": format_numbers10(GroupSellDict[i][Currency1Title]) } )
                
        if len(ResSellList):
                MinPrice = ResSellList[0]["price"]    
    
        Dict = {"orders_sum":format_numbers10(AccumSellSum), 
                "list":ResSellList,
                "min_price": MinPrice, 
                "max_price": Price }
        RespJ = json.JSONEncoder().encode(Dict)
        
        return RespJ
Ejemplo n.º 2
0
def buy_list(Req, Pair):
        Current = None
        try:
            Current = TradePairs.objects.get(url_title = Pair)
        except :
            return json_false500(Req)
        
        
        
        BuyList =  Orders.objects.filter(status = "processing",
                                        currency1 = Current.currency_from,
                                        currency2 = Current.currency_on)
        getcontext().prec = settings.TRANS_PREC
        Currency1Title = Current.currency_from.title
        Currency2Title = Current.currency_on.title
        List1 = {}
        AccumBuySum = 0
        for item in BuyList : 
                SellSum = item.sum1 ## UAH
                BuySum = item.sum2  ## LTC
                Rate = item.price
                AccumBuySum += SellSum
                if List1.has_key(Rate) :
                        List1[Rate][Currency1Title] = List1[Rate][Currency1Title] + SellSum
                        List1[Rate][Currency2Title] = List1[Rate][Currency2Title] + BuySum
                else :
                        List1[Rate] = {Currency1Title: SellSum, Currency2Title: BuySum }
        
        ResBuyList = []
        
        LL = List1.keys()
        L = []
        for i in LL:
             Temp = Decimal(i)
             List1[Temp] =  List1[i]    
             L.append( Temp )   
             
        L.sort()
        L.reverse()
        
        Price  = 0
        MaxPrice  = 0
        for i in  L :
                Price = format_numbers10(i)
                ResBuyList.append( {"price":Price, 
                                    "currency_trade": format_numbers10(List1[i][Currency2Title]),
                                    "currency_base": format_numbers10(List1[i][Currency1Title]) } )    

        if len(ResBuyList):
                MaxPrice = ResBuyList[0]["price"]
        Dict = {"orders_sum":format_numbers10(AccumBuySum), "list":ResBuyList,
                 "max_price":MaxPrice, "min_price": Price }
        RespJ =  json.JSONEncoder().encode(Dict)
        return RespJ
Ejemplo n.º 3
0
def buy_list(Req, Pair):
        
        
        
        
        Current = TradePairs.objects.get(url_title = Pair)
        BuyList =  Orders.objects.filter(status = "processing",
                                        currency1 = Current.currency_from,
                                        currency2 = Current.currency_on)
        getcontext().prec = settings.TRANS_PREC
        Currency1Title = Current.currency_from.title
        Currency2Title = Current.currency_on.title
        List1 = {}
        AccumBuySum = 0
        for item in BuyList : 
                SellSum = item.sum1 ## UAH
                BuySum = item.sum2  ## LTC
                Rate = item.price
                AccumBuySum += SellSum
                if List1.has_key(Rate) :
                        List1[Rate][Currency1Title] = List1[Rate][Currency1Title] + SellSum
                        List1[Rate][Currency2Title] = List1[Rate][Currency2Title] + BuySum
                else :
                        List1[Rate] = {Currency1Title: SellSum, Currency2Title: BuySum }
        
        ResBuyList = []
        
        LL = List1.keys()
        L = []
        for i in LL:
             Temp = Decimal(i)
             List1[Temp] =  List1[i]    
             L.append( Temp )   
             
        L.sort()
        L.reverse()
        
        Price  = 0
        MaxPrice  = 0
        for i in  L :
                Price = format_numbers10(i)
                ResBuyList.append( {"price":Price, 
                                    "currency_trade": format_numbers10(List1[i][Currency2Title]),
                                    "currency_base": format_numbers10(List1[i][Currency1Title]) } )    

        if len(ResBuyList):
                MaxPrice = ResBuyList[0]["price"]
        Dict = {"orders_sum":format_numbers10(AccumBuySum), "list":ResBuyList,
                 "max_price":MaxPrice, "min_price": Price }
        RespJ =  json.JSONEncoder().encode(Dict)
        return RespJ
Ejemplo n.º 4
0
def sell_list(Req, Pair):              
       
        Current = TradePairs.objects.get(url_title = Pair)
        SellList = Orders.objects.filter(status = "processing",
                                      currency1 = Current.currency_on,
                                      currency2 = Current.currency_from)
        getcontext().prec = 8
        Currency1Title = Current.currency_from.title
        Currency2Title = Current.currency_on.title
        AccumSellSum = 0
        GroupSellDict = {}
        for item in SellList :
             SellSum = item.sum1 ##LTC
             BuySum = item.sum2 ## UAH
             Rate = item.price
             AccumSellSum += SellSum
             if GroupSellDict.has_key(Rate) :
                GroupSellDict[Rate][Currency2Title] = GroupSellDict[Rate][Currency2Title] + SellSum
                GroupSellDict[Rate][Currency1Title] = GroupSellDict[Rate][Currency1Title] + BuySum
             else :
                GroupSellDict[Rate] = {Currency2Title: SellSum, Currency1Title: BuySum }
                
        ResSellList = [] 
        LL = GroupSellDict.keys()
        L = []
        for i in LL:
             Temp = Decimal(i)
             GroupSellDict[Temp] =  GroupSellDict[i]    
             L.append( Temp )   
             
        L.sort()
        
        Price  = 0
        MinPrice = 0
        for i in L:
                Price = format_numbers10(i)
                ResSellList.append( {"price":Price,
                                     "currency_trade":format_numbers10(GroupSellDict[i][Currency2Title]),
                                     "currency_base": format_numbers10(GroupSellDict[i][Currency1Title]) } )
                
        if len(ResSellList):
                MinPrice = ResSellList[0]["price"]    
    
        Dict = {"orders_sum":format_numbers10(AccumSellSum), 
                "list":ResSellList,
                "min_price": MinPrice, 
                "max_price": Price }
        RespJ = json.JSONEncoder().encode(Dict)
        
        return RespJ
Ejemplo n.º 5
0
def balance(Req, User_id):
    List = []
    Dict = {}
    for i in Accounts.objects.filter(user_id=User_id):
        List.append({
            "balance": format_numbers10(i.balance),
            "currency": i.currency.title
        })

    User = Req.user
    Dict["notify_count"] = Msg.objects.filter(user_to=User,
                                              user_from_id=1,
                                              user_hide_to="false",
                                              user_seen_to="false").count()
    Dict["msg_count"] = Msg.objects.filter(
        user_to=User, user_hide_to="false",
        user_seen_to="false").exclude(user_from_id=1).count()
    try:
        online = OnlineUsers(user=Req.user)
        online.save()
    except:
        online = OnlineUsers.objects.get(user=Req.user)
        online.pub_date = datetime.datetime.now()
        online.save()

    if Req.session.has_key('use_f2a'):
        Dict["use_f2a"] = Req.session['use_f2a']
    else:
        Dict["use_f2a"] = False

    Dict["accounts"] = List
    RespJ = json.JSONEncoder().encode(Dict)
    return RespJ
Ejemplo n.º 6
0
def balance(Req, User_id):
            List = []
            Dict = {}
            for i in Accounts.objects.filter(user_id = User_id):
                List.append({"balance": format_numbers10(i.balance),"currency": i.currency.title })               
                
            User = Req.user        
            Dict["notify_count"] = Msg.objects.filter(user_to = User, 
                                                  user_from_id = 1,
                                                  user_hide_to = "false",
                                                  user_seen_to = "false" ).count()
            Dict["msg_count"] = Msg.objects.filter(user_to = User, 
                                                user_hide_to = "false",
                                                user_seen_to = "false" ).exclude(user_from_id = 1).count()
            try:
                online = OnlineUsers(user = Req.user )
                online.save()
            except :
                online = OnlineUsers.objects.get(user = Req.user )    
                online.pub_date = datetime.datetime.now()
                online.save()
            
            if Req.session.has_key('use_f2a'):
                Dict["use_f2a"]= Req.session['use_f2a'] 
            else:
                Dict["use_f2a"] = False     
            
            Dict["accounts"] = List
            RespJ = json.JSONEncoder().encode(Dict)
            return RespJ
Ejemplo n.º 7
0
def client_orders(Req, User_id, Title):
    Dict = {}

    Current = None
    try:
        Current = TradePairs.objects.get(url_title=Title)
    except:
        return json_false500(Req)

    Dict["auth"] = True
    MyOrders = Orders.objects.raw(
        "SELECT * FROM main_orders WHERE user_id=%i AND ( \
                                        (currency1_id=%i AND currency2_id=%i ) OR  \
                                        (currency2_id=%i AND currency1_id=%i )\
                                        ) AND status='processing' ORDER BY id DESC"
        % (
            User_id,
            Current.currency_from.id,
            Current.currency_on.id,
            Current.currency_from.id,
            Current.currency_on.id,
        ))

    MyOrdersList = []
    c = getcontext()
    c.prec = settings.TRANS_PREC

    for i in MyOrders:
        MyOrdersDict = {}
        MyOrdersDict["pub_date"] = formats.date_format(i.pub_date,
                                                       "DATETIME_FORMAT")
        MyOrdersDict["id"] = i.id
        MyOrdersDict["sum2"] = str(i.sum2)
        MyOrdersDict["sum1"] = str(i.sum1)

        if i.currency1 == Current.currency_on:
            MyOrdersDict["type"] = "sell"
            Number = i.sum2 / i.sum1
            MyOrdersDict["price"] = format_numbers10(i.price)
            MyOrdersDict["amnt_trade"] = format_numbers10(i.sum1)
            MyOrdersDict["amnt_base"] = format_numbers10(i.sum2)
        else:
            MyOrdersDict["type"] = "buy"
            Number = i.sum1 / i.sum2
            MyOrdersDict["price"] = format_numbers10(i.price)
            MyOrdersDict["amnt_base"] = format_numbers10(i.sum1)
            MyOrdersDict["amnt_trade"] = format_numbers10(i.sum2)
        MyOrdersList.append(MyOrdersDict)

    balance_sell = Accounts.objects.get(user_id=User_id,
                                        currency=Current.currency_on)
    balance_buy = Accounts.objects.get(user_id=User_id,
                                       currency=Current.currency_from)
    Dict["balance_buy"] = format_numbers_strong(balance_buy.balance)
    Dict["balance_sell"] = format_numbers_strong(balance_sell.balance)
    Dict["your_open_orders"] = MyOrdersList
    RespJ = json.JSONEncoder().encode(Dict)
    return RespJ
Ejemplo n.º 8
0
def client_orders(Req, User_id, Title ):
        Dict = {}
        
        Current = None
        try:
            Current = TradePairs.objects.get(url_title = Title)
        except :
            return json_false500(Req)
        
        
        Dict["auth"] = True     
        MyOrders = Orders.objects.raw("SELECT * FROM main_orders WHERE user_id=%i AND ( \
                                        (currency1_id=%i AND currency2_id=%i ) OR  \
                                        (currency2_id=%i AND currency1_id=%i )\
                                        ) AND status='processing' ORDER BY id DESC" %
                                        (User_id,
                                        Current.currency_from.id,
                                        Current.currency_on.id,
                                        Current.currency_from.id,
                                        Current.currency_on.id,
                                        )
                                        )
                                        
        MyOrdersList = []
        c = getcontext()
        c.prec = settings.TRANS_PREC
        
        for i in MyOrders:
                MyOrdersDict = {}
                MyOrdersDict["pub_date"] = formats.date_format(i.pub_date, "DATETIME_FORMAT")
                MyOrdersDict["id"] = i.id
                MyOrdersDict["sum2"] = str(i.sum2)
                MyOrdersDict["sum1"] = str(i.sum1)

                if i.currency1 == Current.currency_on :            
                        MyOrdersDict["type"] = "sell"
                        Number = i.sum2 / i.sum1
                        MyOrdersDict["price"] = format_numbers10(i.price)
                        MyOrdersDict["amnt_trade"] = format_numbers10(i.sum1)
                        MyOrdersDict["amnt_base"] = format_numbers10(i.sum2)
                else:
                        MyOrdersDict["type"] = "buy"
                        Number = i.sum1/ i.sum2
                        MyOrdersDict["price"] = format_numbers10(i.price)
                        MyOrdersDict["amnt_base"] = format_numbers10(i.sum1)
                        MyOrdersDict["amnt_trade"] = format_numbers10(i.sum2)
                MyOrdersList.append(MyOrdersDict)   
                
        balance_sell  =  Accounts.objects.get(user_id = User_id, currency =  Current.currency_on )        
        balance_buy  =  Accounts.objects.get(user_id = User_id, currency =  Current.currency_from )        
        Dict["balance_buy"] = format_numbers_strong(balance_buy.balance )
        Dict["balance_sell"] = format_numbers_strong(balance_sell.balance )
        Dict["your_open_orders"] = MyOrdersList
        RespJ = json.JSONEncoder().encode(Dict)
        return RespJ
Ejemplo n.º 9
0
def process_deal_item(item, Current):
    new_item = {}
    new_item["pub_date"] = formats.date_format(item["ts"], "DATETIME_FORMAT")
    if int(item["trans_owner_id"] != int(item["order_owner_id"])):

        rate = item["price"]
        if int(item["currency_id"]) == int(Current.currency_on.id):
            new_item["type"] = "buy"
            new_item["user"] = item["username"]
            new_item["price"] = format_numbers10(rate)
            new_item["amnt_base"] = format_numbers10(item["amnt"] * rate)
            new_item["amnt_trade"] = format_numbers10(item["amnt"])

        else:
            new_item["type"] = "sell"
            new_item["user"] = item["username"]
            new_item["price"] = format_numbers10(rate)
            new_item["amnt_base"] = format_numbers10(item["amnt"])
            new_item["amnt_trade"] = str(item["amnt"] / rate)

    else:
        rate = item["price"]
        if int(item["currency_id"]) == int(Current.currency_on.id):
            new_item["type"] = "buy"
            new_item["user"] = item["username"]
            new_item["price"] = format_numbers10(rate)
            new_item["amnt_base"] = format_numbers10(item["amnt"] / rate)
            new_item["amnt_trade"] = format_numbers10(item["amnt"])

        else:
            new_item["type"] = "sell"
            new_item["user"] = item["username"]
            new_item["price"] = format_numbers10(rate)
            new_item["amnt_base"] = format_numbers10(item["amnt"])
            new_item["amnt_trade"] = format_numbers10(item["amnt"] * rate)
    return new_item
Ejemplo n.º 10
0
def process_deal_item(item, Current):          
    new_item = {}
    new_item["pub_date"] = formats.date_format(item["ts"], "DATETIME_FORMAT") 
    if  int(item["trans_owner_id"] != int(item["order_owner_id"]) ):         
            
            
        rate = item["price"]
        if int(item["currency_id"]) == int(Current.currency_on.id) : 
                new_item["type"] = "buy"
                new_item["user"] = item["username"]
                new_item["price"] = format_numbers10(rate)
                new_item["amnt_base"] = format_numbers10(item["amnt"]*rate)
                new_item["amnt_trade"] = format_numbers10(item["amnt"])     
                        
        else :
                new_item["type"] = "sell"
                new_item["user"] = item["username"]
                new_item["price"] = format_numbers10(rate)
                new_item["amnt_base"] = format_numbers10(item["amnt"])
                new_item["amnt_trade"] = str(item["amnt"]/rate)
                
                
    else :
        rate = item["price"]
        if int(item["currency_id"]) == int(Current.currency_on.id) : 
                new_item["type"] = "buy"
                new_item["user"] = item["username"]
                new_item["price"] = format_numbers10(rate)
                new_item["amnt_base"] = format_numbers10(item["amnt"]/rate)
                new_item["amnt_trade"] = format_numbers10(item["amnt"])     
                        
        else :
                new_item["type"] = "sell"
                new_item["user"] = item["username"]
                new_item["price"] = format_numbers10(rate)
                new_item["amnt_base"] = format_numbers10(item["amnt"])
                new_item["amnt_trade"] = format_numbers10(item["amnt"]*rate)        
    return new_item    
Ejemplo n.º 11
0
def process_deal_item(item, Current):
    new_item = {}
    new_item['user_id'] = int(item["trans_owner_id"])
    if int(item["trans_owner_id"]) != int(item["order_owner_id"]):


        rate = item["price"]
        if int(item["currency_id"]) == int(Current.currency_on.id):
            new_item["type"] = "buy"
            new_item["user"] = item["username"]
            new_item["price"] = format_numbers10(rate)
            new_item["amnt_base"] = format_numbers10(item["amnt"] * rate)
            new_item["amnt_trade"] = format_numbers10(item["amnt"])

        else:
            new_item["type"] = "sell"
            new_item["user"] = item["username"]
            new_item["price"] = format_numbers10(rate)
            new_item["amnt_base"] = format_numbers10(item["amnt"])
            new_item["amnt_trade"] = str(item["amnt"] / rate)


    else:
        rate = item["price"]
        if int(item["currency_id"]) == int(Current.currency_on.id):
            new_item["type"] = "buy"
            new_item["user"] = item["username"]
            new_item["price"] = format_numbers10(rate)
            new_item["amnt_base"] = format_numbers10(item["amnt"] / rate)
            new_item["amnt_trade"] = format_numbers10(item["amnt"])

        else:
            new_item["type"] = "sell"
            new_item["user"] = item["username"]
            new_item["price"] = format_numbers10(rate)
            new_item["amnt_base"] = format_numbers10(item["amnt"])
            new_item["amnt_trade"] = format_numbers10(item["amnt"] * rate)

    return DealsMemory(type_deal=new_item["type"],
                       user=new_item["user"],
                       amnt_base=new_item["amnt_base"],
                       amnt_trade=new_item["amnt_trade"],
                       price=new_item["price"],
                       pub_date=item["ts"],
                       trade_pair=Current.id,
                       user_id=new_item['user_id']
    )