public void ArbitrageVolumePnL_Simple2_Test()
        {
            var eurgbpOB = new OrderBook("FE", _eurgbp,
                                         new List <LimitOrder> (), // bids
                                         new List <LimitOrder>     // asks
            {
                new LimitOrder(0.90477m, 757921.29m)
            },
                                         DateTime.Now);

            var eurusdOB = new OrderBook("FE", _eurusd,
                                         new List <LimitOrder> // bids
            {
                new LimitOrder(1.16211m, 1923.11m),
                new LimitOrder(0.58117m, 100)
            },
                                         new List <LimitOrder>(), // asks
                                         DateTime.Now);

            var gbpusdOB = new OrderBook("FE", _gbpusd,
                                         new List <LimitOrder>(), // bids
                                         new List <LimitOrder>    // asks
            {
                new LimitOrder(1.28167m, 2909.98m),               // 0.78023, 3729.63406 (reciprocal)
                new LimitOrder(1.29906m, 50000m)                  // 0.76978, 64953.0 (reciprocal)
            },
                                         DateTime.Now);

            var eurgbpSynth = SynthOrderBook.FromOrderBooks(eurusdOB, gbpusdOB, _eurgbp);

            var volumePnL = Arbitrage.GetArbitrageVolumeAndPnL(eurgbpSynth.Bids, eurgbpOB.Asks);

            Assert.NotNull(volumePnL?.Volume);
            Assert.NotNull(volumePnL?.PnL);
        }
Пример #2
0
        public void From3OrderBooks_1_1_1_Test()
        {
            const string source1    = "TEST1";
            const string source2    = "TEST2";
            const string source3    = "TEST3";
            var          timestamp1 = DateTime.UtcNow.AddSeconds(-2);
            var          timestamp2 = DateTime.UtcNow.AddSeconds(-1);
            var          timestamp3 = DateTime.UtcNow;

            var btcEurOrderBook = new OrderBook(source1, _eurbtc,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(1 / 7310m, 9), new LimitOrder(1 / 7300m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(1 / 7320m, 10), new LimitOrder(1 / 7330m, 7), new LimitOrder(1 / 7340m, 3)
            },
                                                timestamp1);

            var eurJpyOrderBook = new OrderBook(source2, _jpyeur,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(1 / 131m, 9), new LimitOrder(1 / 130m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(1 / 132m, 11), new LimitOrder(1 / 133m, 7), new LimitOrder(1 / 134m, 3)
            },
                                                timestamp2);

            var jpyUsdOrderBook = new OrderBook(source3, _usdjpy,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(1 / 0.009132m, 9), new LimitOrder(1 / 0.009131m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(1 / 0.009133m, 12), new LimitOrder(1 / 0.009134m, 7), new LimitOrder(1 / 0.009135m, 3)
            },
                                                timestamp3);

            var synthOrderBook = SynthOrderBook.FromOrderBooks(btcEurOrderBook, eurJpyOrderBook, jpyUsdOrderBook, _btcusd);

            Assert.Equal("TEST1 - TEST2 - TEST3", synthOrderBook.Source);
            Assert.Equal(_btcusd, synthOrderBook.AssetPair);
            Assert.Equal("EURBTC & JPYEUR & USDJPY", synthOrderBook.ConversionPath);
            Assert.Equal(3, synthOrderBook.Bids.Count());
            Assert.Equal(2, synthOrderBook.Asks.Count());
            Assert.Equal(8984.8206m, synthOrderBook.BestBid.Price, 8);
            Assert.Equal(8665.319m, synthOrderBook.BestAsk.Price, 8);
            Assert.Equal(0.00000305m, synthOrderBook.BestBid.Volume, 8);
            Assert.Equal(0.00000527m, synthOrderBook.BestAsk.Volume, 8);
            Assert.Equal(timestamp1, synthOrderBook.Timestamp);
            Assert.Equal(3, synthOrderBook.OriginalOrderBooks.Count);
        }
