def setUp(self): TestSputnik.setUp(self) from sputnik import cashier from sputnik import accountant self.accountant = accountant.CashierExport(FakeComponent("accountant")) self.bitcoinrpc = {'BTC': FakeBitcoin()} self.compropago = FakeComponent() self.bitgo = FakeBitgo() self.sendmail = FakeSendmail('*****@*****.**') from tempfile import mkstemp import json keyfile = mkstemp(prefix="bitgo_key")[1] with open(keyfile, "w") as f: json.dump({'passphrase': 'NULL'}, f) self.cashier = cashier.Cashier( self.session, self.accountant, self.bitcoinrpc, self.compropago, cold_wallet_period=None, sendmail=self.sendmail, template_dir="../server/sputnik/admin_templates", minimum_confirmations=6, bitgo=self.bitgo, bitgo_private_key_file=keyfile, alerts=FakeComponent("alerts")) self.administrator_export = cashier.AdministratorExport(self.cashier) self.webserver_export = cashier.WebserverExport(self.cashier) self.accountant_export = cashier.AccountantExport(self.cashier) self.compropago_hook = cashier.CompropagoHook(self.cashier) self.bitcoin_notify = cashier.BitcoinNotify(self.cashier)
def test_get_order_book(self): order_bid = self.create_order(1, 100, -1) order_ask = self.create_order(1, 105, 1) self.engine.place_order(order_bid) self.engine.place_order(order_ask) order_book = self.administrator_export.get_order_book() self.assertTrue( FakeComponent.check( { 'BUY': { 1: { 'errors': "", 'id': 1, 'price': 100, 'quantity': 1, 'quantity_left': 1, 'username': None } }, 'SELL': { 2: { 'errors': "", 'id': 2, 'price': 105, 'quantity': 1, 'quantity_left': 1, 'username': None } } }, order_book))
def setUp(self): TestNotifier.setUp(self) from sputnik import engine2 from sputnik import accountant self.accountant = accountant.EngineExport(FakeComponent("accountant")) self.accountant_notifier = engine2.AccountantNotifier( self.engine, self.accountant, self.contract)
def test_ask(self): order = self.create_order(1, 100, 1) # make a copy of the order to compare against order2 = self.create_order(1, 100, 1) self.engine.place_order(order) self.assertTrue(FakeComponent.check(self.engine.orderbook, {-1: [], 1: [order2]})) self.assertTrue(self.fake_listener.component.check_for_calls([('on_queue_success', (order2,), {})]))
def setUp(self): TestNotifier.setUp(self) from sputnik import engine2 self.webserver = FakeComponent() self.webserver_notifier = engine2.WebserverNotifier(self.engine, self.webserver, self.contract, reg_publish=False)
def setUp(self): TestSputnik.setUp(self) from sputnik import engine2 self.engine = engine2.Engine() self.fake_listener = FakeComponent("listener") self.engine.add_listener(self.fake_listener) self.order_counter = 0 self.administrator_export = engine2.AdministratorExport(self.engine)
def test_no_trade(self): order_bid = self.create_order(1, 100, -1) order_ask = self.create_order(1, 105, 1) self.engine.place_order(order_bid) self.engine.place_order(order_ask) self.assertTrue(FakeComponent.check(self.engine.orderbook, {-1: [order_bid], 1: [order_ask]})) self.assertTrue(self.fake_listener.component.check_for_calls([('on_queue_success', (order_bid,), {}), ('on_queue_success', (order_ask,), {})]))
def test_ask(self): order = self.create_order(1, 100, 1) # make a copy of the order to compare against order2 = self.create_order(1, 100, 1) self.engine.place_order(order) self.assertTrue( FakeComponent.check(self.engine.orderbook, { -1: [], 1: [order2] })) self.assertTrue( self.fake_listener.component.check_for_calls([('on_queue_success', (order2, ), {})]))
def test_no_trade(self): order_bid = self.create_order(1, 100, -1) order_ask = self.create_order(1, 105, 1) self.engine.place_order(order_bid) self.engine.place_order(order_ask) self.assertTrue( FakeComponent.check(self.engine.orderbook, { -1: [order_bid], 1: [order_ask] })) self.assertTrue( self.fake_listener.component.check_for_calls([ ('on_queue_success', (order_bid, ), {}), ('on_queue_success', (order_ask, ), {}) ]))
def test_get_order_book(self): order_bid = self.create_order(1, 100, -1) order_ask = self.create_order(1, 105, 1) self.engine.place_order(order_bid) self.engine.place_order(order_ask) order_book = self.administrator_export.get_order_book() self.assertTrue(FakeComponent.check( {'BUY': {1: {'errors': "", 'id': 1, 'price': 100, 'quantity': 1, 'quantity_left': 1, 'username': None}}, 'SELL': {2: {'errors': "", 'id': 2, 'price': 105, 'quantity': 1, 'quantity_left': 1, 'username': None}}}, order_book))
def test_trade_crossed(self): order_bid = self.create_order(1, 100, -1) order_bid2 = self.create_order(1, 100, -1) order_bid3 = self.create_order(1, 100, -1) order_bid3.quantity_left = 0 order_ask = self.create_order(1, 95, 1) order_ask2 = self.create_order(1, 95, 1) order_ask2.quantity_left = 0 self.engine.place_order(order_bid) self.engine.place_order(order_ask) self.assertTrue( FakeComponent.check(self.engine.orderbook, { -1: [], 1: [] })) self.assertTrue( self.fake_listener.component.check_for_calls([ ('on_queue_success', (order_bid2, ), {}), ('on_trade_success', (order_ask2, order_bid3, 100, 1), {}) ]))
def test_trade_crossed(self): order_bid = self.create_order(1, 100, -1) order_bid2 = self.create_order(1, 100, -1) order_bid3 = self.create_order(1, 100, -1) order_bid3.quantity_left = 0 order_ask = self.create_order(1, 95, 1) order_ask2 = self.create_order(1, 95, 1) order_ask2.quantity_left = 0 self.engine.place_order(order_bid) self.engine.place_order(order_ask) self.assertTrue(FakeComponent.check(self.engine.orderbook, {-1: [], 1: []})) self.assertTrue(self.fake_listener.component.check_for_calls([('on_queue_success', (order_bid2,), {}), ('on_trade_success', ( order_ask2, order_bid3, 100, 1), {})]))