Пример #1
0
//sorts by price
void Sort::sort_by_price()
{
	if(route->get_next())
	{
		//same as above, only with price
		RouteList *old_head, *new_head, *cur_node, *max_node;
		double cur_max, temp_price;
		old_head = route;
		new_head = route;
		while(old_head)
		{
			RouteListManipulator rlm;
			cur_node = old_head;
			max_node = old_head;
			cur_max = get_price(cur_node->get_current()->get_flights(), bags);
			while(cur_node)
			{
				temp_price = get_price(cur_node->get_current()->get_flights(), bags);
				if(temp_price > cur_max)
				{
					cur_max = temp_price;
					max_node = cur_node;
				}
				cur_node = cur_node->get_next();
			}
			if(max_node == old_head)
			{
				old_head = old_head->get_next();
			}
			rlm.set_to_head(new_head, max_node);
			new_head = max_node;
		}
		route = new_head;
	}
}
Пример #2
0
      bool get_next_bid()
      { try {
         if( _current_bid && _current_bid->get_quantity().amount > 0 )
            return _current_bid.valid();

         ++_orders_filled;
         _current_bid.reset();

         if( _bid_itr.valid() )
         {
            auto bid = market_order( bid_order, _bid_itr.key(), _bid_itr.value() );
            if( bid.get_price().quote_asset_id == _quote_id &&
                bid.get_price().base_asset_id == _base_id )
            {
                if( bid.get_price() < _market_stat.center_price && get_next_short() )
                {
                   return _current_bid.valid();
                }

                _current_bid = bid;
                --_bid_itr;
                return _current_bid.valid();
            }
         }
         get_next_short();
         return _current_bid.valid();
      } FC_CAPTURE_AND_RETHROW() }
Пример #3
0
asset market_order::get_quote_quantity( const price& relative )const
{
  switch( order_type_enum( type ) )
  {
     case relative_bid_order:
     case bid_order:
     { // balance is in USD  divide by price
        return get_balance();
     }
     case relative_ask_order:
     case ask_order:
     { // balance is in USD  divide by price
        return get_balance() * get_price(relative);
     }
     case short_order:
     {
        return get_balance() * get_price(relative);
     }
     case cover_order:
     {
        return get_balance();
     }
     default:
        FC_ASSERT( false, "Not Implemented" );
  }
  // NEVER GET HERE.....
 // return get_balance() * get_price();
}
Пример #4
0
asset market_order::get_quantity( const price& relative )const
{
  switch( order_type_enum( type ) )
  {
     case relative_bid_order:
     case bid_order:
     { // balance is in USD  divide by price
        return get_balance() * get_price(relative);
     }
     case relative_ask_order:
     case ask_order:
     { // balance is in USD  divide by price
        return get_balance();
     }
     case short_order:
     {
        return get_balance();
     }
     case cover_order:
     {
        return asset( (*collateral * BTS_BLOCKCHAIN_MCALL_D2C_NUMERATOR) / BTS_BLOCKCHAIN_MCALL_D2C_DENOMINATOR );
     }
     default:
        FC_ASSERT( false, "Not Implemented" );
  }
  // NEVER GET HERE.....
  //return get_balance() * get_price();
}
Пример #5
0
bool CCandleBar::get_ma(size_t date_index, int periods, int type, double& data)
{
	std::lock_guard<std::mutex> lck(*mutex_);

	if (date_index < 0 || date_index >= candles_.size() || periods <= 0 || periods > date_index + 1)
	{
		return false;
	}
	
	int		k_count = 0;
	double	ma_data = 0;

	for (size_t i = date_index; i >= 0; --i)
	{
		ma_data += get_price(i, type);
		k_count++;
		if (periods == k_count)
		{
			data = ma_data / periods;
			return true;
		}
	}

	return false;
}
Пример #6
0
//sorts by price
bool Sort::sort_by_price(int num_hops)
{
	bool any_change = false;
	if(num_hops == route->get_current()->get_num_flights())
	{
		any_change = true;
	}
	if(route->get_next())
	{
		//same as above, only with price
		RouteList *old_head, *new_head, *cur_node, *max_node;
		double cur_max, temp_price;
		old_head = route;
		new_head = route;
		while(old_head)
		{
			RouteListManipulator rlm;
			cur_node = old_head;
			max_node = old_head;
			cur_max = get_price(cur_node->get_current()->get_flights(), bags);
			while(cur_node)
			{
				temp_price = get_price(cur_node->get_current()->get_flights(), bags);
				if(temp_price >= cur_max && num_hops == cur_node->get_current()->get_num_flights())
				{
					cur_max = temp_price;
					max_node = cur_node;
					any_change = true;
				}
				cur_node = cur_node->get_next();
			}
			if(!any_change)
			{
				return any_change;
			}
			if(max_node == old_head)
			{
				old_head = old_head->get_next();
			}
			rlm.set_to_head(new_head, max_node);
			new_head = max_node;
		}
		route = new_head;
	}
	return any_change;
}
Пример #7
0
//-------------PRINT MEDICATION----------------
void toString(Repo* self){
    int len = vector_getLen(self->arr);
    for (int i=0; i<len; i++){
        Medication m = vector_getAt(self->arr, i);
        printf("Name: %s | Concentration: %.2f | Quantity: %d | Price: %.2f \n",
           get_name(&m),
           get_concentration(&m),
           get_quantity(&m),
           get_price(&m)
           );
    }
}
                  bool get_next_bid()
                  { try {
                     if( _current_bid && _current_bid->get_quantity().amount > 0 )
                        return _current_bid.valid();

                     _current_bid.reset();
                     if( _bid_itr.valid() )
                     {
                        auto bid = market_order( bid_order, _bid_itr.key(), _bid_itr.value() );
                        if( bid.get_price().quote_asset_id == _quote_id &&
                            bid.get_price().base_asset_id == _base_id )
                        {
                            _current_bid = bid;
                        }
                     }

                     if( _short_itr.valid() )
                     {
                        auto bid = market_order( short_order, _short_itr.key(), _short_itr.value() );
                        wlog( "SHORT ITER VALID: ${o}", ("o",bid) );
                        if( bid.get_price().quote_asset_id == _quote_id &&
                            bid.get_price().base_asset_id == _base_id )
                        {
                            if( !_current_bid || _current_bid->get_price() < bid.get_price() )
                            {
                               --_short_itr;
                               _current_bid = bid;
                               ilog( "returning ${v}", ("v",_current_bid.valid() ) );
                               return _current_bid.valid();
                            }
                        }
                     }
                     else
                     {
                        wlog( "           No Shorts         ****   " );
                     }
                     if( _bid_itr.valid() ) --_bid_itr;
                     return _current_bid.valid();
                  } FC_CAPTURE_AND_RETHROW() }
