def load_from_file(f): rows_count, slots_per_row, unavailable_count, pool_count, server_count = map(int, f.readline().split()) data_center = DataCenter(rows_count, slots_per_row) for i in xrange(unavailable_count): row_id, slot_id = map(int, f.readline().split()) data_center.set(row_id, slot_id, UnavailableSlot()) servers = [map(int, f.readline().split()) for i in xrange(server_count)] servers = [Server(i, size, capacity) for i, (size, capacity) in enumerate(servers)] f.seek(0) return rows_count, slots_per_row, unavailable_count, pool_count, server_count, servers, data_center
def main( pair: str, depth: int, theta: float, window_size: int, sleep_seconds: int, position_size: float, ): """ Load and log price information from kraken """ sobi_strategy = SobiStrategy(window_size=window_size, theta=theta, depth=depth, position_size=position_size) backtester = Backtest() data_center = DataCenter(pair=pair) while True: # query latest data from exchange market_state = data_center.get_market_data() # update indicators and signals sobi_strategy.update_market_state(current_state=market_state) desired_position = sobi_strategy.desired_position # create orders and calculate pnl backtester.update_market_state(market_state) backtester.rebalance_position(desired_position) pnl = backtester.get_current_profit() last_order = backtester.get_last_order() # log output to console log_info = dict( time_rfc=market_state["time"], midprice=market_state["order_book"].midprice, best_bid=market_state["order_book"].best_bid, best_ask=market_state["order_book"].best_ask, **sobi_strategy.indicators, **sobi_strategy.signals, last_order=last_order, pnl=pnl, ) log_msg = ut.get_log_msg(log_info) logging.info(log_msg) # conform to krakens call rate limit time.sleep(sleep_seconds)
def main( pair: str, strategy: Strategy, ): """ Initialize context and run the given stragety """ backtester = Backtest() data_center = DataCenter(pair=pair) while True: run_iteration(pair=pair, strategy=strategy, engine=backtester, data_center=data_center)
def run_iteration(pair: str, strategy: Strategy, engine: Backtest, data_center: DataCenter): """ Run one round trip --> Gather and updat data --> Recalculate strategy indicators and signals --> rebalance position if necessary """ # query latest data from exchange market_state = data_center.get_market_data() # update indicators and signals strategy.update_market_state(current_state=market_state) desired_position = strategy.desired_position # create orders and calculate pnl engine.update_market_state(market_state) engine.rebalance_position(desired_position) pnl = engine.get_current_profit() last_order = engine.get_last_order() # log output to console log_info = dict( time_rfc=market_state["time"], midprice=market_state["order_book"].midprice, best_bid=market_state["order_book"].best_bid, best_ask=market_state["order_book"].best_ask, **strategy.indicators, current_signal=strategy.trade_signal, last_order=last_order, pnl=pnl, ) log_msg = ut.get_log_msg(log_info) logging.info(log_msg) # conform to krakens call rate limit time.sleep(strategy.sleep_seconds)
import time from db_helper import DBHelper from data_center import DataCenter from Utils import utils if __name__ == "__main__": db = DBHelper() dc = DataCenter(db) last_day = "" while True: if last_day == "": last_day = db.get_max_day() day = str(utils.today()) if day != last_day: dc.record(day) last_day = day time.sleep(60)
if not self.vm.resetMachine(vmId): break EventManager.trigger( Event('Socket.addReply.' + clientId, Message(cmd=Message.CMD_RESET_VM_OK))) return True Log.e("重启虚拟机失败") class ExternalManager(QObject): EXTERNAL_SERVER_PORT = 22333 def __init__(self, parent=None): QObject.__init__(self, parent) self.server = Server(self.EXTERNAL_SERVER_PORT) self.dispatcher = ExternalDispatcher(self.server) self.server.setDispatcher(self.dispatcher) def start(self): self.server.start() if __name__ == '__main__': from PyQt5.QtCore import * import sys from data_center import DataCenter app = QCoreApplication(sys.argv) dC = DataCenter() s = ExternalManager() s.start() app.exec_()