def test_margin_available_for_multi_asset_account(self): # Arrange event = AccountState( AccountId("SIM", "001"), [Money("10.00000000", BTC), Money("20.00000000", ETH)], [Money("10.00000000", BTC), Money("20.00000000", ETH)], [Money("0.00000000", BTC), Money("0.00000000", ETH)], info={}, # No default currency set event_id=uuid4(), event_timestamp=UNIX_EPOCH, ) account = Account(event) # Wire up account to portfolio account.register_portfolio(self.portfolio) self.portfolio.register_account(account) # Act result1 = account.margin_available(BTC) account.update_initial_margin(Money("0.00010000", BTC)) result2 = account.margin_available(BTC) account.update_maint_margin(Money("0.00020000", BTC)) result3 = account.margin_available(BTC) result4 = account.margin_available(ETH) # Assert self.assertEqual(Money("10.00000000", BTC), result1) self.assertEqual(Money("9.99990000", BTC), result2) self.assertEqual(Money("9.99970000", BTC), result3) self.assertEqual(Money("20.00000000", ETH), result4)
def test_margin_available_for_single_asset_account(self): # Arrange event = AccountState( AccountId("SIM", "001"), [Money("100000.00", USD)], [Money("0.00", USD)], [Money("0.00", USD)], info={"default_currency": "USD"}, # No default currency set event_id=uuid4(), event_timestamp=UNIX_EPOCH, ) account = Account(event) # Wire up account to portfolio account.register_portfolio(self.portfolio) self.portfolio.register_account(account) # Act result1 = account.margin_available() account.update_initial_margin(Money("500.00", USD)) result2 = account.margin_available() account.update_maint_margin(Money("1000.00", USD)) result3 = account.margin_available() # Assert self.assertEqual(Money("100000.00", USD), result1) self.assertEqual(Money("99500.00", USD), result2) self.assertEqual(Money("98500.00", USD), result3)
def test_update_initial_margin(self): # Arrange event = AccountState( AccountId("SIM", "001"), [Money("10.00000000", BTC), Money("20.00000000", ETH)], [Money("10.00000000", BTC), Money("20.00000000", ETH)], [Money("0.00000000", BTC), Money("0.00000000", ETH)], info={}, # No default currency set event_id=uuid4(), event_timestamp=UNIX_EPOCH, ) # Act account = Account(event) # Wire up account to portfolio account.register_portfolio(self.portfolio) self.portfolio.register_account(account) margin = Money("0.00100000", BTC) # Act account.update_initial_margin(margin) # Assert self.assertEqual(margin, account.initial_margin(BTC)) self.assertEqual({BTC: margin}, account.initial_margins())
def test_margin_available_for_multi_asset_account(self): # Arrange event = AccountState( account_id=AccountId("SIM", "001"), account_type=AccountType.CASH, base_currency=None, # Multi-currency reported=True, balances=[ AccountBalance( BTC, Money(10.00000000, BTC), Money(0.00000000, BTC), Money(10.00000000, BTC), ), AccountBalance( ETH, Money(20.00000000, ETH), Money(0.00000000, ETH), Money(20.00000000, ETH), ), ], info={}, # No default currency set event_id=uuid4(), ts_updated_ns=0, timestamp_ns=0, ) account = Account(event) # Wire up account to portfolio account.register_portfolio(self.portfolio) self.portfolio.register_account(account) # Act result1 = account.margin_available(BTC) account.update_initial_margin(Money(0.00010000, BTC)) result2 = account.margin_available(BTC) account.update_maint_margin(Money(0.00020000, BTC)) result3 = account.margin_available(BTC) result4 = account.margin_available(ETH) # Assert self.assertEqual(Money(10.00000000, BTC), result1) self.assertEqual(Money(9.99990000, BTC), result2) self.assertEqual(Money(9.99970000, BTC), result3) self.assertEqual(Money(20.00000000, ETH), result4)
def test_update_initial_margin(self): # Arrange event = AccountState( account_id=AccountId("SIM", "001"), account_type=AccountType.CASH, base_currency=None, # Multi-currency reported=True, balances=[ AccountBalance( BTC, Money(10.00000000, BTC), Money(0.00000000, BTC), Money(10.00000000, BTC), ), AccountBalance( ETH, Money(20.00000000, ETH), Money(0.00000000, ETH), Money(20.00000000, ETH), ), ], info={}, # No default currency set event_id=uuid4(), ts_updated_ns=0, timestamp_ns=0, ) # Act account = Account(event) # Wire up account to portfolio account.register_portfolio(self.portfolio) self.portfolio.register_account(account) margin = Money(0.00100000, BTC) # Act account.update_initial_margin(margin) # Assert self.assertEqual(margin, account.initial_margin(BTC)) self.assertEqual({BTC: margin}, account.initial_margins())
def test_margin_available_for_single_asset_account(self): # Arrange event = AccountState( account_id=AccountId("SIM", "001"), account_type=AccountType.CASH, base_currency=USD, reported=True, balances=[ AccountBalance( USD, Money(100000.00, USD), Money(0.00, USD), Money(100000.00, USD), ), ], info={}, event_id=uuid4(), ts_updated_ns=0, timestamp_ns=0, ) account = Account(event) # Wire up account to portfolio account.register_portfolio(self.portfolio) self.portfolio.register_account(account) # Act result1 = account.margin_available() account.update_initial_margin(Money(500.00, USD)) result2 = account.margin_available() account.update_maint_margin(Money(1000.00, USD)) result3 = account.margin_available() # Assert self.assertEqual(Money(100000.00, USD), result1) self.assertEqual(Money(99500.00, USD), result2) self.assertEqual(Money(98500.00, USD), result3)