Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.check_db_connection()
# Main event queue.
self.events = queue.Queue(0)
# Producer/consumer worker classes.
self.data = Datahandler(self.exchanges, self.logger, self.db_prices,
self.db_client)
self.strategy = Strategy(self.exchanges, self.logger, self.db_prices,
self.db_other, self.db_client)
self.portfolio = Portfolio(self.exchanges, self.logger, self.db_other,
self.db_client, self.strategy.models)
self.broker = Broker(self.exchanges, self.logger, self.db_other,
self.db_client, self.live_trading)
# Processing performance tracking variables.
self.start_processing = None
self.end_processing = None
self.cycle_count = 0
self.run()
def update(self):
"""Returns: void
Replace the candles with the most recent ones available.
Algorithm for minimizing number of updated candles:
Get the time difference from chart end to now.
If the time difference is greater than the width of the chart,
request candles.
else,
request candles from end of chart to now.
"""
new_history = None
if self.get_lag() > self.get_time_span():
# replace all candles
new_history = Broker.get_instrument_history(
instrument=self._instrument,
granularity=self._granularity,
count=self.get_size(),
to=datetime.datetime.utcnow()
)
else:
# request new candles starting from end of chart
# TODO verify candleFormat is same as existing chart
new_history_ = broker.get_instrument_history(
instrument=self._instrument,
granularity=self._granularity,
from_time=self.get_end_timestamp
)
if new_history == None:
Log.write('chart.py update(): Failed to get new candles.')
raise Exception
self.poller.unregister(self.workers_query)
if __name__ == '__main__':
import optparse
parser = optparse.OptionParser()
parser.add_option("-t", "--tries", dest="tries",
help="Number of tries (default: infinite)",
action="store", type="int", default=None)
parser.add_option("-T", "--timeout", dest="timeout",
help="Timeout in seconds (default: none)",
action="store", type="float", default=None)
parser.usage = "%prog [options] requestsAddr workersAddr answersAddr"
(options, args) = parser.parse_args()
if len(args) != 3:
parser.error("incorrect number of arguments")
b = Broker(zmq.Context(1), options.timeout, options.tries, *args)
b.run()
granularity=None, # string - See Oanda's documentation
count=None, # int - number of candles
start=None, # datetime - UTC
end=None, # datetime - UTC
price='MBA', # string
include_first=None, # bool
daily_alignment=None, # int
alignment_timezone=None, # string - timezone
weekly_alignment=None
):
self._candles = []
# verify instance of by accessing a member.
if in_instrument.get_id() == 0:
pass
# get candles from broker
instrument_history = Broker.get_instrument_history(
instrument=in_instrument,
granularity=granularity,
count=count,
from_time=start,
to=end,
price=price,
include_first=include_first,
daily_alignment=daily_alignment,
alignment_timezone=alignment_timezone,
weekly_alignment=weekly_alignment
)
if instrument_history == None:
Log.write('chart.py __init__(): Failed to get instrument history.')
raise Exception
else:
candles_raw = instrument_history['candles']
def __init__(self,
registry_type=Registry,
broker_means=dists.normal(0.05),
**kw):
super(MdsModel, self).__init__(**kw)
regions = self.graph.regions
self.regions = [i for i in range(regions[0]*regions[1])]
self.brokers = dict()
for r in self.regions:
node = self.random_region_node(r)
node.server.service_time = self.service_dist(broker_means())
broker = Broker(
r,
node,
registry_type(),
60,
self.brokers)
# give them an intitial picture of the grid
for node in self.graph.nodes_in_region(r):
state = ResourceState(node.resource_agent, node.resource.free)
broker.registry.update_state(state)
self.brokers[r] = broker
for node in self.graph.nodes_iter():
node.broker = self.brokers[node.region]
# this nodes resource agent