Пример #3
0
        public void From3OrderBooks_0_1_0_Test()
        {
            const string source1    = "TEST1";
            const string source2    = "TEST2";
            const string source3    = "TEST3";
            var          timestamp1 = DateTime.UtcNow.AddSeconds(-2);
            var          timestamp2 = DateTime.UtcNow.AddSeconds(-1);
            var          timestamp3 = DateTime.UtcNow;

            var btcEurOrderBook = new OrderBook(source1, _btceur,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(7310m, 9), new LimitOrder(7300m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(7320m, 10), new LimitOrder(7330m, 7), new LimitOrder(7340m, 3)
            },
                                                timestamp1);

            var eurJpyOrderBook = new OrderBook(source2, _eurjpy,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(131m, 9), new LimitOrder(130m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(132m, 11), new LimitOrder(133m, 7), new LimitOrder(134m, 3)
            },
                                                timestamp2);

            var jpyUsdOrderBook = new OrderBook(source3, _jpyusd,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(0.009132m, 9), new LimitOrder(0.009131m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(0.009133m, 12), new LimitOrder(0.009134m, 7), new LimitOrder(0.009135m, 3)
            },
                                                timestamp3);

            var synthOrderBook = SynthOrderBook.FromOrderBooks(btcEurOrderBook, eurJpyOrderBook, jpyUsdOrderBook, _btcusd);

            Assert.Equal("TEST1 - TEST2 - TEST3", synthOrderBook.Source);
            Assert.Equal(_btcusd, synthOrderBook.AssetPair);
            Assert.Equal("BTCEUR & EURJPY & JPYUSD", synthOrderBook.ConversionPath);
            Assert.Equal(2, synthOrderBook.Bids.Count());
            Assert.Equal(3, synthOrderBook.Asks.Count());
            Assert.Equal(8744.894520m, synthOrderBook.BestBid.Price);
            Assert.Equal(8824.669920m, synthOrderBook.BestAsk.Price);
            Assert.Equal(0.00000940m, synthOrderBook.BestBid.Volume, 8);
            Assert.Equal(0.00001242m, synthOrderBook.BestAsk.Volume, 8);
            Assert.Equal(timestamp1, synthOrderBook.Timestamp);
            Assert.Equal(3, synthOrderBook.OriginalOrderBooks.Count);
        }
Пример #4
0
        public void From3OrderBooks_1_0_1_Test()
        {
            const string source1    = "TEST1";
            const string source2    = "TEST2";
            const string source3    = "TEST3";
            var          timestamp1 = DateTime.UtcNow.AddSeconds(-2);
            var          timestamp2 = DateTime.UtcNow.AddSeconds(-1);
            var          timestamp3 = DateTime.UtcNow;

            var btcEurOrderBook = new OrderBook(source1, _eurbtc,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(1 / 7310m, 9), new VolumePrice(1 / 7300m, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(1 / 7320m, 10), new VolumePrice(1 / 7330m, 7), new VolumePrice(1 / 7340m, 3)
            },
                                                timestamp1);

            var eurJpyOrderBook = new OrderBook(source2, _eurjpy,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(131m, 9), new VolumePrice(130m, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(132m, 11), new VolumePrice(133m, 7), new VolumePrice(134m, 3)
            },
                                                timestamp2);

            var jpyUsdOrderBook = new OrderBook(source3, _usdjpy,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(1 / 0.009132m, 9), new VolumePrice(1 / 0.009131m, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(1 / 0.009133m, 12), new VolumePrice(1 / 0.009134m, 7), new VolumePrice(1 / 0.009135m, 3)
            },
                                                timestamp3);

            var synthOrderBook = SynthOrderBook.FromOrderBooks(btcEurOrderBook, eurJpyOrderBook, jpyUsdOrderBook, _btcusd);

            Assert.Equal("TEST1-TEST2-TEST3", synthOrderBook.Source);
            Assert.Equal(_btcusd, synthOrderBook.AssetPair);
            Assert.Equal("TEST1-EURBTC * TEST2-EURJPY * TEST3-USDJPY", synthOrderBook.ConversionPath);
            Assert.Equal(6, synthOrderBook.Bids.Count());
            Assert.Equal(3, synthOrderBook.Asks.Count());
            Assert.Equal(8783.6679m, synthOrderBook.BestBid.Value.Price, 8);
            Assert.Equal(8798.6316m, synthOrderBook.BestAsk.Value.Price, 8);
            Assert.Equal(0.00034154m, synthOrderBook.BestBid.Value.Volume, 8);
            Assert.Equal(0.00056827m, synthOrderBook.BestAsk.Value.Volume, 8);
            Assert.Equal(timestamp1, synthOrderBook.Timestamp);
            Assert.Equal(3, synthOrderBook.OriginalOrderBooks.Count);
        }
