Is this possible?
A general purpose multi-agent system
Have you met GIL?
ØMQ is very cool - If you don't have a project that needs it... ¡create one!
Agents are independent, but they must know the addresses of other agents
from osbrain import random_nameserver
from osbrain import run_agent
def hello_world(agent):
agent.log_info('Hello world!')
if __name__ == '__main__':
# System deployment
ns = random_nameserver()
agent = run_agent('Agent0', nsaddr=ns)
# System configuration
agent.set_method(iddle=hello_world)
from osbrain import random_nameserver
from osbrain import run_agent
def log_message(agent, message):
agent.log_info('received: %s' % message)
def hello_world(agent):
agent.log_info('Sending message...')
agent.send('push', 'Hello, world!')
if __name__ == '__main__':
# System deployment
ns = random_nameserver()
pusher = run_agent('Pusher', nsaddr=ns)
puller = run_agent('Puller', nsaddr=ns)
# System configuration
addr = pusher.bind('PUSH', alias='push')
pusher.set_method(iddle=hello_world)
puller.connect(addr, handler=log_message)
from osbrain import random_nameserver
from osbrain import run_agent
from osbrain import BaseAgent
class Push(BaseAgent):
def on_init(self):
self.bind('PUSH', alias='push')
def iddle(self):
self.log_info('Sending message...')
self.send('push', 'Hello, world!')
def log_message(agent, message):
agent.log_info('received: %s' % message)
if __name__ == '__main__':
# System deployment
ns = random_nameserver()
pusher = run_agent('Pusher', nsaddr=ns, base=Push)
puller = run_agent('Puller', nsaddr=ns)
# System configuration
puller.connect(pusher.addr('push'), handler=log_message)
from osmarkets.brain import Brain
from osmarkets.architecture import OandaArchitecture
class Example(Brain):
def on_new_bar(self, series):
# Algorithm
if series[0].close > series[1].close:
side = 'buy'
else:
side = 'sell'
# Order
self.send_order(side=side,
size=100,
symbol=series.bsid.symbol)
if __name__ == '__main__':
system = OandaArchitecture(logging=True,
account_id=123456,
access_token='123abc-345def',
environment='live')
system.stream(['EUR_USD'])
system.add_brain('example', base=Example)
system['example'].set_attr(DEBUG=True)
system['example'].subscribe(('EUR_USD', 1, 'Minutes'), 100)
♥ Python ♥