예제 #1
0
        public static SecurityTypes ToStockSharp(this eInstrumentType type)
        {
            switch (type)
            {
            case eInstrumentType.itFuture:
                return(SecurityTypes.Future);

            case eInstrumentType.itOptionPut:
                return(SecurityTypes.Option);

            case eInstrumentType.itOptionCall:
                return(SecurityTypes.Option);

            case eInstrumentType.itStock:
                return(SecurityTypes.Stock);

            case eInstrumentType.itTreasure:
                return(SecurityTypes.Bond);

            case eInstrumentType.itSyntheticStrategy:
                return(SecurityTypes.Index);

            case eInstrumentType.itAllOptions:
                return(SecurityTypes.Option);

            case eInstrumentType.itOther:
            case eInstrumentType.itUndefined:
            case eInstrumentType.itAllInstruments:
                throw new NotSupportedException(LocalizedStrings.UnsupportSecType.Put(type));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, LocalizedStrings.Str1603);
            }
        }
예제 #2
0
        internal bool ValidInstrumentDirection(eInstrumentType instrumentTypeFrom, eOptionalMoves requiredMove)
        {
            bool isValidMove = true;

            //soldier1 can move only up
            if (instrumentTypeFrom == eInstrumentType.PlayerOneSoldier)
            {
                if (requiredMove != eOptionalMoves.EatUpLeft && requiredMove != eOptionalMoves.EatUpRight &&
                    requiredMove != eOptionalMoves.MoveUpLeft && requiredMove != eOptionalMoves.MoveUpRight)
                {
                    isValidMove = false;
                }
            }
            //soldier2 can move only down
            else if (instrumentTypeFrom == eInstrumentType.PlayerTwoSoldier)
            {
                if (requiredMove != eOptionalMoves.EatDownLeft && requiredMove != eOptionalMoves.EatDownRight &&
                    requiredMove != eOptionalMoves.MoveDownLeft && requiredMove != eOptionalMoves.MoveDownRight)
                {
                    isValidMove = false;
                }
            }

            return(isValidMove);
        }
예제 #3
0
        internal bool IsCorrectPlayerIsInCell(eInstrumentType i_InstrumentTypeInCell)
        {
            bool isCorrectPlayerInCell = false;

            if (m_Player.PlayerID == Player.ePlayerID.PlayerOne)
            {
                isCorrectPlayerInCell = i_InstrumentTypeInCell == eInstrumentType.PlayerOneSoldier ||
                                        i_InstrumentTypeInCell == eInstrumentType.PlayerOneKing;
            }
            else
            {
                isCorrectPlayerInCell = i_InstrumentTypeInCell == eInstrumentType.PlayerTwoSoldier ||
                                        i_InstrumentTypeInCell == eInstrumentType.PlayerTwoKing;
            }

            return(isCorrectPlayerInCell);
        }
예제 #4
0
        internal bool IsValidMoveAsPlayer(string i_Move)
        {
            bool isValidMoveResult = true;
            //convert the move into integer
            int colMoveFrom = CharToLocationAtBoard(i_Move[0]);
            int rowMoveFrom = CharToLocationAtBoard(i_Move[1]);
            int colMoveTo   = CharToLocationAtBoard(i_Move[3]);
            int rowMoveTo   = CharToLocationAtBoard(i_Move[4]);
            //check what is the spcific instrument type in board
            eInstrumentType instrumentTypeFrom = m_Board[rowMoveFrom, colMoveFrom];
            //catalog move type
            eOptionalMoves requiredMove = ConvertToEnumMove(rowMoveFrom, rowMoveTo, colMoveFrom, colMoveTo);

            if (requiredMove == eOptionalMoves.InvalidMove)
            {
                isValidMoveResult = false;
                Console.Write("Invalid move. Please try again: ");
            }
            else if (!ValidMoveByType(rowMoveFrom, colMoveFrom, requiredMove))
            {
                isValidMoveResult = false;
                Console.Write("Invalid move. Please try again: ");
            }
            else if (!IsCorrectPlayerIsInCell(instrumentTypeFrom))
            {
                isValidMoveResult = false;
                Console.Write("Invalid move, it is not your instrument. Please try again: ");
            }
            else if (!ValidInstrumentDirection(instrumentTypeFrom, requiredMove))
            {
                isValidMoveResult = false;
                Console.Write("Invalid move, a soldier can go only forward. Please try again: ");
            }
            else if (CheckIfCanEat())
            {
                if (requiredMove != eOptionalMoves.EatDownLeft && requiredMove != eOptionalMoves.EatDownRight &&
                    requiredMove != eOptionalMoves.EatUpLeft && requiredMove != eOptionalMoves.EatUpRight)
                {
                    isValidMoveResult = false;
                    Console.Write("Invalid move, you should make a capture. Please try again: ");
                }
            }

            return(isValidMoveResult);
        }
예제 #5
0
        internal bool ValidInstrumentDirection(eInstrumentType i_InstrumentTypeFrom, eOptionalMoves i_RequiredMove)
        {
            bool isValidMove = true;

            if (i_InstrumentTypeFrom == eInstrumentType.PlayerOneSoldier)
            {
                isValidMove = i_RequiredMove == eOptionalMoves.EatUpLeft ||
                              i_RequiredMove == eOptionalMoves.EatUpRight ||
                              i_RequiredMove == eOptionalMoves.MoveUpLeft ||
                              i_RequiredMove == eOptionalMoves.MoveUpRight;
            }
            else if (i_InstrumentTypeFrom == eInstrumentType.PlayerTwoSoldier)
            {
                isValidMove = i_RequiredMove == eOptionalMoves.EatDownLeft ||
                              i_RequiredMove == eOptionalMoves.EatDownRight ||
                              i_RequiredMove == eOptionalMoves.MoveDownLeft ||
                              i_RequiredMove == eOptionalMoves.MoveDownRight;
            }

            return(isValidMove);
        }
