Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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)


Exemple #4
0
                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_()