Пример #5
0
        public void From3OrderBooks_0_1_1_Test()
        {
            const string source1    = "TEST1";
            const string source2    = "TEST2";
            const string source3    = "TEST3";
            var          timestamp1 = DateTime.UtcNow.AddSeconds(-2);
            var          timestamp2 = DateTime.UtcNow.AddSeconds(-1);
            var          timestamp3 = DateTime.UtcNow;

            var btcEurOrderBook = new OrderBook(source1, _btceur,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(7310m, 9), new VolumePrice(7300m, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(7320m, 10), new VolumePrice(7330m, 7), new VolumePrice(7340m, 3)
            },
                                                timestamp1);

            var jpyEurOrderBook = new OrderBook(source2, _jpyeur,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(1 / 132m, 11), new VolumePrice(1 / 133m, 7), new VolumePrice(1 / 134m, 3)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(1 / 131m, 9), new VolumePrice(1 / 130m, 5)
            },
                                                timestamp2);

            var jpyUsdOrderBook = new OrderBook(source3, _usdjpy,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(1 / 0.009132m, 9), new VolumePrice(1 / 0.009131m, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(1 / 0.009133m, 12), new VolumePrice(1 / 0.009134m, 7), new VolumePrice(1 / 0.009135m, 3)
            },
                                                timestamp3);

            var synthOrderBook = SynthOrderBook.FromOrderBooks(btcEurOrderBook, jpyEurOrderBook, jpyUsdOrderBook, _btcusd);

            Assert.Equal("TEST1-TEST2-TEST3", synthOrderBook.Source);
            Assert.Equal(_btcusd, synthOrderBook.AssetPair);
            Assert.Equal("TEST1-BTCEUR * TEST2-JPYEUR * TEST3-USDJPY", synthOrderBook.ConversionPath);
            Assert.Equal(2, synthOrderBook.Bids.Count());
            Assert.Equal(3, synthOrderBook.Asks.Count());
            Assert.Equal(8747.76735m, synthOrderBook.BestBid.Value.Price, 8);
            Assert.Equal(8822.73744m, synthOrderBook.BestAsk.Value.Price, 8);
            Assert.Equal(0.00000940m, synthOrderBook.BestBid.Value.Volume, 8);
            Assert.Equal(0.00001138m, synthOrderBook.BestAsk.Value.Volume, 8);
            Assert.Equal(timestamp1, synthOrderBook.Timestamp);
            Assert.Equal(3, synthOrderBook.OriginalOrderBooks.Count);
        }