예제 #6
0
        internal bool IsValidMoveAsPlayer(int io_RowFrom, int io_ColFrom, int io_RowTo, int io_ColTo)
        {
            bool isValidMoveResult = true;

            eInstrumentType instrumentTypeFrom = m_Board[io_RowFrom, io_ColFrom];
            eOptionalMoves  requiredMove       = ConvertToEnumMove(io_RowFrom, io_RowTo, io_ColFrom, io_ColTo);

            if (requiredMove == eOptionalMoves.InvalidMove)
            {
                isValidMoveResult = false;
                throw new Exception("Invalid move. Please try again.");
            }
            else if (!ValidMoveByType(io_RowFrom, io_ColFrom, requiredMove))
            {
                isValidMoveResult = false;
                throw new Exception("Invalid move. Please try again.");
            }
            else if (!IsCorrectPlayerIsInCell(instrumentTypeFrom))
            {
                isValidMoveResult = false;
                throw new Exception("Invalid move, it is not your instrument. Please try again.");
            }
            else if (!ValidInstrumentDirection(instrumentTypeFrom, requiredMove))
            {
                isValidMoveResult = false;
                throw new Exception("Invalid move, a soldier can go only forward. Please try again.");
            }
            else if (CheckIfCanEat())
            {
                if (requiredMove != eOptionalMoves.EatDownLeft && requiredMove != eOptionalMoves.EatDownRight &&
                    requiredMove != eOptionalMoves.EatUpLeft && requiredMove != eOptionalMoves.EatUpRight)
                {
                    isValidMoveResult = false;
                    throw new Exception("Invalid move, you should make a capture. Please try again.");
                }
            }

            return(isValidMoveResult);
        }
예제 #7
0
        /// <summary>
        /// This event is fired when a previously requested commodity symbol
        /// is resolved into the instruments list.
        /// this is where we will send a security definition back to our clients
        /// </summary>
        /// <param name="commodityName">
        /// The commodity symbol that was requested by the user in the
        /// corresponding RequestCommodityInstruments method call.
        /// </param>
        /// <param name="instrumentTypes">
        /// Instrument type bitmask that was set by the user in the
        /// corresponding RequestCommodityInstruments method call.
        /// </param>
        /// <param name="instrumentNames">
        /// Collection, which contains names of instruments corresponding to the requested
        /// commodity and filtered by the bitmask set in RequestCommodityInstruments Method.
        /// </param>
        private void CEL_CommodityInstrumentsResolved(string commodityName, eInstrumentType instrumentTypes, CQGCommodityInstruments instrumentNames)
        {
            /*
                     * Dont use this as we handle the list
            try
            {
                // set up a security def message
                QuickFix.SecurityReqID mySecReqID;
                QuickFix.SecurityResponseID mySecurityResponseID;
                QuickFix.SecurityResponseType mySecurityResponseType;

                QuickFix43.SecurityDefinition mySecDef;

                QuickFix.Message myMsg;

                // get teh CFI code
                string myCFICode = getCFI(instrumentTypes);

                for (int l = 0; l <= instrumentNames.Count - 1; l++)
                {
                    // set up a security def message
                    mySecReqID = new QuickFix.SecurityReqID(m_ID);
                    mySecurityResponseID = new QuickFix.SecurityResponseID(KaiUtil.Identities.Instance.genReqID());
                    mySecurityResponseType = new QuickFix.SecurityResponseType(QuickFix.SecurityResponseType.LIST_OF_SECURITIES_RETURNED_PER_REQUEST);

                    mySecDef = new QuickFix43.SecurityDefinition(mySecReqID, mySecurityResponseID, mySecurityResponseType);

                    myMsg = mySecDef as QuickFix.Message;

                    KaiUtil.QFUtils.Instance().SetupInstrument(ref myMsg, "FIX.4.3", commodityName, "",
                        instrumentNames[l], "CQG", "XXX", myCFICode, "", 0.0);

                    // send our response message back to the clients of the adapter
                    this.sendResponse("d", mySecDef.ToString());

                    m_CQGHostForm.Message = "Product resolved:" + instrumentNames[l];
                }
            }
            catch (Exception myE)
            {
                log.Error("CEL_TradableCommoditiesResolved", myE);
            }
             *  */
        }
예제 #8
0
 /// <summary>
 /// Get a CFI from a CQG instrument
 /// </summary>
 /// <param name="instrumentType"></param>
 /// <returns></returns>
 private string getCFI(eInstrumentType instrumentType)
 {
     string myCFI = "";
     switch (instrumentType)
     {
         case eInstrumentType.itFuture:
             myCFI = "FXXXXX";
             break;
         case eInstrumentType.itOptionCall:
             myCFI = "OCXXXX";
             break;
         case eInstrumentType.itOptionPut:
             myCFI = "OPXXXX";
             break;
         case eInstrumentType.itStock:
             myCFI = "ESXXXX";
             break;
         default:
             myCFI = "ESXXXX";
             break;
     }
     return myCFI;
 }
예제 #9
0
 void CQGApp_CommodityInstrumentsResolved(string commodity_name, eInstrumentType instrument_types, CQGCommodityInstruments cqg_commodity_intruments)
 {
     try
     {
         // Iterate through the resolved instrument names collection
         foreach (string instrumentName in cqg_commodity_intruments)
         {
             // Subscribe to each instrument in the collection
             m_CQGHostForm.CQGApp.NewInstrument(instrumentName);
         }
     }
     catch (Exception myE)
     {
         log.Error("CQGApp_CommodityInstrumentsResolved", myE);
     }
 }