Пример #9
0
 bool get_next_short()
 {
    if( _short_itr.valid() )
    {
       auto bid = market_order( short_order, _short_itr.key(), _short_itr.value() );
       if( bid.get_price().quote_asset_id == _quote_id &&
           bid.get_price().base_asset_id == _base_id )
       {
           ++_short_itr;
           _current_bid = bid;
           return _current_bid.valid();
       }
    }
    return false;
 }
Пример #10
0
bool StockTransactions::sell(Stocks symbol, MMTransactions& mm, int shares, int shares_owned)
{
	if (shares > get_sharesOwned())
	{
		return false;
	}
	else
	{
		set_price(symbol.get_currentPrice() * shares);
		set_shares(get_sharesOwned() - shares);
		mm.deposit(get_price());
		m_transactionType = transactionType::SALE;
		return true;
	}
}
Пример #11
0
int main( int, char** ) {
    std::ifstream input_file( "../file_io/file.txt" );

    if( input_file.is_open() ) {
        std::string input_line;
        while( getline( input_file, input_line) ) {
            std::vector< std::string > strings;

            std::split( input_line, ' ', strings );
            std::cout << "Price: " << get_price( input_line ) << " "
                      << "Barcode: " << get_barcode( input_line ) << std::endl;
        }

        input_file.close();
    }

    return 0;
}
Пример #12
0
void Route::print_route(int num_bags)
{
	FlightNodeTracker *fl = flight_list;
	cout << "Flight Number\tCompany\t\tSource Location\tDeparture Date/Time" << endl;
	while(fl)
	{
		Date_Time *temp;
		//prints the flight number
		cout << fl->get_flight()->get_flight_num() << "\t\t";
		//prints flight company
		cout << fl->get_flight()->get_flight_comp() << "\t";
		if(strlen(fl->get_flight()->get_flight_comp()) < 8)
		{
			cout <<"\t";
		}
		//prints the source hub's name
		cout << fl->get_flight()->get_source()->get_short_name() << "\t\t";
		//prints the departure time
		cout << fl->get_flight()->get_departure()->get_time() << endl;
		//prints the destination hub's name
		cout << "\t\t\t\t" << fl->get_flight()->get_destination()->get_short_name() << "\t\t";
		//prints the arrival time (without adjusting for time-zones)
		temp = fl->get_flight()->get_departure()->copy();
		temp->add_min(fl->get_flight()->get_duration());

		cout << temp->get_time() << endl;
		//print pricing details
		cout << "\t\t\t\t$" << (fl->get_flight()->get_price() + fl->get_flight()->getBaggageFees(num_bags)) << "\t\t";
		cout << "Base Price: $" << fl->get_flight()->get_price() << endl;

		delete temp;
		//advances the tracker
		fl = fl->get_next();
	}
	cout << "Number of Bags: " << num_bags << endl;
	//prints the price and time
	cout << "Total Price: $" << get_price(num_bags) << endl;
	cout << "Total Time: " << get_time() << " minutes." << endl;
}
Пример #13
0
int main ( int argc, char* argv ) {
  int N = 0;
  int K = 0;
  int M = 0;
  table* price_character_table = NULL;
  char * s = NULL;
  int s_l = 0;
  int lines = 0;
  int amount_cents = 0;
  float amount_dollar = 0;
  int i, j;

  while ( scanf("%d\n",&N) == 1 ) {
    amount_cents = 0;
    scanf("%d\n",&K);
    price_character_table = (table *) malloc ( ( sizeof ( int ) + sizeof ( char ) ) * K );
    i = 0;
    if ( price_character_table ) 
      while ( i < K && scanf("%c %d\n", &price_character_table[i].character, &price_character_table[i].price) )
        i++;
    scanf("%d\n", &lines);
    for ( i = 0 ; i < lines ; i++ ) {
      s = (char *) malloc ( sizeof (char) * 10000 );
      if ( scanf("%[^\n]\n",s) == 1 ) {
        s_l = strlen(s);
        for ( j = 0 ; j < s_l ; j++ )
          amount_cents += get_price(s[j],price_character_table,K);
      }
    }
    amount_dollar = amount_cents;
    amount_dollar /= 100;
    printf("%.2f$\n",amount_dollar);
  }

  return 0;
}
Пример #14
0
double CCandleBar::get_safe_price(size_t date_index, int type)
{
	std::lock_guard<std::mutex> lck(*mutex_);

	return get_price(date_index, type);
}
Пример #15
0
FlightUSAirway *FlightUSAirway::clone()
{
	FlightUSAirway *new_flight = new FlightUSAirway(get_flight_num(), get_price(), get_duration(), get_departure()->copy(), get_source(), get_destination());
	return new_flight;
}
Пример #16
0
FlightSoutWest *FlightSoutWest::clone()
{
	FlightSoutWest *new_flight = new FlightSoutWest(get_flight_num(), get_price(), get_duration(), get_departure()->copy(), get_source(), get_destination());
	return new_flight;
}
                  bool get_next_ask()
                  { try {
                     if( _current_ask && _current_ask->state.balance > 0 )
                     {
                        wlog( "current ask" );
                        return _current_ask.valid();
                     }
                     _current_ask.reset();

                     /**
                      *  Margin calls take priority over all other ask orders
                      */
                     while( _current_bid && _collateral_itr.valid() )
                     {
                        auto cover_ask = market_order( cover_order,
                                                 _collateral_itr.key(),
                                                 order_record(_collateral_itr.value().payoff_balance),
                                                 _collateral_itr.value().collateral_balance  );

                        if( cover_ask.get_price().quote_asset_id == _quote_id &&
                            cover_ask.get_price().base_asset_id == _base_id )
                        {
                            if( _current_bid->get_price() < cover_ask.get_highest_cover_price()  )
                            {
                               // cover position has been blown out, current bid is not able to
                               // cover the position, so it will sit until the price recovers
                               // enough to fill it.
                               //
                               // The idea here is that the longs have agreed to a maximum
                               // protection equal to the collateral.  If they would like to
                               // sell their USD for XTS this is the best price the short is
                               // obligated to offer.
                               FC_CAPTURE_AND_THROW( insufficient_collateral, (_current_bid)(cover_ask)(cover_ask.get_highest_cover_price()));
                               --_collateral_itr;
                               continue;
                            }
                            // max bid must be greater than call price
                            if( _current_bid->get_price() < cover_ask.get_price() )
                            {
                             //  if( _current_ask->get_price() > cover_ask.get_price() )
                               {
                                  _current_ask = cover_ask;
                                  _current_payoff_balance = _collateral_itr.value().payoff_balance;
                                  --_collateral_itr;
                                  return _current_ask.valid();
                               }
                            }
                        }
                        break;
                     }

                     if( _ask_itr.valid() )
                     {
                        auto ask = market_order( ask_order, _ask_itr.key(), _ask_itr.value() );
                        wlog( "ASK ITER VALID: ${o}", ("o",ask) );
                        if( ask.get_price().quote_asset_id == _quote_id &&
                            ask.get_price().base_asset_id == _base_id )
                        {
                            _current_ask = ask;
                        }
                        ++_ask_itr;
                        return true;
                     }
                     return _current_ask.valid();
                  } FC_CAPTURE_AND_RETHROW() }
Пример #18
0
FlightDelta *FlightDelta::clone()
{
	FlightDelta *new_flight = new FlightDelta(get_flight_num(), get_price(), get_duration(), get_departure()->copy(), get_source(), get_destination());
	return new_flight;
}
Пример #19
0
int main(void) {
  set_weight(100);
  set_price(1.25);
  std::cout << "Weight: " << get_weight() << ", Price: " << get_price() << std::endl;
  return 0;
}