Exemplo n.º 1
0
        /// <summary>
        /// Saves this arbitration run to the database. If this arbitration run does not have an id, then
        /// an INSERT statement is used. Otherwise, the record in the ARBITRATION_RUN table with the corresponding id
        /// is updated. This method throws any error that could occur when saving to the db.
        /// </summary>
        /// <returns>The id of this arbitration run in the ARBITRATION_RUN table. (If this is an update, id is unchanged).</returns>
        public int?PersistToDb()
        {
            //Whether this is an update or an insert, the last modified date time will need to be updated.
            _lastModifiedDateTime = DateTime.Now;

            string logFileNameSqlString             = DatabaseManager.FormatStringForDb(_logFileName);
            string startDateTimeSqlString           = DatabaseManager.FormatDateTimeForDb(_startDateTime);
            string endDateTimeSqlString             = DatabaseManager.FormatDateTimeForDb(_endDateTime);
            string lastModifiedDateTimeSqlString    = DatabaseManager.FormatDateTimeForDb(_lastModifiedDateTime);
            string opportunitySelectionMethodString = DatabaseManager.FormatStringForDb(_opportunitySelectionMethod.ToString());
            string arbitrationModeString            = DatabaseManager.FormatStringForDb(_arbitrationMode.ToString());
            string transferModeString = DatabaseManager.FormatStringForDb(_transferMode.ToString());
            string rollupNumberString = DatabaseManager.FormatNullableIntegerForDb(_rollupNumber);
            string rollupHoursString  = DatabaseManager.FormatNullableDecimalForDb(_rollupHours);
            string fiatTypeString     = DatabaseManager.FormatStringForDb(_fiatType.ToString());
            string exchangeBaseCurrencyPercentageRestrictionString = DatabaseManager.FormatNullableDecimalForDb(_exchangeBaseCurrencyPercentageRestriction);

            if (_id == null)
            {
                //If we are inserting a new record to the db, set CREATE_DATETIME
                _createDateTime = DateTime.Now;
                string createDateTimeString = DatabaseManager.FormatDateTimeForDb(_createDateTime);

                string insertSql = String.Format("" +
                                                 "insert into ARBITRATION_RUN( " +
                                                 "    USE_ANX, " +
                                                 "    USE_BITFINEX, " +
                                                 "    USE_BITSTAMP, " +
                                                 "    USE_BITX, " +
                                                 "    USE_BTCE, " +
                                                 "    USE_COINBASE, " +
                                                 "    USE_ITBIT, " +
                                                 "    USE_KRAKEN, " +
                                                 "    USE_OKCOIN, " +
                                                 "    MINIMUM_PROFIT_FOR_TRADE, " +
                                                 "    SEARCH_INTERVAL_MILLISECONDS, " +
                                                 "    ROUNDS_REQUIRED_FOR_VALIDATION, " +
                                                 "    MAX_BTC_FOR_TRADE, " +
                                                 "    MAX_FIAT_FOR_TRADE, " +
                                                 "    FIAT_TYPE, " +
                                                 "    OPPORTUNITY_SELECTION_METHOD, " +
                                                 "    MODE, " +
                                                 "    TRANSFER_MODE, " +
                                                 "    ROLLUP_TRADE_NUMBER, " +
                                                 "    ROLLUP_HOURS, " +
                                                 "    EXCHANGE_BASE_CURRENCY_PERCENTAGE_RESTRICTION, " +
                                                 "    LOG_FILE, " +
                                                 "    START_DATETIME, " +
                                                 "    END_DATETIME, " +
                                                 "    CREATE_DATETIME, " +
                                                 "    LAST_MODIFIED_DATETIME)" +
                                                 "OUTPUT INSERTED.ID VALUES( " +
                                                 "    {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}" +
                                                 ")", _useAnx ? 1 : 0, _useBitfinex ? 1 : 0, _useBitstamp ? 1 : 0, _useBitX ? 1 : 0, _useBtce ? 1 : 0, _useCoinbase ? 1 : 0, _useItBit ? 1 : 0, _useKraken ? 1 : 0, _useOkCoin ? 1 : 0, _minimumProfit, _searchIntervalMilliseconds, _roundsRequiredForValidation, _maxBtcTradeAmount, _maxFiatTradeAmount, fiatTypeString, opportunitySelectionMethodString, arbitrationModeString, transferModeString, rollupNumberString, rollupHoursString, exchangeBaseCurrencyPercentageRestrictionString, logFileNameSqlString, startDateTimeSqlString, endDateTimeSqlString, createDateTimeString, lastModifiedDateTimeSqlString);

                _id = DatabaseManager.ExecuteInsert(insertSql);
            }

            else
            {
                string updateSql = String.Format("" +
                                                 "UPDATE " +
                                                 "    ARBITRATION_RUN " +
                                                 "SET " +
                                                 "    USE_ANX = {0}, " +
                                                 "    USE_BITFINEX = {1}, " +
                                                 "    USE_BITSTAMP = {2}, " +
                                                 "    USE_BITX = {3}, " +
                                                 "    USE_BTCE = {4}, " +
                                                 "    USE_COINBASE = {5}, " +
                                                 "    USE_ITBIT = {6}, " +
                                                 "    USE_KRAKEN = {7}, " +
                                                 "    USE_OKCOIN = {8}, " +
                                                 "    MINIMUM_PROFIT_FOR_TRADE = {9}, " +
                                                 "    SEARCH_INTERVAL_MILLISECONDS = {10}, " +
                                                 "    MAX_BTC_FOR_TRADE = {11}, " +
                                                 "    LOG_FILE = {12}, " +
                                                 "    start_datetime = {13}, " +
                                                 "    end_datetime = {14}, " +
                                                 "    LAST_MODIFIED_DATETIME = {15}, " +
                                                 "    MAX_FIAT_FOR_TRADE = {16}, " +
                                                 "    OPPORTUNITY_SELECTION_METHOD = {17}, " +
                                                 "    MODE = {18}, " +
                                                 "    EXCHANGE_BASE_CURRENCY_PERCENTAGE_RESTRICTION = {19}, " +
                                                 "    TRANSFER_MODE = {20}, " +
                                                 "    ROLLUP_TRADE_NUMBER = {21}, " +
                                                 "    ROLLUP_HOURS = {22}, " +
                                                 "    ROUNDS_REQUIRED_FOR_VALIDATION = {23}, " +
                                                 "    FIAT_TYPE = {24} " +
                                                 "WHERE " +
                                                 "    ID = {25} ", _useAnx ? 1 : 0, _useBitfinex ? 1 : 0, _useBitstamp ? 1 : 0, _useBitX ? 1 : 0, _useBtce ? 1 : 0, _useCoinbase ? 1 : 0, _useItBit ? 1 : 0, _useKraken ? 1 : 0, _useOkCoin ? 1 : 0, _minimumProfit, _searchIntervalMilliseconds, _maxBtcTradeAmount, logFileNameSqlString, startDateTimeSqlString, endDateTimeSqlString, lastModifiedDateTimeSqlString, _maxFiatTradeAmount, opportunitySelectionMethodString, arbitrationModeString, exchangeBaseCurrencyPercentageRestrictionString, transferModeString, rollupNumberString, rollupHoursString, _roundsRequiredForValidation, fiatTypeString, _id.Value);

                DatabaseManager.ExecuteNonQuery(updateSql);
            }

            return(_id);
        }
Exemplo n.º 2
0
 public decimal GetFiateBalance(FiatType Ftype)
 {
     //SetCredentials(); // var a = x.GetSymbols(); // Gets available trading pairs.
     x.SetApiCredentials(key, secret);
     return(x.GetBalances().Data[Ftype.ToString()]);
 }