Exemplo n.º 1
0
string PgsqlDataProvider::prepareProcessTradesQuery(const TradeList& tradeList)
{
  ostringstream query;
  query << "SELECT process_trades((ARRAY[";

  if (tradeList.size() != 0)  
  {
    ConstTradeIterator iterator = tradeList.begin();
    ConstTradeIterator endIterator = tradeList.end();

    query << format(*iterator);
    iterator++;

    while (iterator != endIterator)
    {
      query << ", " << format(*iterator);
      iterator++;
    }
  }

  query << "])::t_trade[]);";

  if (verbose)
    cout << "Query: " << query.str() << endl;
  return query.str();
}
Exemplo n.º 2
0
void checkExpiry ( TradeList &BuyListAll, TradeList &SellListAll ){
    

    cout << "Checking expiry once " << endl;
    TradeList::iterator buy,sell;
    ScripList::iterator b1,s1;
    ScripList blist, slist;
    
    time_t CT;
    time(&CT);
    string CurrentTime = Current_Time(&CT);
    
    for ( sell = SellListAll.begin() ; sell != SellListAll.end() ; sell++ ){
        slist = sell->second;
        for ( s1 = slist.begin(); s1 != slist.end() ; s1++ ){
            if ( !isAlive ( (*s1).expiry, CurrentTime ) ){
                //print to file  
                PrintScrip(*s1); 
                (sell->second).erase(s1);
                cout << "Erasing a record once since it is consumed" << endl;
            }
        }
    }
     

    for ( buy = BuyListAll.begin() ; buy != BuyListAll.end() ; buy++ ){
        blist = buy->second;
        for ( b1 = blist.begin(); b1 != blist.end() ; b1++ ){
            if ( !isAlive ( (*b1).expiry, CurrentTime ) ){
                //print to file
                PrintScrip(*b1); 
                (buy->second).erase(b1);
                cout << "Erasing a record once since it is consumed" << endl;
            }
        }
    }

}
Exemplo n.º 3
0
void doTransaction ( TradeList &BuyListAll, TradeList &SellListAll ){

    TradeList::iterator buy,sell;
    bool tradeflag = true;
    
    for ( sell = SellListAll.begin() ; sell != SellListAll.end() ; sell++ ){
        buy = BuyListAll.find(sell->first);

        if ( buy != BuyListAll.end() ){ // there is a buyer

            ScripList blist = buy->second;
            ScripList slist = sell->second;
            ScripList::iterator b1,s1;
            s1 = slist.begin();//check the first sale item

                for ( b1 = blist.begin(); b1 != blist.end() && tradeflag ; b1++ ){//check the buyer list entirely
                    if ( (*b1).rate > (*s1).rate ){

                        if ( (*b1).num >= (*s1).num ){//all sold
                            // *************print to file*************** //
                            PrintScrip(*s1); 
                            PrintScrip(*b1); 
                            (*b1).num -= (*s1).num;
                            (sell->second).erase(s1);
                            if ( (*b1).num == 0 )
                                (buy->second).erase(b1);
                            tradeflag = false;
                            }
                        if ( (*b1).num < (*s1).num ){//partially sold
                            // *************print to file*************** //
                            PrintScrip(*s1); 
                            PrintScrip(*b1); 
                            (*s1).num -= (*b1).num;
                            (buy->second).erase(b1);
                        }
                    }
                }
                
        }
    }
}