Exemple #1
0
    def test_get_executable_partial_second_order(self):
        cross = arbitrage.detect_cross(self.more_ob_1(), self.more_ob_2())

        cross.volume.should.equal(Money('1', 'BTC'))
        cross.revenue.should.equal(Money('0.75', 'USD'))

        buy_balance = {'USD': Money('449.375', 'USD'), 'BTC': Money('0', 'BTC')}
        sell_balance = {'USD': Money('0', 'USD'), 'BTC': Money('1', 'BTC')}

        result = arbitrage.get_executable_volume(cross, buy_balance, sell_balance)

        result.should.equal(Money('0.75', 'BTC'))
Exemple #2
0
    def test_get_executable_restriction(self):
        cross = arbitrage.detect_cross(self.more_ob_1(), self.more_ob_2())

        cross.volume.should.equal(Money('1', 'BTC'))
        cross.revenue.should.equal(Money('0.75', 'USD'))

        buy_balance = {'USD': Money('299.5', 'USD'), 'BTC': Money('0', 'BTC')}
        sell_balance = {'USD': Money('0', 'USD'), 'BTC': Money('1', 'BTC')}

        result = arbitrage.get_executable_volume(cross, buy_balance, sell_balance)

        result.should.equal(Money('0.5', 'BTC'))
Exemple #3
0
    def test_get_executable_no_sell_balance_b(self):
        cross = arbitrage.detect_cross(self.basic_ob_2(), self.basic_ob_1())

        cross.volume.should.equal(Money('1', 'BTC'))
        cross.revenue.should.equal(Money('1', 'USD'))

        buy_balance = {'USD': Money('599', 'USD'), 'BTC': Money('1000000', 'BTC')}
        sell_balance = {'USD': Money('0', 'USD'), 'BTC': Money('0', 'BTC')}

        result = arbitrage.get_executable_volume(cross, buy_balance, sell_balance)

        result.should.equal(Money('0', 'BTC'))
Exemple #4
0
    def test_get_executable_half(self):
        cross = arbitrage.detect_cross(
            self.basic_ob_2(price_currency='BTC', vol_currency='ETH'),
            self.basic_ob_1(price_currency='BTC', vol_currency='ETH'),
        )

        cross.volume.should.equal(Money('1', 'ETH'))
        cross.revenue.should.equal(Money('1', 'BTC'))

        buy_balance = {'BTC': Money('299.5', 'BTC'), 'ETH': Money('1000000', 'ETH')}
        sell_balance = {'BTC': Money('0', 'BTC'), 'ETH': Money('1', 'ETH')}

        result = arbitrage.get_executable_volume(cross, buy_balance, sell_balance)

        result.should.equal(Money('0.5', 'ETH'))
Exemple #5
0
    def test_get_executable_fee_complex(self):
        self.itbit.market_order_fee = Decimal('0.0001')
        self.bitstamp.market_order_fee = Decimal('0.0001')

        cross = arbitrage.detect_cross(self.more_ob_1(), self.more_ob_2())

        cross.volume.should.equal(Money('1', 'BTC'))
        cross.revenue.should.equal(Money('0.75', 'USD'))

        buy_balance = {'USD': Money('599.25', 'USD'), 'BTC': Money('0', 'BTC')}
        sell_balance = {'USD': Money('0', 'USD'), 'BTC': Money('1', 'BTC')}

        result = arbitrage.get_executable_volume(cross, buy_balance, sell_balance)

        result.round_to_decimal_places(8, ROUND_TRUNC)\
            .should.equal(Money('0.99990005', 'BTC'))
Exemple #6
0
    def tick(self, open_orders):
        eth_crosses = arb.detect_crosses_between_many_orderbooks([
            self.harness.bitstamp_eth_eur.get_orderbook(),
            #self.harness.bitstamp_eth_btc.get_orderbook(),
            self.harness.bitstamp_eth_usd.get_orderbook(),
        ])

        for cross in eth_crosses:
            print("Cross: " + str(cross))
            executable_volume = arb.get_executable_volume(
                cross,
                cross.buy_exchange.get_balance(),
                cross.sell_exchange.get_balance(),
            )
            print("Executable Volume:" + str(executable_volume))
            if executable_volume:
                cross.buy_exchange.market_order(executable_volume, Consts.BID)
                cross.sell_exchange.market_order(executable_volume, Consts.ASK)
Exemple #7
0
    def get_test_executable_realistic_fee(self):
        self.itbit.market_order_fee = Decimal('0.0001')
        self.bitstamp.market_order_fee = Decimal('0.0001')

        cross = arbitrage.detect_cross(
            self.basic_ob_2(),
            self.basic_ob_1(),
            ignore_unprofitable=False,
        )

        cross.volume.should.equal(Money('1', 'BTC'))
        cross.revenue.should.equal(Money('1', 'USD'))

        buy_balance = {'USD': Money('599', 'USD'), 'BTC': Money('0', 'BTC')}
        sell_balance = {'USD': Money('0', 'USD'), 'BTC': Money('1', 'BTC')}

        result = arbitrage.get_executable_volume(cross, buy_balance, sell_balance)

        result.round_to_decimal_places(8).should.equal(Money('0.99990001', 'BTC'))
Exemple #8
0
    def test_get_executable_simple_fee(self):
        self.itbit.market_order_fee = 1
        self.bitstamp.market_order_fee = 1

        cross = arbitrage.detect_cross(
            self.basic_ob_2(),
            self.basic_ob_1(),
            ignore_unprofitable=False,
        )

        cross.volume.should.equal(Money('1', 'BTC'))
        cross.revenue.should.equal(Money('1', 'USD'))

        buy_balance = {'USD': Money('599', 'USD'), 'BTC': Money('0', 'BTC')}
        sell_balance = {'USD': Money('0', 'USD'), 'BTC': Money('1', 'BTC')}

        result = arbitrage.get_executable_volume(cross, buy_balance, sell_balance)

        result.should.equal(Money('0.5', 'BTC'))
    def tick(self, open_orders):

        self.logger.debug("--Strategy Tick--")
        self.logger.info("Current Orders: " + str(open_orders))

        btc_crosses = arb.detect_cross(
            self.harness.bitstamp_btc_usd.get_orderbook(),
            self.harness.bitstamp_btc_eur.get_orderbook())

        for cross in btc_crosses:
            print("Cross: " + str(cross))
            executable_volume = arb.get_executable_volume(
                cross,
                cross.buy_exchange.get_balance(),
                cross.sell_exchange.get_balance(),
            )
            print("Executable Volume:" + str(executable_volume))
            if executable_volume:
                cross.buy_exchange.market_order(executable_volume, Consts.BID)
                cross.sell_exchange.market_order(executable_volume, Consts.ASK)