Beispiel #1
0
        public bool SellItem(float amount, VolumeOwner owner, float cost_fee)
        {
            if (GetBitcoins(owner) < amount)
            {
                Logger.Log("Wallet", "Not enough bitcoins to sell in wallet!");
                Logger.LogVal("has", GetBitcoins(owner), LogType.BTC);
                Logger.LogVal("need", amount, LogType.BTC);
                Logger.Log("");
                return(false);
            }

            var list = GetOrderedList(owner);

            for (int i = 0; i < list.Count && amount > 0; i++)
            {
                float share = list[i].share[(int)owner] * list[i].data.Amount;

                if (share < amount)
                {
                    amount -= share;
                    list[i].share[(int)owner] = 0;
                }
                else
                {
                    amount = 0;
                    list[i].share[(int)owner] -= amount / list[i].data.Amount;
                    break;
                }
            }

            Logger.Log("Wallet", "Sold item from wallet!");

            _money.AddMoney(owner, amount * cost_fee);
            return(true);
        }
Beispiel #2
0
        public void AddMoney(VolumeOwner owner, float amount)
        {
            spendings[(int)owner] -= amount;

            Logger.Log("Wallet", "Booked " + amount.ToString("N2") + " € for " + owner.ToString() + "!");

            float dif = -1.0f * spendings[(int)owner];

            if (dif > 0)
            {
                float res = spendings[(int)VolumeOwner.RESERVE_EUR];
                if (res != 0)
                {
                    if (res > dif)
                    {
                        spendings[(int)VolumeOwner.RESERVE_EUR] -= dif;
                        dif = 0;
                    }
                    else
                    {
                        spendings[(int)VolumeOwner.RESERVE_EUR] = 0;
                        dif -= res;
                    }
                }
                spendings[(int)owner] = 0;
                kapital += dif;
            }
        }
Beispiel #3
0
        public float RemainingMoney(VolumeOwner owner, float maxPerc = 1.0f)
        {
            if (owner == VolumeOwner.ALL)
            {
                float res = 0;
                foreach (var s in spendings)
                {
                    res += s;
                }
                return(kapital - res);
            }
            else if ((int)owner > 3)
            {
                return(0);
            }
            float result = kapital * share[(int)owner] - spendings[(int)owner];
            float max    = kapital * share[(int)owner] * maxPerc;

            if (result > max)
            {
                result = max;
            }

            return(result);
        }
Beispiel #4
0
        public float PossibleBitcoins(VolumeOwner owner)
        {
            //float av = AvgFee(true, 5);

            //if (av == 0) return 0;

            return(0);
            //return Wallet.that._money.RemainingMoney(owner) / OfferBook.that.AvgFee(true, 5);
        }
Beispiel #5
0
        public float GetBitcoins(VolumeOwner owner)
        {
            float result = 0;

            foreach (var item in _content)
            {
                result += item.share[(int)owner] * item.data.Amount;
            }

            return(result);
        }
Beispiel #6
0
        public bool Spend(VolumeOwner owner, float amount)
        {
            if (RemainingMoney(owner) < amount)
            {
                return(false);
            }

            spendings[(int)owner] += amount;

            return(true);
        }
Beispiel #7
0
        public float GetBitcoins(VolumeOwner owner, float price_fee, float minGainPercentage)
        {
            float result = 0;

            foreach (var item in _content)
            {
                if (price_fee / item.data.GetFeePrice(true) >= minGainPercentage)
                {
                    result += item.share[(int)owner] * item.data.Amount;
                }
            }

            return(result);
        }
Beispiel #8
0
        public bool SellItem(ref float targetAmount, VolumeOwner owner, float cost_fee)
        {
            float amount = GetBitcoins(owner);

            if (amount >= targetAmount)
            {
                amount       = targetAmount;
                targetAmount = 0;
            }
            else
            {
                targetAmount -= amount;
            }

            return(SellItem(amount - targetAmount, owner, cost_fee));
        }
Beispiel #9
0
 public float SpentMoney(VolumeOwner owner)
 {
     if (owner == VolumeOwner.ALL)
     {
         float res = 0;
         foreach (var s in spendings)
         {
             res += s;
         }
         return(res);
     }
     else if ((int)owner > 3)
     {
         return(0);
     }
     return(spendings[(int)owner]);
 }
Beispiel #10
0
        List <WalletItem> GetOrderedList(VolumeOwner owner)
        {
            List <WalletItem> list = new List <WalletItem>();

            while (true)
            {
                float min = 9999999999;
                bool  br = true;
                int   i = 0, iM = 0;
                foreach (var item in _content)
                {
                    bool newIt = true;
                    foreach (var it in list)
                    {
                        if (it == item)
                        {                        //item is already in ordered list
                            newIt = false;
                            break;
                        }
                    }
                    if (newIt && (item.share[(int)owner] > 0))
                    {
                        //item is new and belongs in parts to requested owner
                        if (min > item.data.BuyPrice)
                        {
                            min = item.data.BuyPrice;
                            br  = false;
                            iM  = i;
                        }
                    }
                    i++;
                }
                if (br)
                {
                    break;
                }

                list.Add(_content[iM]);
            }

            return(list);
        }