/// <summary>Check the orders are in the correct order</summary> public bool AssertOrdersValid() { MarketDepth.AssertOrdersValid(); // Check the spread if (Spread < 0m._(RateUnits)) { throw new Exception("Spread is negative"); } return(true); }
/// <summary>Update this pair using the contents of 'rhs'</summary> public void Update(TradePair rhs) { // Sanity check if (Base != rhs.Base || Quote != rhs.Quote || Exchange != rhs.Exchange) { throw new Exception("Update for the wrong trading pair"); } // Update the update-able parts TradePairId = rhs.TradePairId; AmountRangeBase = rhs.AmountRangeBase; AmountRangeQuote = rhs.AmountRangeQuote; PriceRangeQ2B = rhs.PriceRangeQ2B; MarketDepth.UpdateOrderBooks(rhs.MarketDepth); }
// Notes: // - Links two coins together by their Ask/Bid prices // - Currency pair: Base/Quote e.g. BTC/USDT = $2500 // "1 unit of base currency (BTC) == 2500 units of quote currency (USDT)" // Note, this means the units of the BTC/USDT rate are USDT-per-BTC, counter intuitively :-/ // since X(BTC) * price(USDT/BTC) = Y(USDT) public TradePair(Coin base_, Coin quote, Exchange exchange, int?trade_pair_id = null, RangeF <Unit <decimal> >?amount_range_base = null, RangeF <Unit <decimal> >?amount_range_quote = null, RangeF <Unit <decimal> >?price_range = null) { Base = base_; Quote = quote; Exchange = exchange; SpotPrice = new SpotPrices(base_, quote); RateUnits = Base.Symbol != Quote.Symbol ? $"{Quote}/{Base}" : string.Empty; RateUnitsInv = Base.Symbol != Quote.Symbol ? $"{Base}/{Quote}" : string.Empty; TradePairId = trade_pair_id; AmountRangeBase = amount_range_base ?? new RangeF <Unit <decimal> >(0m._(Base), decimal.MaxValue._(Base)); AmountRangeQuote = amount_range_quote ?? new RangeF <Unit <decimal> >(0m._(Quote), decimal.MaxValue._(Quote)); PriceRangeQ2B = price_range ?? new RangeF <Unit <decimal> >(0m._(RateUnits), decimal.MaxValue._(RateUnits)); MarketDepth = new MarketDepth(base_, quote); }
/// <summary>The total value of orders with a better price than 'price'</summary> public Unit <decimal> OrderBookDepth(ETradeType tt, Unit <decimal> price_q2b, out bool beyond_order_book) { return(MarketDepth.OrderBookDepth(tt, price_q2b, out beyond_order_book)); }
public MarketDepth(MarketDepth rhs) { RateUnits = rhs.RateUnits; Q2B = new OrderBook(rhs.Q2B); B2Q = new OrderBook(rhs.B2Q); }
public void UpdateOrderBooks(MarketDepth rhs) { UpdateOrderBooks(rhs.B2Q.Offers, rhs.Q2B.Offers); }