int TestAllFunctions()
{
	DEBUG_METHOD();

	int returnVal = 0;
	// TODO It would be useful to produce output to the console to show which functions 'passed' and which 'failed' so that we can look at their output in the future.
	returnVal += CMap_test();
	std::cout << '\n';
	DistanceMatrixTest();
	std::cout << '\n';
	returnVal += CGraph_test();
	std::cout << '\n';
	returnVal += CGraph_test2();
	std::cout << '\n';
	returnVal += CGraph_test3();
	std::cout << '\n';
	returnVal += CParseCSV_test();
	std::cout << '\n';
	CParseCSV_test2();
	std::cout << '\n';
	//CBlockReader_test();                // Will fail without images in the Data/SpotImageExamples folder
	//std::cout << '\n';
	//returnVal += CBlockReader_test2();  // Will fail without images in the Data/SpotImageExamples folder
	//std::cout << '\n';
	//returnVal += CMazeMapper_test();
	//std::cout << '\n';



	return returnVal;
}
Esempio n. 2
0
  /**
   * Request from fornt end to modify params
   */
  void TestContext::onCMDModifyStrategy(API2::AbstractUserParams* newParams)
  {
    DEBUG_METHOD(reqQryDebugLog());
    _modify = true;
    API2::UserParams* modParams = (API2::UserParams*) newParams;

    /**
     * setting new params in a new data structure of params
     */
    if(!setModifiedInternalParameters(modParams))
    {
      DEBUG_MESSAGE(reqQryDebugLog(),"Front End Parameters Failed");
      terminateStrategyComment(API2::CONSTANTS::RSP_StrategyComment_STRATEGY_VERSION_DIFFERS);
      return;
    }

    /**
     * If no order pending , we can modifyStartegy
     */
    if(_modify && !isAnyOrderPending())
      modifyStrategy();

    /** need to send this response to front end that strategy has successfully recieved modify command
    */
    reqSendStrategyResponse(API2::CONSTANTS::RSP_ResponseType_STRATEGY_RUNNING,
        API2::CONSTANTS::RSP_RiskStatus_SUCCESS,
        API2::CONSTANTS::RSP_StrategyComment_USER_INPUT);
  }
Esempio n. 3
0
 /**
  * Request from front end to terminate strategy
  */
 void TestContext::onCMDTerminateStartegy()
 {
   DEBUG_METHOD(reqQryDebugLog());
   _terminate = true;
   if(_terminate && !isAnyOrderPending())
     terminateStrategy();
   return;
 }
Esempio n. 4
0
  void TestContext::mapFrontEndValues(){
    DEBUG_METHOD(reqQryDebugLog());
    /**
     * Copying the modifiedParams structure to original structure
     */
    _userParams._buyOrderLots = _modUserParams._buyOrderLots;
    _userParams._sellOrderLots = _modUserParams._sellOrderLots;
    _userParams._buyTotalLots = _modUserParams._buyTotalLots;
    _userParams._sellTotalLots = _modUserParams._sellTotalLots;
    _userParams._buyPrice = _modUserParams._buyPrice;
    _userParams._sellPrice = _modUserParams._sellPrice;
    _userParams._maxDiff = _modUserParams._maxDiff;

  }
Esempio n. 5
0
  void TestContext::setOrderWrapper()
  {
    /*
     * Creating instances of OrderWrapper here , to place or cancel orders through this instance
     */
    DEBUG_METHOD(reqQryDebugLog());
    API2::AccountDetail account;

    _buyOrderWrapper = API2::COMMON::OrderWrapper(
        _biddingInstrument,
        _buyOrder,
        this,
        account
        );

    _sellOrderWrapper = API2::COMMON::OrderWrapper(
        _biddingInstrument,
        _sellOrder,
        this,
        account
        );
  }
Esempio n. 6
0
  void TestContext::registerSymbols()
  {
    /*
     * Creating Instrument for Leg
     */
    DEBUG_METHOD(reqQryDebugLog());

    if((GET_EXCHANGE_ID(_userParams._symbolIdBidding) != API2::CONSTANTS::CMD_ExchangeId_NSECM ) &&
        (GET_EXCHANGE_ID(_userParams._symbolIdBidding) != API2::CONSTANTS::CMD_ExchangeId_NSEFO ) &&
        ( GET_EXCHANGE_ID(_userParams._symbolIdBidding)!= API2::CONSTANTS::CMD_ExchangeId_NSECDS))

      _biddingInstrument = createNewInstrument(_userParams._symbolIdBidding,true,true,false); 

    else
    {
      /** 
       * If Snapshot feed required for this instrument , pass third argument as true
       * false in case of TBT
       */
      _biddingInstrument = createNewInstrument(_userParams._symbolIdBidding,true,!_isTbtEnabled);
    }
  }
