def get_mmp_attributes(self): mmp_attributes = self._dealer_contract.contract.functions.getMMPAttributes().call() mmp_values = utils.prepare_for_storing(mmp_attributes[0]) mmp_duals = utils.prepare_for_storing(mmp_attributes[1]) mmp_target_coefs = utils.prepare_for_storing(mmp_attributes[2]) mmp_bounds = utils.prepare_for_storing(mmp_attributes[3]) return mmp_values, mmp_duals, mmp_target_coefs, mmp_bounds
def test_prepare_for_storing(self): received_list = [100, 200, 300] received_value = 190000 prepared_list = utils.prepare_for_storing(received_list) prepared_value = utils.prepare_for_storing(received_value) self.assertIsInstance(prepared_list, np.ndarray) self.assertIsInstance(prepared_list[0], float) self.assertIsInstance(prepared_value, float)
def add_order(self, order_id, order): account = order[0] bundle = utils.prepare_for_storing(order[1]) bid = utils.prepare_for_storing(order[2]) if account in self._pool.keys(): self._pool[account].add_order(bundle, bid, order_id) else: self._pool[account] = Orders(account) self._pool[account].add_order(bundle, bid, order_id)
def accept_trade(self): if (self._accept_trade): trade = self._dealer_contract.contract.functions.acceptTrade( self._accept_trade).call({'from': self._account_address}) self._trade = utils.prepare_for_storing(trade) self._dealer_contract.contract.functions.acceptTrade( self._accept_trade).transact({'from': self._account_address})
def calculate_own_trade(self): trades_accounts = self._dealer_contract.contract.functions.getTradesAccounts( ).call() # get lookup table of all accounts which have a trade trades = [ self._dealer_contract.contract.functions.getTrade(account).call() for account in trades_accounts ] trades = [ utils.prepare_for_storing(trade) for trade in trades if trade ] trades = [np.array(trade) for trade in trades] self._trade = sum(trades)
def get_mkt_prices(self): mkt_prices = self._dealer_contract.contract.functions.getMktPrices().call() self._mkt_prices = utils.prepare_for_storing(mkt_prices)
def get_trade(self): bill = utils.from_ether_to_wei(self._bill) trade = self._dealer_contract.contract.functions.getTrade().call({'from': self._account_address, 'value': bill}) self._trade = utils.prepare_for_storing(trade) self._dealer_contract.contract.functions.getTrade().transact({'from': self._account_address, 'value': bill})
def get_resource_inventory(self): resource_inventory = self._dealer_contract.contract.functions.getResourceInventory( ).call() return utils.prepare_for_storing(resource_inventory)