Пример #1
0
        public static List <Transfer> DetectAndExecuteRollupTransfers_Live(int rollupNumber, int arbitrationRunId, List <BaseExchange> exchanges, ILog log = null)
        {
            DataTable       transfersToExecute = CalculateRollupTransfers(rollupNumber, arbitrationRunId);
            List <Transfer> transfers          = null;

            //If there were transfers found that need to be executed.
            if (transfersToExecute != null)
            {
                foreach (DataRow transferRow in transfersToExecute.Rows)
                {
                    BaseExchange originExchange      = GetExchangeFromListByName((string)transferRow["BUY_EXCHANGE"], exchanges);
                    BaseExchange destinationExchange = GetExchangeFromListByName((string)transferRow["SELL_EXCHANGE"], exchanges);
                    decimal      amount = (decimal)transferRow["AMOUNT"];

                    //Validate inputs Create the transfer object
                    try
                    {
                        //This might throw a NotEnoughBtcException
                        Transfer transfer = ValidateInputsAndBuildTransferObject(originExchange, destinationExchange, amount);

                        //Setting transfer list here, because at least one transfer was found and properly built
                        if (transfers == null)
                        {
                            transfers = new List <Transfer>();
                        }

                        //Execute the actual transfer
                        originExchange.Transfer(amount, destinationExchange.BitcoinDepositAddress);

                        //Save the transfer object to the DB before returning
                        transfer.PersistToDb();

                        //If a log was given, create a log message
                        if (log != null)
                        {
                            log.Info(String.Format(LOG_MESSAGE, transfer.Id.Value, transfer.Amount, transfer.OriginExchange.Name, transfer.DestinationExchange.Name));
                        }

                        //Update all the necessary arbitration trades with the transfer id
                        UpdateArbitrationTradesWithTransferId(arbitrationRunId, transfer.OriginExchange.Name, transfer.DestinationExchange.Name, transfer.Id.Value);

                        transfers.Add(transfer);
                    }
                    catch (NotEnoughBtcException)
                    {
                        //This may or may not be a valid error. If there is not enough btc for the transfer, but there is btc in transfer, then it's ok, the transfers
                        //just need to get caught up. In this case, do nothing; just need to wait until the transfer complete and try again. But, if there is still not
                        //enough btc while accounting for the amount in transfer, this is a legitmate error, so rethrow.
                        if (!(Decimal.Add(originExchange.AvailableBtc, originExchange.BTCInTransfer) >= amount))
                        {
                            throw;
                        }
                    }
                }
            }

            return(transfers);
        }
Пример #2
0
        /// <summary>
        /// Transfers coins between the given exchanges. Coin amounts are not updated.
        /// This method  throws an ArgumentException is Amount is greater than the AvailableBtc of the given origin exchange,
        /// the given exchanges are null, or Amount is less than or equal to 0.
        /// </summary>
        /// <param name="originExchange">The exchange coins will be moved out of.</param>
        /// <param name="destinationExchange">The exchange coins will be sent to.</param>
        /// <param name="amount">The number of bitcoins to be exchanged between the two giving exchanges.</param>
        /// <returns>A  transfer object representing the transfer that took place. This method saves the transfer
        ///     object to the DB before it is returned.</returns>
        public static Transfer OnTimeTransfer_Live(BaseExchange originExchange, BaseExchange destinationExchange, decimal amount, ILog log = null)
        {
            Transfer returnTransfer = ValidateInputsAndBuildTransferObject(originExchange, destinationExchange, amount);

            originExchange.Transfer(amount, destinationExchange.BitcoinDepositAddress);

            //Save the transfer object to the DB before returning
            returnTransfer.PersistToDb();

            //If a log was given, create a log message
            if (log != null)
            {
                log.Info(String.Format(LOG_MESSAGE, returnTransfer.Id.Value, returnTransfer.Amount, returnTransfer.OriginExchange.Name, returnTransfer.DestinationExchange.Name));
            }

            return(returnTransfer);
        }