Esempio n. 7
0
int main()
{
	{
		SECTION("orderedarray: simple insertion");
		mystl::orderedarray<int> a1;
		size_t ind;

		// insert a végére
		a1.insert(2);
		a1.insert(6);
		a1.insert(10);

		// insert az elejére
		a1.insert(-5);
		a1.insert(-10);
        
		// dupla insert
		a1.insert(2);
		a1.insert(8);
		a1.insert(6);

		// dupla insert az elejére
		a1.insert(-10);
		a1.insert(-10);
		a1.insert(9);
		a1.insert(-10);
        
		// dupla insert a végére
		a1.insert(30);
		a1.insert(15);
		a1.insert(30);
		a1.insert(30);
        
		// copy konstruktor
		mystl::orderedarray<int> a2 = a1;
		a2.insert(17);

		// operator =
		mystl::orderedarray<int> a3;

		a3 = a2;
		a3.insert(-1);

		std::cout << "a1: " << a1 << "\na2: " << a2 << "\na3: " << a3 << "\n";

		// keresés
		SECTION("orderedarray: find");
		{
			DEBUG_METHOD(ind = a2.find(2));

			if( ind == mystl::orderedarray<int>::npos )
				std::cout << "nincs benne a 2\n";
			else
			{
				const mystl::orderedarray<int>& a4 = a2;
				std::cout << "a2[a2.find(2)] == " << a4[ind] << "\n";
			}

			DEBUG_METHOD(ind = a2.find(-10));

			if( ind == mystl::orderedarray<int>::npos )
				std::cout << "nincs benne a -10\n";
			else
				std::cout << "benne van a -10\n";

			DEBUG_METHOD(ind = a2.find(30));

			if( ind == mystl::orderedarray<int>::npos )
				std::cout << "nincs benne a 30\n";
			else
				std::cout << "benne van a 30\n";
		}

		// törlés
		SECTION("orderedarray: erase");
		{
			std::cout << "erase(8)\n";
			a2.erase(8);

			DEBUG_METHOD(ind = a2.find(8));

			if( ind == mystl::orderedarray<int>::npos )
				std::cout << "nincs benne a 8\n";
			else
				std::cout << "benne van a 8\n";

			DEBUG_METHOD(a2.erase(-10));
			DEBUG_METHOD(a2.erase(30));
			DEBUG_METHOD(a2.erase(30));

			std::cout << "a2: " << a2 << "\n";
		}

		// clear
		SECTION("orderedarray: erase");
		{
			DEBUG_METHOD(a2.clear());
			std::cout << "\na2.size() == " << a2.size() << "\n";

			DEBUG_METHOD(ind = a2.find(30));

			if( ind == mystl::orderedarray<int>::npos )
				std::cout << "nincs benne a 30\n";
			else
				std::cout << "benne van a 30\n";

			a2.erase(10);
		}
	}

	{
		SECTION("list: simple insertion");

		mystl::list<int> l1;

		l1.push_back(10);
		l1.push_back(5);
		l1.push_back(1);
		l1.push_back(-7);
		l1.push_back(8);

		ASSERT(l1.front() == 10);
		ASSERT(l1.back() == 8);

		write("l1", l1);

		DEBUG_METHOD(l1.clear());
		write("l1", l1);

		SECTION("list: insert at front");

		l1.push_front(10);
		l1.push_front(3);
		l1.push_back(5);
		l1.push_front(6);
		l1.push_back(-1);

		write("l1", l1);

		SECTION("list: resize & copy");

		DEBUG_METHOD(l1.resize(10, 25));
		write("l1", l1);

		DEBUG_METHOD(mystl::list<int> l2(l1));
		mystl::list<int> l3;

		l3.push_back(34);
		l3.push_back(11);

		ASSERT(l2.front() == l1.front());
		ASSERT(l2.back() == l1.back());
		ASSERT(l3.back() == 11);

		DEBUG_METHOD(l2.push_front(2));
		DEBUG_METHOD(l3 = l1);

		write("l2", l2);
		write("l3", l3);

		SECTION("list: random insertion");
		{
			DEBUG_METHOD(l2.insert(l2.begin(), 55));
			DEBUG_METHOD(l2.insert(l2.end(), 44));

			ASSERT(l2.front() == 55);
			ASSERT(l2.back() == 44);

			write("l2", l2);

			mystl::list<int>::iterator it = l2.begin();

			for( int i = 0; i < 4; ++i )
				++it;

			std::cout << "*it == " << *it << "\n";

			DEBUG_METHOD(l2.insert(it, 3));
			DEBUG_METHOD(l2.insert(it, 5));
			DEBUG_METHOD(l2.insert(it, 1));

			write("l2", l2);
		}

		SECTION("list: iterators");
		{
			mystl::list<int>::iterator it1, it2;

			it1 = l1.begin();
			it2 = l2.end();

			DEBUG_METHOD(it1 == it2);
			DEBUG_METHOD(it1 != it2);
			DEBUG_METHOD(*it2);
			DEBUG_METHOD(++it2);
			DEBUG_METHOD(it2++);
			DEBUG_METHOD(--it1);
			DEBUG_METHOD(it1--);
		}

		SECTION("list: erase & remove");
		{
			write("l2", l2);

			DEBUG_METHOD(l2.erase(l2.begin()));
			DEBUG_METHOD(l2.erase(l2.end()));

			write("l2", l2);

			mystl::list<int>::iterator it = l2.begin();

			for( int i = 0; i < 4; ++i )
				++it;

			std::cout << "*it == " << *it << "\n";

			DEBUG_METHOD(l2.erase(it));
			DEBUG_METHOD(l2.erase(it));

			write("l2", l2);

			DEBUG_METHOD(l2.remove(25));
			write("l2", l2);
		}
	}

	{
		SECTION("list: types");

		class Apple
		{
		private:
			int i;

		public:
			Apple() {
				i = 0;
			}

			Apple(int j) {
				i = j;
			}

			void foo() {
				std::cout << "Apple::foo(): i == " << i << "\n";
			}
		};
        
		typedef mystl::list<Apple> applelist;
		typedef mystl::list<Apple*> appleptrlist;

		applelist apples;
		appleptrlist appleptrs;

		apples.push_back(6);
		apples.push_back(10);
		apples.push_front(-4);
		apples.push_back(5);

		appleptrs.push_back(new Apple(20));
		appleptrs.push_back(new Apple(1));
		appleptrs.push_front(new Apple(-4));
		appleptrs.push_back(new Apple(-3));
		appleptrs.push_front(new Apple(6));

		std::cout << "apples:\n";

		for( applelist::iterator it = apples.begin(); it != apples.end(); ++it )
			it->foo();

		std::cout << "\nappleptrs:\n";

		for( appleptrlist::iterator it = appleptrs.begin(); it != appleptrs.end(); ++it )
		{
			(*it)->foo();
			delete (*it);
		}
	}

	std::cout << "\n";
	_CrtDumpMemoryLeaks();

	system("pause");
	return 0;
}
Esempio n. 8
0
void CGoodsIn::GetRawCompassData()
{
	DEBUG_METHOD();
}
Esempio n. 9
0
//what is this even for?!
void CGoodsIn::GetRawSensorData()
{
	DEBUG_METHOD();
}
Esempio n. 10
0
//Is any of this relevant?
void CGoodsIn::GetJunctionType()
{
	DEBUG_METHOD();
}
Esempio n. 11
0
//////////////////////////////////////////////////////////////////////////////////////////
// To signal a part of the challenge has been completed. Number 3
void CSignals::Notification3()
{
	DEBUG_METHOD();
}
Esempio n. 12
0
//////////////////////////////////////////////////////////////////////////////////////////
// To signal an error.
void CSignals::Error()
{
	DEBUG_METHOD();
}
Esempio n. 13
0
//////////////////////////////////////////////////////////////////////////////////////////
// To signal the challenge is completed.
void CSignals::Complete()
{
	DEBUG_METHOD();
}
Esempio n. 14
0
//////////////////////////////////////////////////////////////////////////////////////////
// To signal the start of something.
void CSignals::Start()
{
	DEBUG_METHOD();
}
Esempio n. 15
0
 /**
  * Map the modified front end params to front end params
  */
 void TestContext::modifyStrategy(){
   DEBUG_METHOD(reqQryDebugLog());
   _modify = false;
   mapFrontEndValues();
   dump();
 }
