Esempio n. 1
0
 /// <summary>Get/Set the pair</summary>
 public TradePair this[string key]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         return(Pairs.TryGetValue(key, out var pair) ? pair : null);
     }
 }
Esempio n. 2
0
 /// <summary>Get a position by order id</summary>
 public Order this[long order_id]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         return(Orders.TryGetValue(order_id, out var ord) ? ord : null);
     }
 }
Esempio n. 3
0
 /// <summary>Get a trade by trade id</summary>
 public TradeCompleted this[long key]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         return(m_trades.TryGetValue(key, out var pos) ? pos : null);
     }
 }
 /// <summary>Get/Set a history entry by order id. Returns null if 'order_id' is not in the collection</summary>
 public OrderCompleted this[long order_id]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         return(Orders.TryGetValue(order_id, out var pos) ? pos : null);
     }
 }
Esempio n. 5
0
 /// <summary>Get/Set a coin by symbol name. Get returns null if 'sym' not in the collection</summary>
 public Coin this[string sym]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         return(Coins.TryGetValue(sym, out var coin) ? coin : null);
     }
 }
 /// <summary>Get/Set a history entry by order id. Returns null if 'key' is not in the collection</summary>
 public Transfer this[string key]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         return(Transfers.TryGetValue(key, out var txfr) ? txfr : null);
     }
 }
Esempio n. 7
0
        /// <summary>Add or update and order fill</summary>
        public TradeCompleted AddOrUpdate(TradeCompleted fill)
        {
            Debug.Assert(Misc.AssertMainThread());
            Debug.Assert(fill.OrderId == m_order.OrderId);
            Debug.Assert(fill.Created > Misc.CryptoCurrencyEpoch && fill.AmountIn > 0 && fill.AmountOut > 0);

            // This is no update, just replace
            m_trades[fill.TradeId] = fill;
            m_order.NotifyPropertyChanged(nameof(OrderCompleted.Trades));
            return(fill);
        }
Esempio n. 8
0
 /// <summary>Get/Set the balance for the given coin. Returns zero balance for unknown coins</summary>
 public Balances this[Coin coin]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         if (coin.Exchange != Exchange && !(Exchange is CrossExchange))
         {
             throw new Exception("Currency not associated with this exchange");
         }
         return(Balances.TryGetValue(coin, out var bal) ? bal : new Balances(coin, Model.UtcNow));
     }
 }
 /// <summary>Add a transfer to this collection</summary>
 public Transfer AddOrUpdate(Transfer transfer)
 {
     Debug.Assert(Misc.AssertMainThread());
     if (Transfers.TryGetValue(transfer.TransactionId, out var existing))
     {
         existing.Update(transfer);
         Transfers.ResetItem(transfer.TransactionId);
     }
     else
     {
         Transfers.Add2(transfer);
     }
     return(transfer);
 }
Esempio n. 10
0
 /// <summary>Add or update an order</summary>
 public Order AddOrUpdate(Order order)
 {
     Debug.Assert(Misc.AssertMainThread());
     Debug.Assert(order.AmountIn > 0 && order.AmountOut > 0 && order.Created > Misc.CryptoCurrencyEpoch);             // Sanity check
     if (Orders.TryGetValue(order.OrderId, out var existing))
     {
         existing.Update(order);
         Orders.ResetItem(order.OrderId);                 // Needed since we're updating in-place
     }
     else
     {
         Orders.Add(order.OrderId, order);
     }
     return(order);
 }
Esempio n. 11
0
 /// <summary>Return a pair involving the given symbol and the two exchanges (in either order)</summary>
 public TradePair this[string sym, Exchange exch0, Exchange exch1]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         if (Pairs.TryGetValue(TradePair.MakeKey(sym, sym, exch0, exch1), out var pair0))
         {
             return(pair0);
         }
         if (Pairs.TryGetValue(TradePair.MakeKey(sym, sym, exch1, exch0), out var pair1))
         {
             return(pair1);
         }
         return(null);
     }
 }
Esempio n. 12
0
 /// <summary>Return a pair involving the given symbols (in either order)</summary>
 public TradePair this[string sym0, string sym1]
 {
     get
     {
         Debug.Assert(Misc.AssertMainThread());
         if (Pairs.TryGetValue(TradePair.MakeKey(sym0, sym1), out var pair0))
         {
             return(pair0);
         }
         if (Pairs.TryGetValue(TradePair.MakeKey(sym1, sym0), out var pair1))
         {
             return(pair1);
         }
         return(null);
     }
 }
Esempio n. 13
0
        /// <summary>Apply an update from an exchange for 'coin'</summary>
        public void ExchangeUpdate(Coin coin, Unit <decimal> total, Unit <decimal> held, DateTimeOffset update_time)
        {
            Debug.Assert(Misc.AssertMainThread());

            // Check the assigned balance info is for this exchange
            if (coin.Exchange != Exchange && !(Exchange is CrossExchange))
            {
                throw new Exception("Currency not associated with this exchange");
            }

            // Get the balances associated with 'coin'
            var balances = GetOrAdd(coin);

            balances.ExchangeUpdate(total, held, update_time);

            // Invalidate bindings
            Balances.ResetItem(balances);
        }
Esempio n. 14
0
        /// <summary>Create a view of price data that updates as new data arrives</summary>
        public Instrument(string name, PriceData pd)
        {
            try
            {
                Debug.Assert(Misc.AssertMainThread());

                Name        = name;
                PriceData   = pd;
                CandleStyle = ECandleStyle.Standard;

                // A cache of candle data read from the DB
                m_cache        = new List <Candle>();
                m_first_cached = 0;
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Esempio n. 15
0
 /// <summary>Get or add a coin type that there is a balance for on the exchange</summary>
 public Balances GetOrAdd(Coin coin)
 {
     Debug.Assert(Misc.AssertMainThread());
     return(Balances.GetOrAdd(coin, x => new Balances(x, DateTimeOffset.MinValue)));
 }
Esempio n. 16
0
 /// <summary>Get or add a coin by symbol name</summary>
 public Coin GetOrAdd(string sym)
 {
     Debug.Assert(Misc.AssertMainThread());
     Debug.Assert(m_coin_data.IndexOf(x => x.Symbol == sym) != -1, "Don't add coins that are not in the settings");
     return(Coins.GetOrAdd(sym, CreateCoin));
 }