Пример #6
0
        public void From2OrderBooks_0_1_Test()
        {
            const string source     = "FakeExchange";
            var          timestamp1 = DateTime.UtcNow.AddSeconds(-1);
            var          timestamp2 = DateTime.UtcNow;

            var btcEurOrderBook = new OrderBook(source, _btceur,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(8825, 9),
                new LimitOrder(8823, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(9000, 10),
                new LimitOrder(8999.95m, 7),
                new LimitOrder(8900.12345677m, 3)
            },
                                                timestamp1);

            var eurUsdOrderBook = new OrderBook(source, _usdeur,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(1 / 1.11m, 9),
                new LimitOrder(1 / 1.10m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(1 / 1.12m, 10),
                new LimitOrder(1 / 1.13m, 7),
                new LimitOrder(1 / 1.14m, 3)
            },
                                                timestamp2);

            var synthOrderBook = SynthOrderBook.FromOrderBooks(btcEurOrderBook, eurUsdOrderBook, _btcusd);

            Assert.Equal("FakeExchange - FakeExchange", synthOrderBook.Source);
            Assert.Equal(_btcusd, synthOrderBook.AssetPair);
            Assert.Equal("BTCEUR & USDEUR", synthOrderBook.ConversionPath);
            Assert.Equal(3, synthOrderBook.Bids.Count());
            Assert.Equal(2, synthOrderBook.Asks.Count());
            Assert.Equal(10060.5m, synthOrderBook.BestBid.Price, 8);
            Assert.Equal(9790.135802447m, synthOrderBook.BestAsk.Price, 8);
            Assert.Equal(0.00029820m, synthOrderBook.BestBid.Volume, 8);
            Assert.Equal(0.00051072m, synthOrderBook.BestAsk.Volume, 8);
            // TODO: Prices must be tested (i.e. GetOrderedLimitOrders methods)
            Assert.Equal(timestamp1, synthOrderBook.Timestamp);
            Assert.Equal(2, synthOrderBook.OriginalOrderBooks.Count);
        }
Пример #7
0
        public void From2OrderBooks_1_1_Test()
        {
            const string source     = "FakeExchange";
            var          timestamp1 = DateTime.UtcNow.AddSeconds(-1);
            var          timestamp2 = DateTime.UtcNow;

            var btcEurOrderBook = new OrderBook(source, _eurbtc,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(1 / 8825m, 9),
                new LimitOrder(1 / 8823m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(1 / 9000m, 10),
                new LimitOrder(1 / 8999.95m, 7),
                new LimitOrder(1 / 8900.12345677m, 3)
            },
                                                timestamp1);

            var eurUsdOrderBook = new OrderBook(source, _usdeur,
                                                new List <LimitOrder> // bids
            {
                new LimitOrder(1 / 1.11m, 9),
                new LimitOrder(1 / 1.10m, 5)
            },
                                                new List <LimitOrder> // asks
            {
                new LimitOrder(1 / 1.12m, 10),
                new LimitOrder(1 / 1.13m, 7),
                new LimitOrder(1 / 1.14m, 3)
            },
                                                timestamp2);

            var synthOrderBook = SynthOrderBook.FromOrderBooks(btcEurOrderBook, eurUsdOrderBook, _btcusd);

            Assert.Equal("FakeExchange - FakeExchange", synthOrderBook.Source);
            Assert.Equal(_btcusd, synthOrderBook.AssetPair);
            Assert.Equal("EURBTC & USDEUR", synthOrderBook.ConversionPath);
            Assert.Equal(3, synthOrderBook.Bids.Count());
            Assert.Equal(3, synthOrderBook.Asks.Count());
            Assert.Equal(10260m, synthOrderBook.BestBid.Price, 8);
            Assert.Equal(9705.30m, synthOrderBook.BestAsk.Price, 8);
            Assert.Equal(0.00029240m, synthOrderBook.BestBid.Volume, 8);
            Assert.Equal(0.00051518m, synthOrderBook.BestAsk.Volume, 8);
            Assert.Equal(timestamp1, synthOrderBook.Timestamp);
            Assert.Equal(2, synthOrderBook.OriginalOrderBooks.Count);
        }
