Exemplo n.º 1
0
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.ws = BitmexWsClient(test=False)
        self.ws.start()

        self.setup_ui()

        self.ws.sig_connected.connect(self.ws_connected)
Exemplo n.º 2
0
    def test_is_http_instance(self):
        client = BitmexWsClient(
            test=True,
            api_key=api_key,
            api_secret=api_secret,
        )

        assert issubclass(BitmexWsClient, WsClient)

        client.close()
Exemplo n.º 3
0
    def test_instance_by_api_key(self):
        client = BitmexWsClient(test=True,
                                api_key=api_key,
                                api_secret=api_secret)

        assert isinstance(client, BitmexWsClient)
        assert client.test is True
        assert client.api_key is api_key
        assert client.api_secret is api_secret

        client.close()
Exemplo n.º 4
0
    def test_pong(self, qtbot):
        client = BitmexWsClient(test=True,
                                api_key=api_key,
                                api_secret=api_secret)
        with qtbot.waitSignal(client.sig_message, timeout=10000) as blocking:
            client.start()

        assert blocking.signal_triggered

        connected = client.json()
        assert type(connected) == dict
        assert 'info' in connected
        assert 'version' in connected
        assert 'timestamp' in connected
        assert 'docs' in connected
        assert 'limit' in connected

        with qtbot.waitSignal(client.sig_message, timeout=10000) as blocking:
            client.ping()

        assert blocking.signal_triggered
        assert type(client.data()) == str
        assert client.data() == 'pong'
Exemplo n.º 5
0
    def test_data(self, qtbot):
        client = BitmexWsClient(test=True,
                                api_key=api_key,
                                api_secret=api_secret)
        with qtbot.waitSignal(client.sig_message, timeout=10000) as blocking:
            client.start()

        assert blocking.signal_triggered

        connected = client.json()
        assert type(connected) == dict
        assert 'info' in connected
        assert 'version' in connected
        assert 'timestamp' in connected
        assert 'docs' in connected
        assert 'limit' in connected

        with qtbot.waitSignal(client.sig_message, timeout=10000) as blocking:
            client.send({"op": "subscribe", "args": ["trade:XBTUSD"]})

        assert blocking.signal_triggered

        print(client.data())
Exemplo n.º 6
0
    def test_connect(self, qtbot):
        client = BitmexWsClient(test=True,
                                api_key=api_key,
                                api_secret=api_secret)

        with qtbot.waitSignals([client.sig_message],
                               order="strict",
                               timeout=10000) as blocking:
            client.start()

        assert blocking.signal_triggered

        data = client.data()
        assert type(data) == str

        data = client.json()
        assert type(data) == dict
        assert 'info' in data
        assert 'version' in data
        assert 'timestamp' in data
        assert 'docs' in data
        assert 'limit' in data
        client.close()
Exemplo n.º 7
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        self.ws = BitmexWsClient(test=False)
        self.ws.start()

        self.setup_ui()

        self.ws.sig_connected.connect(self.ws_connected)

    def ws_connected(self):
        # web socket client connected

        self.ws.subscribe("trade:XBTUSD")

    def closeTab(self, index):
        tab = self.tabs.widget(index)
        tab.deleteLater()
        self.tabs.removeTab(index)

    def setup_ui(self):
        self.resize(1024, 768)
        self.setObjectName("MainWindow")
        self.setWindowTitle("BSTrade")

        self.tabs = QTabWidget()
        self.tabs.setTabBar(TabBar())
        self.tabs.setTabsClosable(True)
        self.tabs.setMovable(True)
        self.tabs.setDocumentMode(True)
        self.tabs.setUsesScrollButtons(True)
        self.tabs.tabCloseRequested.connect(self.closeTab)
        self.tabs.setStyleSheet("""
            QTabBar::tab {
                background: lightgray;
                color: black;
                border: 0;
                /* min-width: 100px; */
                max-width: 200px;
                /* width: 150px; */
                height: 12px;
                padding: 5px;
                font-size: 11px;
                border: 1px solid #ebebeb;
            }
        
            QTabBar::tab:selected {
                background: gray;
                color: white;
            }
            
        """)

        self.tabs.addTab(BSChartWidget(self), 'Big with test title')

        for i in range(10):
            self.tabs.addTab(QTextEdit(), 'text{}'.format(i))

        self.setCentralWidget(self.tabs)

        self.add_menus_and_exit()
        self.setup_dock_widgets()

    def add_menus_and_exit(self):
        # self.statusBar().showMessage('Text in statusbar')

        menubar = self.menuBar()  # create menu bar

        file_menu = menubar.addMenu('File')  # add first menu

        new_icon = QIcon('BSTrade/icons/new_icon.png')  # create icon
        new_action = QAction(new_icon, 'New', self)  # add icon to menu
        new_action.setStatusTip('New File')  # update statusBar
        file_menu.addAction(new_action)  # add Action to menu item

        file_menu.addSeparator()  # add separator line between menu items

        exit_icon = QIcon('BSTrade/icons/exit_icon.png')  # create icon
        exit_action = QAction(exit_icon, 'Exit', self)  # create Exit Action
        exit_action.setStatusTip('Click to exit the application')
        exit_action.triggered.connect(
            self.close)  # close application when clicked
        exit_action.setShortcut(
            'Ctrl+Q')  # keyboard shortcut, window has focus
        file_menu.addAction(exit_action)

        # ---------------------------------
        edit_menu = menubar.addMenu('Edit')  # add a second menu

    def setup_dock_widgets(self):
        dock1 = QDockWidget()
        dock1.setMinimumWidth(200)
        dock1.setMinimumHeight(100)
        dock1.setWindowTitle("Recent Trade")

        recent_trade_view = RecentTradeTableView(self, ws=self.ws)
        recent_trade_model = RecentTradeTableModel(self,
                                                   view=recent_trade_view)
        recent_trade_view.setModel(recent_trade_model)
        dock1.setWidget(recent_trade_view)

        self.addDockWidget(Qt.RightDockWidgetArea, dock1)

        dock2 = QDockWidget()
        dock2.setMinimumWidth(200)
        dock2.setMinimumHeight(100)
        dock2.setWindowTitle("Left dock")
        self.addDockWidget(Qt.LeftDockWidgetArea, dock2)