Esempio n. 16
0
  /**
   * Places Orders
   */
  void TestContext::placeOrder(const API2::DATA_TYPES::OrderMode &orderMode)
  {
    DEBUG_METHOD(reqQryDebugLog());

    /**
     * If strategy has been requested for termination or modification,
     * need to return from here
     */
    if(_terminate || _modify)
      return;
    /**
     * If any order is pending
     * we need to return from here
     */
    if(isAnyOrderPending())
      return;
    /**
     * Buy Case
     */
    if(orderMode == API2::CONSTANTS::CMD_OrderMode_BUY)
    {
      API2::DATA_TYPES::QTY qty = std::min(_userParams._buyOrderLots,_userParams._buyTotalLots - _buyTotalTradedLots);
      API2::DATA_TYPES::PRICE price = _userParams._buyPrice;

      // price in terms of tick size
      // e.g if price is 200.07
      // converting it to 200.05
      price = price - (price % _buyOrderWrapper._instrument->getStaticData()->tickSize);

      qty *= _biddingInstrument->getStaticData()->marketLot;

      if( qty != 0 )
      qty += _buyOrderWrapper.getLastFilledQuantity();

      if(qty <= 0 || price <= 0)
      {
        placeCancelOrder( _buyOrderWrapper );
        return;
      }
      /**
       * getLastQuantity() returns the last quantity of which order was placed
       *
       * getLastQuotedPrice() returns the last price on which order was placed
       */

      if(qty == _buyOrderWrapper.getLastQuantity() &&
          price == _buyOrderWrapper.getLastQuotedPrice())
        return;

      /**
       * If getLastQuantity() returns a non zero ,
       * that means an order is already standing 
       * we can replace it
       */
      if(_buyOrderWrapper.getLastQuantity())
      {
        /**
         *replaces the existing order
         */
        if(!_buyOrderWrapper.replaceOrder(_riskStatus,price,qty))
        {
          /**
           * If replaceOrder returns false
           * RMS checks have been failed
           * Terminating strategy here
           */
          _buyOrderWrapper._isPendingReplace = false;
          DEBUG_MESSAGE(reqQryDebugLog()," Buy Could not be Replaced");
          terminateStrategyComment(API2::CONSTANTS::RSP_StrategyComment_STRATEGY_ERROR_STATE);
          return;
        }
        DEBUG_MESSAGE(reqQryDebugLog()," Buy Replaced");
      }
      else
      {
        /**
         *If getLastQuantity() returns 0
         * we need to reset orderWrapper(generate an new order structure and new common orderId)
         *
         */
        _buyOrderWrapper.reset();
        /**
         * places a new order
         */
        if(!_buyOrderWrapper.newOrder(_riskStatus,price,qty))
        {
          /**
           * If placeOrder returns false
           * RMS checks have been failed
           * Terminating strategy here
           */
          _buyOrderWrapper._isPendingNew = false;
          DEBUG_MESSAGE(reqQryDebugLog()," Buy Could not be Placed")
            terminateStrategyComment(API2::CONSTANTS::RSP_StrategyComment_STRATEGY_ERROR_STATE);
          return;
        }
        DEBUG_MESSAGE(reqQryDebugLog()," Buy Placed");
      }
    }
    /**
     * Sell Case
     */
    else if(orderMode == API2::CONSTANTS::CMD_OrderMode_SELL)
    {
      API2::DATA_TYPES::QTY qty = std::min(_userParams._sellOrderLots,_userParams._sellTotalLots - _sellTotalTradedLots);
      API2::DATA_TYPES::PRICE price = _userParams._sellPrice;

      // price in terms of tick size
      // e.g. if price is 300.02 , then converting it to 300.05
      SIGNED_LONG rem = price % _sellOrderWrapper._instrument->getStaticData()->tickSize;
      if(rem)
      {
        price = price + (_sellOrderWrapper._instrument->getStaticData()->tickSize - rem);
      }
      qty *= _biddingInstrument->getStaticData()->marketLot;
      
      if( qty != 0 )
      qty += _sellOrderWrapper.getLastFilledQuantity();

      if(qty <= 0 || price <= 0)
      {
        placeCancelOrder( _sellOrderWrapper );
        return;
      }

      if(qty == _sellOrderWrapper.getLastQuantity() &&
          price == _sellOrderWrapper.getLastQuotedPrice())
        return;

      if(_sellOrderWrapper.getLastQuantity())
      {
        if(!_sellOrderWrapper.replaceOrder(_riskStatus,price,qty))
        {
          _sellOrderWrapper._isPendingReplace = false;
          DEBUG_MESSAGE(reqQryDebugLog()," Sell Could not be Replaced");
          terminateStrategyComment(API2::CONSTANTS::RSP_StrategyComment_STRATEGY_ERROR_STATE);
          return;
        }
        DEBUG_MESSAGE(reqQryDebugLog()," Sell Replaced");
      }
      else
      {
        _sellOrderWrapper.reset();
        if(!_sellOrderWrapper.newOrder(_riskStatus,price,qty))
        {
          _buyOrderWrapper._isPendingNew = false;
          DEBUG_MESSAGE(reqQryDebugLog()," Sell Could not be Placed")
            terminateStrategyComment(API2::CONSTANTS::RSP_StrategyComment_STRATEGY_ERROR_STATE);
          return;
        }
        DEBUG_MESSAGE(reqQryDebugLog()," Sell Placed");
      }
    }
  }