Пример #8
0
        public void From2OrderBooks_1_0_Test()
        {
            const string source     = "FakeExchange";
            var          timestamp1 = DateTime.UtcNow.AddSeconds(-1);
            var          timestamp2 = DateTime.UtcNow;

            var btcEurOrderBook = new OrderBook(source, _eurbtc,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(1 / 8825m, 9),
                new VolumePrice(1 / 8823m, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(1 / 9000m, 10),
                new VolumePrice(1 / 8999.95m, 7),
                new VolumePrice(1 / 8900.12345677m, 3)
            },
                                                timestamp1);

            var eurUsdOrderBook = new OrderBook(source, _eurusd,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(1.11m, 9),
                new VolumePrice(1.10m, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(1.12m, 10),
                new VolumePrice(1.13m, 7),
                new VolumePrice(1.14m, 3)
            },
                                                timestamp2);

            var synthOrderBook = SynthOrderBook.FromOrderBooks(btcEurOrderBook, eurUsdOrderBook, _btcusd);

            Assert.Equal("FakeExchange-FakeExchange", synthOrderBook.Source);
            Assert.Equal(_btcusd, synthOrderBook.AssetPair);
            Assert.Equal("FakeExchange-EURBTC * FakeExchange-EURUSD", synthOrderBook.ConversionPath);
            Assert.Equal(2, synthOrderBook.Bids.Count());
            Assert.Equal(2, synthOrderBook.Asks.Count());
            Assert.Equal(9990m, synthOrderBook.BestBid.Value.Price, 8);
            Assert.Equal(9881.76m, synthOrderBook.BestAsk.Value.Price, 8);
            Assert.Equal(0.001m, synthOrderBook.BestBid.Value.Volume, 8);
            Assert.Equal(0.00056670m, synthOrderBook.BestAsk.Value.Volume, 8);
            Assert.Equal(timestamp1, synthOrderBook.Timestamp);
            Assert.Equal(2, synthOrderBook.OriginalOrderBooks.Count);
        }
Пример #9
0
        public void From2OrderBooks_0_0_Test()
        {
            const string source     = "FakeExchange";
            var          timestamp1 = DateTime.UtcNow.AddSeconds(-1);
            var          timestamp2 = DateTime.UtcNow;

            var btcEurOrderBook = new OrderBook(source, _btceur,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(8825, 9),
                new VolumePrice(8823, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(9000, 10),
                new VolumePrice(8999.95m, 7),
                new VolumePrice(8900.12345677m, 3)
            },
                                                timestamp1);

            var eurUsdOrderBook = new OrderBook(source, _eurusd,
                                                new List <VolumePrice> // bids
            {
                new VolumePrice(1.11m, 9),
                new VolumePrice(1.10m, 5)
            },
                                                new List <VolumePrice> // asks
            {
                new VolumePrice(1.12m, 10),
                new VolumePrice(1.13m, 7),
                new VolumePrice(1.14m, 3)
            },
                                                timestamp2);

            var synthOrderBook = SynthOrderBook.FromOrderBooks(btcEurOrderBook, eurUsdOrderBook, _btcusd);

            Assert.Equal("FakeExchange-FakeExchange", synthOrderBook.Source);
            Assert.Equal(_btcusd, synthOrderBook.AssetPair);
            Assert.Equal("FakeExchange-BTCEUR * FakeExchange-EURUSD", synthOrderBook.ConversionPath);
            Assert.Equal(2, synthOrderBook.Bids.Count());
            Assert.Equal(3, synthOrderBook.Asks.Count());
            Assert.Equal(9795.75m, synthOrderBook.BestBid.Value.Price, 8);
            Assert.Equal(9968.1382715824m, synthOrderBook.BestAsk.Value.Price, 8);
            // TODO: Prices must be tested in all From* methods (i.e. GetOrderedVolumePrices methods)
            Assert.Equal(timestamp1, synthOrderBook.Timestamp);
            Assert.Equal(2, synthOrderBook.OriginalOrderBooks.Count);
        }