Exemplo n.º 1
0
def makeClient(number: int):

    #check if entity has already been created
    if (os.path.exists('./workdir/Agent_Auction/client/client' + str(number) +
                       '_private.key')):

        #locate the agent account entity for interacting with the ledger.
        with open(
                './workdir/Agent_Auction/client/client' + str(number) +
                '_private.key', 'r') as private_key_file:
            client_agentID = Entity.load(private_key_file)

    else:
        #create new entity for the agent
        client_agentID = Entity()
        #store private key of newly formed entity
        with open(
                './workdir/Agent_Auction/client/client' + str(number) +
                '_private.key', 'w') as private_key_file:
            client_agentID.dump(private_key_file)
        #give the account starting tokens
        api.sync(api.tokens.wealth(client_agentID, 1000))

    startBalance = api.tokens.balance(client_agentID)

    price = random.randint(25, 100)
    interval = random.randint(5, 20)

    # define an OEF Agent
    client = client_agent.ClientAgent(str(Address(client_agentID)),
                                      price,
                                      interval,
                                      client_agentID,
                                      oef_addr="127.0.0.1",
                                      oef_port=10000)

    print('Balance Before:', startBalance)

    # connect it to the OEF Node
    client.connect()

    # query OEF for DataService providers
    echo_query1 = Query(
        [Constraint("timezone", Eq(3)),
         Constraint("twentyfour", Eq(False))], TIME_AGENT())

    client.search_services(0, echo_query1)
    client.run()
Exemplo n.º 2
0
    else:
        #create new entity for the agent
        client_agentID = Entity()
        #store private key of newly formed entity
        with open('./workdir/Agent4/client/client_private.key', 'w') as private_key_file:
            client_agentID.dump(private_key_file)
        #give the account starting tokens
        api.sync(api.tokens.wealth(client_agentID, 2000))

    startBalance = api.tokens.balance(client_agentID)

    # define an OEF Agent
    client_agent = ClientAgent(str(Address(client_agentID)), oef_addr="127.0.0.1", oef_port=10000)

    print('Balance Before:', startBalance)

    highest_price = 1700
    if highest_price > api.tokens.balance(client_agentID):
        highest_price = api.tokens.balance(client_agentID)
    currentPrice = 0

    # connect it to the OEF Node
    client_agent.connect()

    # query OEF for DataService providers
    echo_query1 = Query([Constraint("timezone", Eq(3)), Constraint("twentyfour", Eq(False))],TIME_AGENT())


    client_agent.search_services(0, echo_query1)
    client_agent.run()
Exemplo n.º 3
0
    else:
        #create the enity for the agent
        server_agentID = Entity()
        #store the private key of the newly created entity
        with open('./workdir/Agent_Auction/agent/server_private.key', 'w') as private_key_file:
            server_agentID.dump(private_key_file)

    startBalance = api.tokens.balance(server_agentID)

    #set trading values
    price = 20
    fet_tx_fee = 40

    print('Price:', price)
    print('Balance Before:', startBalance)

    # create agent and connect it to OEF
    server_agent = Demo_Agent(str(Address(server_agentID)), oef_addr="127.0.0.1", oef_port=10000)
    server_agent.scheme['timezone'] = 3
    server_agent.scheme['id'] = str(uuid.uuid4())
    server_agent.scheme['twentyfour'] = False
    server_agent.price = price
    server_agent.startPrice = price
    timeout = 2
    server_agent.connect()
    # register a service on the OEF
    server_agent.description = Description(server_agent.scheme, TIME_AGENT())
    server_agent.register_service(0,server_agent.description)
    server_agent.run()
Exemplo n.º 4
0
                                 msg_id + 1)
                print("Accept")
            else:
                print("They don't have data")
                self.stop()

    def on_decline(self, msg_id: int, dialogue_id: int, origin: str,
                   target: int):
        print("Received a decline!")
        self.received_declines += 1


if __name__ == '__main__':

    # define an OEF Agent
    Agent_id = str(uuid.uuid4())

    print(Agent_id)
    client_agent = ClientAgent(str(uuid.uuid4()),
                               oef_addr="oef.economicagents.com",
                               oef_port=3333)

    # connect it to the OEF Node
    client_agent.connect()

    # query OEF for DataService providers
    echo_query = Query([Constraint("timezone", Eq(2))], TIME_AGENT())

    client_agent.search_services(0, echo_query)
    client_agent.run()
Exemplo n.º 5
0
        #store private key of newly formed entity
        with open('./workdir/Agent3/client/client_private.key',
                  'w') as private_key_file:
            client_agentID.dump(private_key_file)
        #give the account starting tokens
        api.sync(api.tokens.wealth(client_agentID, 1000))

    startBalance = api.tokens.balance(client_agentID)

    highest_price = 999

    # define an OEF Agent
    client_agent = ClientAgent(str(Address(client_agentID)),
                               highest_price,
                               client_agentID,
                               oef_addr="127.0.0.1",
                               oef_port=10000)

    print('Balance Before:', startBalance)

    # connect it to the OEF Node
    client_agent.connect()

    # query OEF for DataService providers
    echo_query1 = Query(
        [Constraint("timezone", Eq(3)),
         Constraint("twentyfour", Eq(False))], TIME_AGENT())

    client_agent.search_services(0, echo_query1)
    client_agent.run()