Exemple #1
0
        /// <summary>
        /// Initialize API with certain ID and Key.
        /// </summary>
        /// <param name="ID">API ID.</param>
        /// <param name="Key">API Key.</param>
        /// <returns>True if initialization has succeeded.</returns>
        public static bool Initialize(string ID, string Key)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            ValidAuthorization = false;

            LibConsole.OpenConsole();
            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Initializating API Wrapper with ID=" + ID.ToString() + " and Key=" + Key);
            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "This program is compatible with API version " + API_VERSION_COMPATIBLE);

            APIID  = ID;
            APIKey = Key;

            // Verify API version
            string RemoteAPIVersion = GetRemoteAPIVersion();

            if (RemoteAPIVersion == null)
            {
                LibConsole.WriteLine(LibConsole.TEXT_TYPE.ERROR, "Failed to get API Version.");
                return(false);
            }

            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Remote API version is " + RemoteAPIVersion);

            if (RemoteAPIVersion != API_VERSION_COMPATIBLE)
            {
                // If API version has changed, only print warning. Program may still work correctly after all.
                LibConsole.WriteLine(LibConsole.TEXT_TYPE.WARNING, "Service API has changed. This program may not work fully correctly.");
            }

            APIBalance Balance = GetBalance();

            if (Balance == null)
            {
                // If we were unable to get balance, then id and key are incorrect.
                LibConsole.WriteLine(LibConsole.TEXT_TYPE.ERROR, "Unable to get balance. Are ID and Key correct?");
                return(false);
            }

            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Provided ID and Key are correct!");

            ValidAuthorization = true;
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Initialize API with certain ID and Key.
        /// </summary>
        /// <param name="ID">API ID.</param>
        /// <param name="Key">API Key.</param>
        /// <returns>True if initialization has succeeded.</returns>
        public static bool Initialize(string ID, string Key)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            ValidAuthorization = false;

            LibConsole.OpenConsole();
            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Initializating API Wrapper with ID=" + ID.ToString() + " and Key=" + Key);
            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "This program is compatible with API version " + API_VERSION_COMPATIBLE);

            APIID  = ID;
            APIKey = Key;

            // Verify API version
            string RemoteAPIVersion = GetRemoteAPIVersion();

            if (RemoteAPIVersion == null)
            {
                LibConsole.WriteLine(LibConsole.TEXT_TYPE.ERROR, "Failed to get API Version.");
                return(false);
            }

            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Remote API version is " + RemoteAPIVersion);

            if (RemoteAPIVersion != API_VERSION_COMPATIBLE)
            {
                // If API version has changed, only print warning. Program may still work correctly after all.
                LibConsole.WriteLine(LibConsole.TEXT_TYPE.WARNING, "Service API has changed. This program may not work fully correctly.");
            }

            APIBalance Balance = GetBalance();

            if (Balance == null)
            {
                // If we were unable to get balance, then id and key are incorrect.
                LibConsole.WriteLine(LibConsole.TEXT_TYPE.ERROR, "Unable to get balance. Are ID and Key correct?");
                return(false);
            }

            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Provided ID and Key are correct!");


            Result <APIBuyInfo> R = Request <Result <APIBuyInfo> >(0, "buy.info", false, null);

            if (R == null)
            {
                LibConsole.WriteLine(LibConsole.TEXT_TYPE.ERROR, "Unable to get buy information. Service unavailable.");
                return(false);
            }

            PRICE_DECREASE_INTERVAL = new TimeSpan(0, 0, R.Data.DownStepTime);
            ALGORITHM_NAME          = new string[R.Data.Algorithms.Length];
            PRICE_DECREASE_STEP     = new double[R.Data.Algorithms.Length];
            ALGORITHM_MULTIPLIER    = new double[R.Data.Algorithms.Length];
            MINIMAL_LIMIT           = new double[R.Data.Algorithms.Length];
            SPEED_TEXT = new string[R.Data.Algorithms.Length];
            for (int i = 0; i < R.Data.Algorithms.Length; i++)
            {
                ALGORITHM_NAME[i]       = R.Data.Algorithms[i].Name;
                PRICE_DECREASE_STEP[i]  = R.Data.Algorithms[i].PriceDownStep;
                ALGORITHM_MULTIPLIER[i] = R.Data.Algorithms[i].Multiplier;
                MINIMAL_LIMIT[i]        = R.Data.Algorithms[i].MinimalLimit;
                SPEED_TEXT[i]           = R.Data.Algorithms[i].SpeedText;
            }

            NUMBER_OF_ALGORITHMS = ALGORITHM_NAME.Length;

            CachedOList = new CachedOrderList[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];
            CachedSList = new CachedStats[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];

            LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Buy information loaded.");

            ValidAuthorization = true;

            return(true);
        }