Ejemplo n.º 1
0
        /// <summary>	Collect fees. </summary>
        ///
        /// <remarks>	Paul, 18/02/2015. </remarks>
        ///
        /// <param name="bitcoinFeeAddress">    The bitcoin fee address. </param>
        /// <param name="bitsharesFeeAccount">	The bitshares fee account. </param>
        public override bool CollectFees(string bitcoinFeeAddress, string bitsharesFeeAccount)
        {
            List <TransactionsRow> transSince = m_daemon.GetCompletedTransactionsInMarketSince(m_market.symbol_pair, m_market.transaction_processed_uid);

            if (transSince.Count > kMaxTransactionsBeforeCollectFees)
            {
                decimal buyFees  = transSince.Where(t => t.order_type == MetaOrderType.buy).Sum(t => t.fee);
                decimal sellFees = transSince.Where(t => t.order_type == MetaOrderType.sell).Sum(t => t.fee);

                // make sure these are in range
                buyFees  = m_asset.Truncate(buyFees);
                sellFees = Numeric.TruncateDecimal(sellFees, 8);

                decimal btcWorthOfBitassets;
                if (m_flipped)
                {
                    btcWorthOfBitassets = buyFees / m_market.bid;
                }
                else
                {
                    btcWorthOfBitassets = buyFees * m_market.bid;
                }

                if (btcWorthOfBitassets > kMinBtcFee &&
                    sellFees > kMinBtcFee)
                {
                    // update this here to prevent failures from continually sending fees
                    m_daemon.UpdateTransactionProcessedForMarket(m_market.symbol_pair, transSince.Last().uid);

                    string bitsharesTrxId = null, bitcoinTxId = null;
                    string exception = null;
                    try
                    {
                        BitsharesTransactionResponse bitsharesTrx = SendBitAssets(buyFees, m_asset, bitsharesFeeAccount, "Fee payment");
                        bitsharesTrxId = bitsharesTrx.record_id;

                        // WTUPID BTC DUST SIZE PREVENTS SMALL TRANSACGTIOJNs
                        bitcoinTxId = m_bitcoin.SendToAddress(bitcoinFeeAddress, sellFees, "Fee payment");
                    }
                    catch (Exception e)
                    {
                        exception = e.ToString();
                    }

                    m_daemon.m_Database.InsertFeeTransaction(m_market.symbol_pair,
                                                             bitsharesTrxId,
                                                             bitcoinTxId,
                                                             buyFees,
                                                             sellFees,
                                                             transSince.Last().uid,
                                                             exception,
                                                             transSince.First().received_txid,
                                                             transSince.Last().received_txid);

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>	Sends a bit assets to depositor. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="RefundBitcoinException">	Thrown when a Refund Bitcoin error condition
        ///                                             occurs. </exception>
        ///
        /// <param name="t">		The TransactionSinceBlock to process. </param>
        /// <param name="asset">	The asset. </param>
        ///
        /// <returns>	A BitsharesTransactionResponse. </returns>
        protected BitsharesTransactionResponse SendBitAssetsToDepositor(TransactionSinceBlock t, BitsharesAsset asset,
                                                                        SenderToDepositRow s2d, MetaOrderType orderType)
        {
            // make sure failures after this point do not result in repeated sending
            m_daemon.MarkDespositAsCreditedStart(t.TxId, s2d.deposit_address, m_market.symbol_pair, orderType, MetaOrderStatus.processing, TransactionPolicy.REPLACE);

            if (t.Amount > m_market.ask_max)
            {
                throw new RefundBitcoinException("Over " + Numeric.SerialisedDecimal(m_market.ask_max) + " " + asset.symbol + "!");
            }

            string  bitsharesAccount = s2d.receiving_address;
            decimal bitAssetAmountNoFee;

            if (m_flipped)
            {
                // they're sending us BTC, not bitAssets because the market is flipped, this is
                // equivelent to the opposite order type, so we have to use bid here
                bitAssetAmountNoFee = t.Amount * m_market.bid;
            }
            else
            {
                bitAssetAmountNoFee = t.Amount / m_market.ask;
            }

            // when buying, the fee is charged in bitAssets,
            // the amount recorded in the transaction is the amount of bitAssets purchased sans fee

            bitAssetAmountNoFee = asset.Truncate(bitAssetAmountNoFee);

            decimal fee         = (m_market.ask_fee_percent / 100) * bitAssetAmountNoFee;
            decimal amountAsset = bitAssetAmountNoFee - fee;

            amountAsset = asset.Truncate(amountAsset);

            BitsharesTransactionResponse bitsharesTrx = SendBitAssets(amountAsset, asset, bitsharesAccount, "mX: " + orderType + " " + asset.symbol);

            m_daemon.MarkDespositAsCreditedEnd(t.TxId, bitsharesTrx.record_id, MetaOrderStatus.completed, bitAssetAmountNoFee, m_market.ask, fee);

            return(bitsharesTrx);
        }
Ejemplo n.º 3
0
        /// <summary>	Sends a bit assets to depositor. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="RefundBitcoinException">	Thrown when a Refund Bitcoin error condition
        /// 											occurs. </exception>
        ///
        /// <param name="t">		The TransactionSinceBlock to process. </param>
        /// <param name="asset">	The asset. </param>
        ///
        /// <returns>	A BitsharesTransactionResponse. </returns>
        protected BitsharesTransactionResponse SendBitAssetsToDepositor(TransactionSinceBlock t, BitsharesAsset asset, 
																		SenderToDepositRow s2d, MetaOrderType orderType)
        {
            // make sure failures after this point do not result in repeated sending
            m_daemon.MarkDespositAsCreditedStart(t.TxId, s2d.deposit_address, m_market.symbol_pair, orderType, MetaOrderStatus.processing, TransactionPolicy.REPLACE);

            if (t.Amount > m_market.ask_max)
            {
                throw new RefundBitcoinException("Over " + Numeric.SerialisedDecimal(m_market.ask_max) + " " + asset.symbol + "!");
            }

            string bitsharesAccount = s2d.receiving_address;
            decimal bitAssetAmountNoFee;

            if (m_flipped)
            {
                // they're sending us BTC, not bitAssets because the market is flipped, this is
                // equivelent to the opposite order type, so we have to use bid here
                bitAssetAmountNoFee = t.Amount * m_market.bid;
            }
            else
            {
                bitAssetAmountNoFee = t.Amount / m_market.ask;
            }

            // when buying, the fee is charged in bitAssets,
            // the amount recorded in the transaction is the amount of bitAssets purchased sans fee

            bitAssetAmountNoFee = asset.Truncate(bitAssetAmountNoFee);

            decimal fee = (m_market.ask_fee_percent / 100) * bitAssetAmountNoFee;
            decimal amountAsset = bitAssetAmountNoFee - fee;

            amountAsset = asset.Truncate(amountAsset);

            BitsharesTransactionResponse bitsharesTrx = SendBitAssets(amountAsset, asset, bitsharesAccount, "mX: " + orderType + " " + asset.symbol);

            m_daemon.MarkDespositAsCreditedEnd(t.TxId, bitsharesTrx.record_id, MetaOrderStatus.completed, bitAssetAmountNoFee, m_market.ask, fee);

            return bitsharesTrx;
        }