├── VERSION ├── src ├── DEBIAN │ ├── dirs │ ├── control │ └── postinst ├── opt │ └── swiftbot │ │ ├── build_version │ │ ├── core-version.txt │ │ ├── .gitignore │ │ ├── bin │ │ ├── workers │ │ ├── swift-bot │ │ ├── swift-orderbooks-proxy │ │ └── swift-arbitrage-api-node │ │ ├── ccfinance.py │ │ ├── config.conf.default │ │ ├── _config.conf │ │ └── wampstatus └── etc │ └── systemd │ └── system │ ├── swift-bot.service │ ├── swift-worker-logs.service │ ├── swift-worker-orders.service │ ├── swift-worker-balances.service │ ├── swift-orderbooks-proxy.service │ ├── swift-worker-settingshost.service │ ├── swift-api.service │ └── crossbar.service ├── qmsgpack ├── doc │ ├── rsync_exclude │ ├── .gitignore │ ├── requirements.txt │ ├── index.rst │ ├── CHANGELOG_sphinx_deployment.md │ ├── LICENSE_sphinx_deployment │ ├── stream.rst │ ├── install.rst │ └── basics.rst ├── qmsgpack.pro ├── .gitignore ├── tests │ ├── tests.pri │ ├── pack │ │ ├── pack.pro │ │ └── CMakeLists.txt │ ├── mixed │ │ ├── mixed.pro │ │ └── CMakeLists.txt │ ├── stream │ │ ├── stream.pro │ │ └── CMakeLists.txt │ ├── unpack │ │ ├── unpack.pro │ │ └── CMakeLists.txt │ ├── qttypes │ │ ├── qttypes.pro │ │ └── CMakeLists.txt │ ├── tests.pro │ ├── CMakeLists.txt │ └── big │ │ ├── CMakeLists.txt │ │ └── big.cpp ├── PVS_HOWTO ├── src │ ├── msgpack_export.h │ ├── msgpackcommon.cpp │ ├── stream │ │ ├── location.h │ │ ├── geometry.h │ │ ├── time.h │ │ ├── location.cpp │ │ └── geometry.cpp │ ├── msgpack.h │ ├── src.pro │ ├── CMakeLists.txt │ ├── private │ │ ├── qt_types_p.h │ │ ├── pack_p.h │ │ └── unpack_p.h │ ├── msgpackcommon.h │ └── msgpackcommon.h.in ├── .travis.yml ├── cmake_uninstall.cmake.in ├── qmsgpack.pri ├── LICENSE ├── msgpack.org.md ├── README.md └── CMakeLists.txt ├── swift-lib ├── libswift-lib.so ├── libswift-lib.so.1 ├── libswift-lib.so.2 ├── libswift-lib.so.1.1 ├── libswift-lib.so.2.1 ├── .gitignore ├── libswift-lib.so.1.1.0 ├── libswift-lib.so.2.1.0 ├── ordermodel.cpp ├── withdrawparams.cpp ├── swiftapiparser.cpp ├── withdrawparams.h ├── apircpclient.h ├── swiftapiparserlakebtc.h ├── swiftapiparserlivecoin.h ├── swiftapiparserbinance.h ├── ordermodel.h ├── swiftapiparserbittrex.h ├── swiftapiparsercexio.h ├── swiftapiparserlbank.h ├── swiftapiparserkucoin.h ├── swiftapiparserexmo.h ├── apircpclient.cpp ├── swiftapiparseridcm.h ├── settingshostcomponent.h ├── swiftapiparserhitbtc.h ├── swiftapiparser.h ├── swiftapiparserkraken.h ├── orderbooksclient.h ├── swiftapiparserhuobi.h ├── swiftapiparserokcoin.h ├── swiftapiparserzb.h ├── orderparams.h ├── settingshostcomponent.cpp ├── swiftapiparserbitfinex.h ├── asyncrcpcallerinterface.h ├── wampclient.h ├── swiftapiparserlbank.cpp ├── swiftapiclientlivecoin.h ├── ordersstorage.h ├── swiftworker.h ├── swiftapiclientcexio.h ├── orderbooksclient.cpp ├── swiftapiclientlbank.h ├── swiftapiclientkucoin.h ├── swiftapiclientexmo.h ├── swiftapiclientidcm.h ├── swiftapiclientbittrex.h ├── swiftapiclientbitfinex.h ├── systemevent.h ├── swiftapiclienthitbtc.h ├── swiftapiclientkraken.h ├── swiftapiclientokcoin.h ├── swiftapiclientzb.h ├── swiftapiclienthuobi.h ├── swiftapiclientlakebtc.h ├── systemevent.cpp └── swift-lib.pro ├── swift-bot ├── .gitignore ├── swift-bot ├── addresswatcher.cpp ├── arbitrageworker.cpp ├── arbitrageworker.h ├── orderbookskeeper.h ├── swift-bot.pro ├── moneyshiftmanager.h ├── userstatuskeeper.h ├── order.h ├── wampproxy.h ├── ordersmanager.h ├── addresswatcher.h └── wampproxy.cpp ├── swift-orderbooks-proxy ├── .gitignore ├── swift-orderbooks-proxy ├── rateswriter.h ├── swift-orderbooks-proxy.pro ├── nodescontroller.h ├── rateswriter.cpp └── orderbooksnode.h ├── swift-arbitrage-api-node ├── .gitignore ├── qt_conf.qrc ├── swift-arbitrage-api-node ├── procwrapper.h ├── swift-arbitrage-api-node.pro ├── procwrapper.cpp └── apiemulator.h ├── workers ├── workers ├── userhistoryworker.cpp ├── userhistoryworker.h ├── dbwriter.h ├── workers.pro ├── logsworker.h ├── strategyworker.h ├── strategyworker.cpp ├── settingshostworker.h ├── orderworker.h └── ordersworker.h ├── DockerBuild └── Dockerfile ├── .gitlab-ci.yml ├── swift-bot-2.pro ├── .gitignore ├── DockerBuildBase └── Dockerfile ├── swift-bot.wiki └── .idea │ └── modules.xml ├── Dockerfile └── SECURITY.md /VERSION: -------------------------------------------------------------------------------- 1 | 2.0.2061 2 | -------------------------------------------------------------------------------- /src/DEBIAN/dirs: -------------------------------------------------------------------------------- 1 | /opt/swiftbot 2 | -------------------------------------------------------------------------------- /qmsgpack/doc/rsync_exclude: -------------------------------------------------------------------------------- 1 | .git 2 | -------------------------------------------------------------------------------- /src/opt/swiftbot/build_version: -------------------------------------------------------------------------------- 1 | 2.0.2061 2 | -------------------------------------------------------------------------------- /src/opt/swiftbot/core-version.txt: -------------------------------------------------------------------------------- 1 | 2.0.1297 2 | -------------------------------------------------------------------------------- /swift-lib/libswift-lib.so: -------------------------------------------------------------------------------- 1 | libswift-lib.so.2.1.0 -------------------------------------------------------------------------------- /swift-lib/libswift-lib.so.1: -------------------------------------------------------------------------------- 1 | libswift-lib.so.1.1.0 -------------------------------------------------------------------------------- /swift-lib/libswift-lib.so.2: -------------------------------------------------------------------------------- 1 | libswift-lib.so.2.1.0 -------------------------------------------------------------------------------- /qmsgpack/doc/.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | !Makefile 3 | -------------------------------------------------------------------------------- /swift-lib/libswift-lib.so.1.1: -------------------------------------------------------------------------------- 1 | libswift-lib.so.1.1.0 -------------------------------------------------------------------------------- /swift-lib/libswift-lib.so.2.1: -------------------------------------------------------------------------------- 1 | libswift-lib.so.2.1.0 -------------------------------------------------------------------------------- /src/opt/swiftbot/.gitignore: -------------------------------------------------------------------------------- 1 | plugins 2 | lib 3 | *.sql 4 | -------------------------------------------------------------------------------- /swift-bot/.gitignore: -------------------------------------------------------------------------------- 1 | *.conf 2 | *.o 3 | moc_* 4 | 5 | -------------------------------------------------------------------------------- /swift-lib/.gitignore: -------------------------------------------------------------------------------- 1 | *.conf 2 | *.o 3 | moc_* 4 | 5 | -------------------------------------------------------------------------------- /swift-orderbooks-proxy/.gitignore: -------------------------------------------------------------------------------- 1 | *.conf 2 | *.o 3 | moc_* 4 | 5 | -------------------------------------------------------------------------------- /swift-arbitrage-api-node/.gitignore: -------------------------------------------------------------------------------- 1 | *.conf 2 | *.o 3 | moc_* 4 | 5 | -------------------------------------------------------------------------------- /qmsgpack/qmsgpack.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | src 5 | -------------------------------------------------------------------------------- /workers/workers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/workers/workers -------------------------------------------------------------------------------- /swift-bot/swift-bot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/swift-bot/swift-bot -------------------------------------------------------------------------------- /qmsgpack/.gitignore: -------------------------------------------------------------------------------- 1 | *.pro.user* 2 | build 3 | lib 4 | Makefile* 5 | *.autosave 6 | bin/ 7 | *.o 8 | -------------------------------------------------------------------------------- /src/opt/swiftbot/bin/workers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/src/opt/swiftbot/bin/workers -------------------------------------------------------------------------------- /src/opt/swiftbot/bin/swift-bot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/src/opt/swiftbot/bin/swift-bot -------------------------------------------------------------------------------- /swift-lib/libswift-lib.so.1.1.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/swift-lib/libswift-lib.so.1.1.0 -------------------------------------------------------------------------------- /swift-lib/libswift-lib.so.2.1.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/swift-lib/libswift-lib.so.2.1.0 -------------------------------------------------------------------------------- /qmsgpack/tests/tests.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += ../../src 2 | LIBS += -L$$shadowed($$PWD/../bin) -l$$qtLibraryTarget(qmsgpack) 3 | -------------------------------------------------------------------------------- /qmsgpack/doc/requirements.txt: -------------------------------------------------------------------------------- 1 | # pip requirements for docs generation 2 | # pip install -r docs/requirements.txt 3 | 4 | Sphinx -------------------------------------------------------------------------------- /swift-lib/ordermodel.cpp: -------------------------------------------------------------------------------- 1 | #include "ordermodel.h" 2 | 3 | OrderModel::OrderModel(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/opt/swiftbot/bin/swift-orderbooks-proxy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/src/opt/swiftbot/bin/swift-orderbooks-proxy -------------------------------------------------------------------------------- /src/opt/swiftbot/bin/swift-arbitrage-api-node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/src/opt/swiftbot/bin/swift-arbitrage-api-node -------------------------------------------------------------------------------- /swift-orderbooks-proxy/swift-orderbooks-proxy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/swift-orderbooks-proxy/swift-orderbooks-proxy -------------------------------------------------------------------------------- /swift-arbitrage-api-node/qt_conf.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qt.conf 4 | 5 | 6 | -------------------------------------------------------------------------------- /swift-arbitrage-api-node/swift-arbitrage-api-node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kirill-01/SwiftBot/HEAD/swift-arbitrage-api-node/swift-arbitrage-api-node -------------------------------------------------------------------------------- /swift-lib/withdrawparams.cpp: -------------------------------------------------------------------------------- 1 | #include "withdrawparams.h" 2 | 3 | WithdrawParams::WithdrawParams(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /qmsgpack/tests/pack/pack.pro: -------------------------------------------------------------------------------- 1 | TARGET = pack_test 2 | QT += testlib 3 | CONFIG += testcase 4 | 5 | include(../tests.pri) 6 | 7 | SOURCES += pack_test.cpp 8 | -------------------------------------------------------------------------------- /qmsgpack/tests/mixed/mixed.pro: -------------------------------------------------------------------------------- 1 | TARGET = mixed_test 2 | QT += testlib 3 | CONFIG += testcase 4 | 5 | include(../tests.pri) 6 | 7 | SOURCES += mixed_test.cpp 8 | -------------------------------------------------------------------------------- /workers/userhistoryworker.cpp: -------------------------------------------------------------------------------- 1 | #include "userhistoryworker.h" 2 | 3 | UserHistoryWorker::UserHistoryWorker(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /qmsgpack/tests/stream/stream.pro: -------------------------------------------------------------------------------- 1 | TARGET = stream_test 2 | QT += testlib 3 | CONFIG += testcase 4 | 5 | include(../tests.pri) 6 | 7 | SOURCES += stream_test.cpp 8 | -------------------------------------------------------------------------------- /qmsgpack/tests/unpack/unpack.pro: -------------------------------------------------------------------------------- 1 | TARGET = unpack_test 2 | QT += testlib 3 | CONFIG += testcase 4 | 5 | include(../tests.pri) 6 | 7 | SOURCES += unpack_test.cpp 8 | -------------------------------------------------------------------------------- /qmsgpack/tests/qttypes/qttypes.pro: -------------------------------------------------------------------------------- 1 | TARGET = qttypes_test 2 | QT += testlib 3 | CONFIG += testcase 4 | 5 | include(../tests.pri) 6 | 7 | SOURCES += qttypes_test.cpp 8 | -------------------------------------------------------------------------------- /DockerBuild/Dockerfile: -------------------------------------------------------------------------------- 1 | from swiftbot-core-base:latest 2 | ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/opt/swiftbot/lib 3 | COPY core.deb /tmp/app.deb 4 | RUN dpkg -i /tmp/app.deb && rm -rf core.deb 5 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparser.cpp: -------------------------------------------------------------------------------- 1 | #include "swiftapiparser.h" 2 | 3 | SwiftApiParser::SwiftApiParser(QObject *parent) : QObject(parent) 4 | { 5 | qRegisterMetaType("SwiftApiClient::AsyncMethods"); 6 | } 7 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | variables: 2 | CI_DEBUG_TRACE: "false" 3 | 4 | build: 5 | variables: 6 | CI_DEBUG_TRACE: "false" 7 | stage: build 8 | only: 9 | refs: 10 | - deploy 11 | script: 12 | - ./build_pkg.sh 13 | -------------------------------------------------------------------------------- /qmsgpack/tests/tests.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | pack \ 5 | unpack \ 6 | mixed 7 | 8 | !contains(DEFINES, MSGPACK_NO_PACKTYPES) { 9 | SUBDIRS += \ 10 | stream \ 11 | qttypes 12 | } 13 | -------------------------------------------------------------------------------- /swift-bot-2.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | CONFIG += ordered 4 | 5 | SUBDIRS += \ 6 | qmsgpack \ 7 | swift-lib \ 8 | swift-arbitrage-api-node \ 9 | swift-bot \ 10 | swift-orderbooks-proxy \ 11 | workers 12 | 13 | -------------------------------------------------------------------------------- /qmsgpack/PVS_HOWTO: -------------------------------------------------------------------------------- 1 | Execute following: 2 | cd qmsgpack 3 | mkdir build 4 | cd build 5 | cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DBUILD_TESTS=True .. 6 | pvs-studio-analyzer analyze -o ../qmsgpack.log 7 | plog-converter -a GA:1,2 -t tasklist -o ../qmsgpack.tasks ../qmsgpack.log 8 | See qmsgpack.tasks then -------------------------------------------------------------------------------- /src/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: SwiftBot2 2 | Version: 2.0.2046 3 | Maintainer: cc.finance 4 | Architecture: amd64 5 | Section: misc 6 | Description: CCFinance cryptocurrency swift trading bot backend 7 | Pre-Depends: curl,certbot,nginx,php7.4,php7.4-fpm,mysql-server,composer,build-essential,python3-dev,python3-pip,libsnappy-dev 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *_log_* 2 | Makefile 3 | */Makefile 4 | */*/Makefile 5 | opt/swiftbot/bin/* 6 | *.pro.user 7 | err_log_* 8 | db*.sql 9 | swiftbot.sql 10 | libmysqlclient21_8.0.19-1ubuntu18.04_amd64.deb 11 | opt/swiftbot/lib 12 | *.o 13 | */*.o 14 | */moc_* 15 | *.sh 16 | !build.sh 17 | *.deb 18 | SwiftBot.wiki 19 | .qmake.stash 20 | -------------------------------------------------------------------------------- /swift-lib/withdrawparams.h: -------------------------------------------------------------------------------- 1 | #ifndef WITHDRAWPARAMS_H 2 | #define WITHDRAWPARAMS_H 3 | 4 | #include 5 | 6 | class WithdrawParams : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit WithdrawParams(QObject *parent = nullptr); 11 | 12 | signals: 13 | 14 | }; 15 | 16 | #endif // WITHDRAWPARAMS_H 17 | -------------------------------------------------------------------------------- /DockerBuildBase/Dockerfile: -------------------------------------------------------------------------------- 1 | from ubuntu:latest 2 | ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/opt/swiftbot/lib 3 | RUN apt update && apt install -y lsb-release gnupg wget 4 | RUN wget https://repo.mysql.com/mysql-apt-config_0.8.15-1_all.deb && echo "4" | dpkg -i mysql-apt-config_0.8.15-1_all.deb && apt update && apt install -y libmysqlclient21 systemd libmysqlclient-dev 5 | -------------------------------------------------------------------------------- /swift-bot.wiki/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | from ubuntu:latest 2 | ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/opt/swiftbot/lib 3 | COPY core.deb /tmp/app.deb 4 | RUN apt update && apt install -y lsb-release gnupg wget 5 | RUN wget https://repo.mysql.com/mysql-apt-config_0.8.15-1_all.deb && echo "4" | dpkg -i mysql-apt-config_0.8.15-1_all.deb && apt update && apt install -y libmysqlclient21 systemd libmysqlclient-dev && dpkg -i /tmp/app.deb 6 | -------------------------------------------------------------------------------- /qmsgpack/src/msgpack_export.h: -------------------------------------------------------------------------------- 1 | #ifndef MSGPACK_EXPORT_H 2 | #define MSGPACK_EXPORT_H 3 | 4 | #include 5 | 6 | #ifndef MSGPACK_STATIC 7 | # if defined(MSGPACK_MAKE_LIB) 8 | # define MSGPACK_EXPORT Q_DECL_EXPORT 9 | # else 10 | # define MSGPACK_EXPORT Q_DECL_IMPORT 11 | # endif 12 | #else 13 | # define MSGPACK_EXPORT 14 | #endif 15 | 16 | #endif // MSGPACK_EXPORT_H 17 | -------------------------------------------------------------------------------- /qmsgpack/src/msgpackcommon.cpp: -------------------------------------------------------------------------------- 1 | // This is an open source non-commercial project. Dear PVS-Studio, please check it. 2 | // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com 3 | #include "msgpackcommon.h" 4 | 5 | QString MsgPack::version() 6 | { 7 | return QString::fromLatin1("%1.%2.%3") 8 | .arg(MSGPACK_MAJOR) 9 | .arg(MSGPACK_MINOR) 10 | .arg(MSGPACK_VERSION); 11 | } 12 | -------------------------------------------------------------------------------- /qmsgpack/doc/index.rst: -------------------------------------------------------------------------------- 1 | qmsgpack - MessagePack serializer implementation for Qt 2 | ======================================================= 3 | 4 | .. toctree:: 5 | :hidden: 6 | 7 | install.rst 8 | basics.rst 9 | stream.rst 10 | custom.rst 11 | 12 | Contents: 13 | 14 | .. toctree:: 15 | :maxdepth: 2 16 | 17 | 18 | 19 | Indices and tables 20 | ================== 21 | 22 | * :ref:`genindex` 23 | * :ref:`modindex` 24 | * :ref:`search` 25 | 26 | -------------------------------------------------------------------------------- /swift-bot/addresswatcher.cpp: -------------------------------------------------------------------------------- 1 | #include "addresswatcher.h" 2 | 3 | AddressWatcher::AddressWatcher(const QString& address, QObject *parent) : QObject(parent), _address(address), netman( new QNetworkAccessManager() ), t(new QTimer()) 4 | { 5 | t->setInterval(20000); 6 | connect( t, &QTimer::timeout, this, &AddressWatcher::sendRequest ); 7 | connect( netman, &QNetworkAccessManager::finished, this, &AddressWatcher::onResponse ); 8 | t->start(); 9 | } 10 | -------------------------------------------------------------------------------- /src/etc/systemd/system/swift-bot.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SwiftBot 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=root 8 | Group=root 9 | StandardInput=null 10 | StandardOutput=journal 11 | StandardError=journal 12 | Environment="LD_LIBRARY_PATH=/opt/swiftbot/lib" 13 | ExecStart=/opt/swiftbot/bin/swift-bot 14 | ExecStop=/usr/bin/killall -9 swift-bot 15 | Restart=always 16 | RestartSec=15 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /qmsgpack/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (Qt5Core_FOUND) 2 | find_package(Qt5Test REQUIRED) 3 | 4 | include_directories(${Qt5Test_INCLUDE_DIRS}) 5 | add_definitions(${Qt5Test_DEFINITIONS}) 6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Test_EXECUTABLE_COMPILE_FLAGS}") 7 | 8 | set(TEST_LIBRARIES ${Qt5Test_LIBRARIES}) 9 | endif () 10 | 11 | set(TEST_SUBDIRS pack unpack mixed stream qttypes) 12 | 13 | foreach(subdir ${TEST_SUBDIRS}) 14 | add_subdirectory(${subdir}) 15 | endforeach() -------------------------------------------------------------------------------- /src/etc/systemd/system/swift-worker-logs.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SwiftApiWorkerLogs 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=root 8 | Group=root 9 | StandardInput=null 10 | StandardOutput=journal 11 | StandardError=journal 12 | Environment="LD_LIBRARY_PATH=/opt/swiftbot/lib" 13 | ExecStart=/opt/swiftbot/bin/workers -w logs 14 | ExecStop=/bin/kill -- $MAINPID 15 | Restart=always 16 | RestartSec=16 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /src/etc/systemd/system/swift-worker-orders.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SwiftApiWorkerOrders 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=root 8 | Group=root 9 | StandardInput=null 10 | StandardOutput=journal 11 | StandardError=journal 12 | Environment="LD_LIBRARY_PATH=/opt/swiftbot/lib" 13 | ExecStart=/opt/swiftbot/bin/workers -w orders 14 | ExecStop=/bin/kill -- $MAINPID 15 | Restart=always 16 | RestartSec=16 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /src/etc/systemd/system/swift-worker-balances.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SwiftApiWorkerBalances 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=root 8 | Group=root 9 | StandardInput=null 10 | StandardOutput=journal 11 | StandardError=journal 12 | Environment="LD_LIBRARY_PATH=/opt/swiftbot/lib" 13 | ExecStart=/opt/swiftbot/bin/workers -w balances 14 | ExecStop=/bin/kill -- $MAINPID 15 | Restart=always 16 | RestartSec=16 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /src/etc/systemd/system/swift-orderbooks-proxy.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SwiftOrderbooksProxy 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=root 8 | Group=root 9 | StandardInput=null 10 | StandardOutput=journal 11 | StandardError=journal 12 | Environment="LD_LIBRARY_PATH=/opt/swiftbot/lib" 13 | ExecStart=/opt/swiftbot/bin/swift-orderbooks-proxy 14 | ExecStop=/usr/bin/killall -9 swift-orderbooks-proxy 15 | RestartSec=3 16 | 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /src/etc/systemd/system/swift-worker-settingshost.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SwiftApiWorkerSettingsHost 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=root 8 | Group=root 9 | StandardInput=null 10 | StandardOutput=null 11 | StandardError=null 12 | Environment="LD_LIBRARY_PATH=/opt/swiftbot/lib" 13 | ExecStart=/opt/swiftbot/bin/workers -w settingshost 14 | ExecStop=/bin/kill -- $MAINPID 15 | Restart=always 16 | RestartSec=16 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /qmsgpack/src/stream/location.h: -------------------------------------------------------------------------------- 1 | #ifndef QMSGPACK_STREAM_LOCATION_H 2 | #define QMSGPACK_STREAM_LOCATION_H 3 | 4 | #ifdef QT_LOCATION_LIB 5 | 6 | #include "../msgpack_export.h" 7 | #include "../msgpackstream.h" 8 | 9 | #include 10 | 11 | MSGPACK_EXPORT MsgPackStream& operator>>(MsgPackStream& s, QGeoCoordinate &coordinate); 12 | MSGPACK_EXPORT MsgPackStream &operator<<(MsgPackStream& s, const QGeoCoordinate &coordinate); 13 | 14 | #endif // QT_LOCATION_LIB 15 | #endif // QMSGPACK_STREAM_LOCATION_H 16 | -------------------------------------------------------------------------------- /src/etc/systemd/system/swift-api.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SwiftApi 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=root 8 | Group=root 9 | StandardInput=null 10 | StandardOutput=journal 11 | StandardError=journal 12 | Environment="LD_LIBRARY_PATH=/opt/swiftbot/lib" 13 | ExecStart=/opt/swiftbot/bin/swift-arbitrage-api-node 14 | ExecStop=/usr/bin/killall -9 /opt/swiftbot/bin/swift-arbitrage-api-node 15 | Restart=always 16 | RestartSec=15 17 | 18 | 19 | [Install] 20 | WantedBy=multi-user.target 21 | -------------------------------------------------------------------------------- /qmsgpack/tests/big/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QT_USE_QTTEST TRUE) 2 | 3 | if (NOT Qt5Core_FOUND) 4 | include( ${QT_USE_FILE} ) 5 | endif() 6 | 7 | include(AddFileDependencies) 8 | 9 | include_directories(../../src ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | set(UNIT_TESTS big) 12 | 13 | foreach(test ${UNIT_TESTS}) 14 | message(status "Building ${test}") 15 | add_executable(${test} ${test}.cpp) 16 | 17 | target_link_libraries(${test} 18 | ${QT_LIBRARIES} 19 | ${TEST_LIBRARIES} 20 | qmsgpack 21 | ) 22 | 23 | add_test(${test} ${test}) 24 | endforeach() -------------------------------------------------------------------------------- /src/etc/systemd/system/crossbar.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Crossbar.io 3 | After=network.target 4 | 5 | [Service] 6 | Type=simple 7 | User=root 8 | Group=root 9 | StandardInput=null 10 | StandardOutput=journal 11 | StandardError=journal 12 | Environment="LD_LIBRARY_PATH=/opt/swiftbot/lib" 13 | ExecStart=/usr/local/bin/crossbar start --cbdir=/opt/swiftbot/crossbar/.crossbar 14 | ExecStop=/usr/local/bin/crossbar stop --cbdir=/opt/swiftbot/crossbar/.crossbar 15 | Restart=always 16 | RestartSec=3 17 | 18 | [Install] 19 | WantedBy=multi-user.target 20 | -------------------------------------------------------------------------------- /qmsgpack/tests/mixed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QT_USE_QTTEST TRUE) 2 | 3 | if (NOT Qt5Core_FOUND) 4 | include( ${QT_USE_FILE} ) 5 | endif() 6 | 7 | include(AddFileDependencies) 8 | 9 | include_directories(../../src ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | set(UNIT_TESTS mixed_test) 12 | 13 | foreach(test ${UNIT_TESTS}) 14 | message(status "Building ${test}") 15 | add_executable(${test} ${test}.cpp) 16 | 17 | target_link_libraries(${test} 18 | ${QT_LIBRARIES} 19 | ${TEST_LIBRARIES} 20 | qmsgpack 21 | ) 22 | 23 | add_test(${test} ${test}) 24 | endforeach() -------------------------------------------------------------------------------- /qmsgpack/tests/pack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QT_USE_QTTEST TRUE) 2 | 3 | if (NOT Qt5Core_FOUND) 4 | include( ${QT_USE_FILE} ) 5 | endif() 6 | 7 | include(AddFileDependencies) 8 | 9 | include_directories(../../src ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | set(UNIT_TESTS pack_test) 12 | 13 | foreach(test ${UNIT_TESTS}) 14 | message(status "Building ${test}") 15 | add_executable(${test} ${test}.cpp) 16 | 17 | target_link_libraries(${test} 18 | ${QT_LIBRARIES} 19 | ${TEST_LIBRARIES} 20 | qmsgpack 21 | ) 22 | 23 | add_test(${test} ${test}) 24 | endforeach() -------------------------------------------------------------------------------- /qmsgpack/tests/qttypes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QT_USE_QTTEST TRUE) 2 | 3 | if (NOT Qt5Core_FOUND) 4 | include( ${QT_USE_FILE} ) 5 | endif() 6 | 7 | include(AddFileDependencies) 8 | 9 | include_directories(../../src ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | set(UNIT_TESTS qttypes_test) 12 | 13 | foreach(test ${UNIT_TESTS}) 14 | message(status "Building ${test}") 15 | add_executable(${test} ${test}.cpp) 16 | 17 | target_link_libraries(${test} 18 | ${QT_LIBRARIES} 19 | ${TEST_LIBRARIES} 20 | qmsgpack 21 | ) 22 | 23 | add_test(${test} ${test}) 24 | endforeach() -------------------------------------------------------------------------------- /qmsgpack/tests/stream/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QT_USE_QTTEST TRUE) 2 | 3 | if (NOT Qt5Core_FOUND) 4 | include( ${QT_USE_FILE} ) 5 | endif() 6 | 7 | include(AddFileDependencies) 8 | 9 | include_directories(../../src ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | set(UNIT_TESTS stream_test) 12 | 13 | foreach(test ${UNIT_TESTS}) 14 | message(status "Building ${test}") 15 | add_executable(${test} ${test}.cpp) 16 | 17 | target_link_libraries(${test} 18 | ${QT_LIBRARIES} 19 | ${TEST_LIBRARIES} 20 | qmsgpack 21 | ) 22 | 23 | add_test(${test} ${test}) 24 | endforeach() -------------------------------------------------------------------------------- /qmsgpack/tests/unpack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QT_USE_QTTEST TRUE) 2 | 3 | if (NOT Qt5Core_FOUND) 4 | include( ${QT_USE_FILE} ) 5 | endif() 6 | 7 | include(AddFileDependencies) 8 | 9 | include_directories(../../src ${CMAKE_CURRENT_BINARY_DIR}) 10 | 11 | set(UNIT_TESTS unpack_test) 12 | 13 | foreach(test ${UNIT_TESTS}) 14 | message(status "Building ${test}") 15 | add_executable(${test} ${test}.cpp) 16 | 17 | target_link_libraries(${test} 18 | ${QT_LIBRARIES} 19 | ${TEST_LIBRARIES} 20 | qmsgpack 21 | ) 22 | 23 | add_test(${test} ${test}) 24 | endforeach() -------------------------------------------------------------------------------- /workers/userhistoryworker.h: -------------------------------------------------------------------------------- 1 | #ifndef USERHISTORYWORKER_H 2 | #define USERHISTORYWORKER_H 3 | 4 | #include 5 | #include "../swift-lib/swiftlib.h" 6 | 7 | class UserHistoryWorker : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit UserHistoryWorker(QObject *parent = nullptr); 12 | 13 | signals: 14 | public slots: 15 | void onWampSession( Wamp::Session * sess ) { 16 | session = sess; 17 | 18 | } 19 | void createSnapshot() { 20 | 21 | } 22 | private: 23 | Wamp::Session * session; 24 | }; 25 | 26 | #endif // USERHISTORYWORKER_H 27 | -------------------------------------------------------------------------------- /swift-lib/apircpclient.h: -------------------------------------------------------------------------------- 1 | #ifndef APIRCPCLIENT_H 2 | #define APIRCPCLIENT_H 3 | 4 | #include 5 | #include "asyncrcpcallerinterface.h" 6 | class ApiRcpClient : public AsyncRcpCallerInterface 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit ApiRcpClient( QObject * parent = nullptr); 11 | void useClient( Wamp::Session * sess ) { 12 | session = sess; 13 | } 14 | signals: 15 | void orderbooks( const QJsonObject& j_result ); 16 | void open_orders( const QJsonObject& j_result ); 17 | public slots: 18 | void onMethodFinished( const quint64& uuid ); 19 | }; 20 | 21 | #endif // APIRCPCLIENT_H 22 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserlakebtc.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERLAKEBTC_H 2 | #define SWIFTAPIPARSERLAKEBTC_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserLakebtc : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiParserLakebtc(QObject * parent = nullptr); 12 | 13 | // SwiftApiParser interface 14 | public: 15 | 16 | QString getExchangeName() const override; 17 | 18 | public: 19 | void parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 20 | }; 21 | 22 | #endif // SWIFTAPIPARSERLAKEBTC_H 23 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserlivecoin.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERLIVECOIN_H 2 | #define SWIFTAPIPARSERLIVECOIN_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | class SwiftApiParserLivecoin : public SwiftApiParser 7 | { 8 | Q_OBJECT 9 | public: 10 | SwiftApiParserLivecoin(QObject *parent = nullptr); 11 | 12 | signals: 13 | 14 | 15 | // SwiftApiParser interface 16 | public: 17 | 18 | QString getExchangeName() const override; 19 | 20 | public slots: 21 | void parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 22 | }; 23 | 24 | #endif // SWIFTAPIPARSERLIVECOIN_H 25 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserbinance.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERBINANCE_H 2 | #define SWIFTAPIPARSERBINANCE_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserBinance : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | 12 | signals: 13 | 14 | 15 | // SwiftApiParser interface 16 | public: 17 | 18 | QString getExchangeName() const override; 19 | 20 | public slots: 21 | void parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 22 | private: 23 | QString parseStatus( const QString& stat ); 24 | }; 25 | 26 | #endif // SWIFTAPIPARSERBINANCE_H 27 | -------------------------------------------------------------------------------- /swift-lib/ordermodel.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERMODEL_H 2 | #define ORDERMODEL_H 3 | 4 | #include 5 | 6 | class OrderModel : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit OrderModel(QObject *parent = nullptr); 11 | 12 | signals: 13 | 14 | private: 15 | QString local_uuid; 16 | QString remote_uuid; 17 | double amount; 18 | double amount_left; 19 | double fee_size; 20 | double fee_amount; 21 | double price; 22 | quint32 market_id; 23 | quint32 exchange_id; 24 | quint32 status; 25 | quint32 type; 26 | quint64 created_at; 27 | quint64 closed_at; 28 | 29 | }; 30 | 31 | #endif // ORDERMODEL_H 32 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserbittrex.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERBITTREX_H 2 | #define SWIFTAPIPARSERBITTREX_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserBittrex : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiParserBittrex(QObject *parent = nullptr); 12 | 13 | signals: 14 | 15 | 16 | // SwiftApiParser interface 17 | public: 18 | 19 | QString getExchangeName() const override; 20 | 21 | public slots: 22 | void parseResponse( const quint64& uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 23 | }; 24 | 25 | #endif // SWIFTAPIPARSERBITTREX_H 26 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparsercexio.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERCEXIO_H 2 | #define SWIFTAPIPARSERCEXIO_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserCexio : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiParserCexio(QObject *parent = nullptr) : SwiftApiParser( parent ) { 12 | 13 | } 14 | 15 | 16 | // SwiftApiParser interface 17 | public: 18 | 19 | QString getExchangeName() const override; 20 | 21 | public slots: 22 | void parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 23 | }; 24 | 25 | #endif // SWIFTAPIPARSERCEXIO_H 26 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserlbank.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERLBANK_H 2 | #define SWIFTAPIPARSERLBANK_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | class SwiftApiParserLbank : public SwiftApiParser 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit SwiftApiParserLbank(QObject *parent = nullptr) : SwiftApiParser(parent) { 11 | 12 | } 13 | 14 | signals: 15 | // SwiftApiParser interface 16 | public: 17 | 18 | QString getExchangeName() const override; 19 | 20 | public slots: 21 | void parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 22 | }; 23 | 24 | #endif // SWIFTAPIPARSERLBANK_H 25 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserkucoin.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERKUCOIN_H 2 | #define SWIFTAPIPARSERKUCOIN_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserKuCoin : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiParserKuCoin( QObject * parent = nullptr ) : SwiftApiParser(parent) { 12 | 13 | } 14 | 15 | // SwiftApiParser interface 16 | public: 17 | 18 | QString getExchangeName() const override; 19 | 20 | public slots: 21 | 22 | void parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 23 | private: 24 | 25 | }; 26 | 27 | #endif // SWIFTAPIPARSERKUCOIN_H 28 | -------------------------------------------------------------------------------- /qmsgpack/src/stream/geometry.h: -------------------------------------------------------------------------------- 1 | #ifndef GEOMETRY_H 2 | #define GEOMETRY_H 3 | 4 | #include "../msgpack_export.h" 5 | #include "../msgpackstream.h" 6 | 7 | #include 8 | 9 | MSGPACK_EXPORT MsgPackStream &operator<<(MsgPackStream& s, const QPoint &point); 10 | MSGPACK_EXPORT MsgPackStream& operator>>(MsgPackStream& s, QPoint &point); 11 | 12 | MSGPACK_EXPORT MsgPackStream &operator<<(MsgPackStream& s, const QSize &sz); 13 | MSGPACK_EXPORT MsgPackStream& operator>>(MsgPackStream& s, QSize &sz); 14 | 15 | MSGPACK_EXPORT MsgPackStream &operator<<(MsgPackStream& s, const QRect &rect); 16 | MSGPACK_EXPORT MsgPackStream& operator>>(MsgPackStream& s, QRect &rect); 17 | 18 | #endif // GEOMETRY_H 19 | 20 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserexmo.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSEREXMO_H 2 | #define SWIFTAPIPARSEREXMO_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserExmo : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiParserExmo(QObject *parent = nullptr) : SwiftApiParser( parent ) { 12 | 13 | } 14 | 15 | // SwiftApiParser interface 16 | public: 17 | QStringList opn_orders_cache; 18 | 19 | QString getExchangeName() const override; 20 | 21 | public slots: 22 | void parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 23 | }; 24 | 25 | #endif // SWIFTAPIPARSEREXMO_H 26 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | -------------------------------------------------------------------------------- /swift-bot/arbitrageworker.cpp: -------------------------------------------------------------------------------- 1 | #include "arbitrageworker.h" 2 | 3 | 4 | 5 | QStringList ArbitrageWorker::listenParams() 6 | { 7 | return QStringList({"BTCUSDPAIR","ETHUSDPAIR","MIN_WINDOW_SPREAD","MIN_ORDER_SIZE","MIN_WINDOW_SPREAD","AMOUNT_PRECISION","MAX_ORDER_SIZE","ORDER_STEP_SIZE","RATE_PRECISION"}); 8 | } 9 | 10 | void ArbitrageWorker::onParamChanged(const QString ¶m, const QString &value) 11 | { 12 | manager->updateParam( param, value ); 13 | // RESTART MANAGER ? 14 | } 15 | 16 | void ArbitrageWorker::initWorker(Wamp::Session *sess) 17 | { 18 | manager->onWampSession( sess ); 19 | } 20 | 21 | QString ArbitrageWorker::getWorkerName() const 22 | { 23 | return "arbitrage"; 24 | } 25 | -------------------------------------------------------------------------------- /swift-lib/apircpclient.cpp: -------------------------------------------------------------------------------- 1 | #include "apircpclient.h" 2 | 3 | ApiRcpClient::ApiRcpClient(QObject *parent) : AsyncRcpCallerInterface(parent) { 4 | connect( this, &AsyncRcpCallerInterface::asyncFinished, this, &ApiRcpClient::onMethodFinished ); 5 | } 6 | 7 | void ApiRcpClient::onMethodFinished(const quint64 &uuid) { 8 | 9 | if ( _async_waiting.contains( uuid ) && _async_results.contains( uuid ) ) { 10 | const QJsonObject j_result( getResultByUuid( uuid ) ); 11 | const SwiftApiClient::AsyncMethods method = getMethodByUuid( uuid ); 12 | if ( method == SwiftApiClient::AsyncMethods::GetOrderbooks ) { 13 | emit orderbooks( j_result ); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /swift-orderbooks-proxy/rateswriter.h: -------------------------------------------------------------------------------- 1 | #ifndef RATESWRITER_H 2 | #define RATESWRITER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class RatesWriter : public QObject 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit RatesWriter(QObject *parent = nullptr); 17 | 18 | signals: 19 | 20 | public slots: 21 | void onRates( const QMap &rates ); 22 | void onThreadStarted(); 23 | private: 24 | QSqlDatabase _db; 25 | QSqlDatabase _ch; 26 | QMutex m; 27 | QMap _last_inserted_values; 28 | }; 29 | 30 | #endif // RATESWRITER_H 31 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparseridcm.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERIDCM_H 2 | #define SWIFTAPIPARSERIDCM_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserIDCM : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiParserIDCM(QObject *parent = nullptr); 12 | 13 | // SwiftApiParser interface 14 | 15 | QString getExchangeName() const override; 16 | 17 | public slots: 18 | void parseResponse( const quint64& uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 19 | 20 | private: 21 | QString orderStatus(int status) const; 22 | QString withdrawStatus(int status) const; 23 | }; 24 | 25 | #endif // SWIFTAPIPARSERIDCM_H 26 | -------------------------------------------------------------------------------- /swift-lib/settingshostcomponent.h: -------------------------------------------------------------------------------- 1 | #ifndef SETTINGSHOSTCOMPONENT_H 2 | #define SETTINGSHOSTCOMPONENT_H 3 | 4 | #include 5 | #include "wampclient.h" 6 | 7 | class SettingsHostComponent : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SettingsHostComponent(QObject *parent = nullptr); 12 | 13 | signals: 14 | void componentShutdownRequested(); 15 | void componentStartRequested(); 16 | public slots: 17 | void logInfo( const QString& message ); 18 | void logError( const QString& message ); 19 | void sendHeartBeat(); 20 | void registerRpcMethods(); 21 | private: 22 | QTimer * heartbeattimer; 23 | WampClient * client; 24 | }; 25 | 26 | #endif // SETTINGSHOSTCOMPONENT_H 27 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserhitbtc.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERHITBTC_H 2 | #define SWIFTAPIPARSERHITBTC_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserHitbtc : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiParserHitbtc(QObject *parent=nullptr) : SwiftApiParser(parent) 12 | { 13 | 14 | } 15 | QMap _account_balances_storage; 16 | 17 | 18 | // SwiftApiParser interface 19 | public: 20 | 21 | QString getExchangeName() const override; 22 | 23 | public slots: 24 | void parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 25 | }; 26 | 27 | #endif // SWIFTAPIPARSERHITBTC_H 28 | -------------------------------------------------------------------------------- /swift-bot/arbitrageworker.h: -------------------------------------------------------------------------------- 1 | #ifndef ARBITRAGEWORKER_H 2 | #define ARBITRAGEWORKER_H 3 | 4 | #include 5 | #include "swiftworker.h" 6 | #include "arbitragemanager.h" 7 | class ArbitrageWorker : public SwiftWorker 8 | { 9 | Q_OBJECT 10 | public: 11 | ArbitrageWorker( QObject * parent = nullptr ) : SwiftWorker(parent), manager( new ArbitrageManager(this) ) { 12 | 13 | } 14 | 15 | // SwiftWorker interface 16 | public: 17 | QStringList listenParams() override; 18 | void onParamChanged(const QString ¶m, const QString &value) override; 19 | void initWorker(Wamp::Session *sess) override; 20 | QString getWorkerName() const override; 21 | ArbitrageManager * manager; 22 | }; 23 | 24 | #endif // ARBITRAGEWORKER_H 25 | -------------------------------------------------------------------------------- /qmsgpack/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: gcc 3 | 4 | dist: trusty 5 | sudo: required 6 | 7 | env: 8 | - QT4_BUILD=OFF 9 | 10 | before_install: 11 | - sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test 12 | - sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa 13 | - sudo apt-get update -qq 14 | 15 | install: 16 | - sudo apt-get install -y --force-yes build-essential g++-4.8 -y 17 | - sudo apt-get install -y --force-yes qtbase5-dev qttools5-dev-tools qttools5-dev 18 | 19 | 20 | script: 21 | - mkdir build 22 | - cd build 23 | - if [ "$QT4_BUILD" == "OFF" ]; then cmake -DBUILD_TESTS=TRUE -DQT4_BUILD=FALSE ..; else cmake -DBUILD_TESTS=TRUE -DQT4_BUILD=TRUE ..; fi 24 | - make 25 | - export CTEST_OUTPUT_ON_FAILURE=1 26 | - make test 27 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparser.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSER_H 2 | #define SWIFTAPIPARSER_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | 7 | class SwiftApiParser : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiParser(QObject *parent = nullptr); 12 | quint32 getExchangeId() const { 13 | return SwiftLib::getAssets()->getExchangeId( getExchangeName() ); 14 | }; 15 | virtual QString getExchangeName() const=0; 16 | signals: 17 | void resultParsed( const quint64& uuid, const QJsonObject& j_result ); 18 | public slots: 19 | virtual void parseResponse( const quint64& uuid, const SwiftApiClient::AsyncMethods& method, const QByteArray& data )=0; 20 | private: 21 | 22 | }; 23 | 24 | #endif // SWIFTAPIPARSER_H 25 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserkraken.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERKRAKEN_H 2 | #define SWIFTAPIPARSERKRAKEN_H 3 | 4 | #include "swiftapiparser.h" 5 | 6 | class SwiftApiParserKraken : public SwiftApiParser 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit SwiftApiParserKraken(QObject *parent = nullptr); 11 | 12 | // SwiftApiParser interface 13 | 14 | QString getExchangeName() const override; 15 | 16 | //typedef 17 | public slots: 18 | void parseResponse( const quint64& uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 19 | 20 | private: 21 | int GetMarketId(const QString& market) const; 22 | QString orderStatus(const QString& status) const; 23 | QString ioStatus(const QString& status) const; 24 | }; 25 | 26 | #endif // SWIFTAPIPARSERKRAKEN_H 27 | -------------------------------------------------------------------------------- /qmsgpack/src/msgpack.h: -------------------------------------------------------------------------------- 1 | #ifndef MSGPACK_H 2 | #define MSGPACK_H 3 | 4 | #include "msgpack_export.h" 5 | #include "msgpackcommon.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace MsgPack 11 | { 12 | MSGPACK_EXPORT QVariant unpack(const QByteArray &data); 13 | MSGPACK_EXPORT bool registerUnpacker(qint8 msgpackType, unpack_user_f unpacker); 14 | 15 | MSGPACK_EXPORT QByteArray pack(const QVariant &variant); 16 | MSGPACK_EXPORT bool registerPacker(int qType, qint8 msgpackType, pack_user_f packer); 17 | MSGPACK_EXPORT qint8 msgpackType(int qType); 18 | 19 | MSGPACK_EXPORT bool registerType(QMetaType::Type qType, quint8 msgpackType); 20 | 21 | MSGPACK_EXPORT void setCompatibilityModeEnabled(bool enabled); 22 | } // MsgPack 23 | 24 | #endif // MSGPACK_H 25 | -------------------------------------------------------------------------------- /qmsgpack/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 3 | ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | STRING(REGEX REPLACE "\n" ";" files "${files}") 7 | FOREACH(file ${files}) 8 | MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 9 | EXEC_PROGRAM( 10 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 11 | OUTPUT_VARIABLE rm_out 12 | RETURN_VALUE rm_retval 13 | ) 14 | IF(NOT "${rm_retval}" STREQUAL 0) 15 | MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 16 | ENDIF(NOT "${rm_retval}" STREQUAL 0) 17 | ENDFOREACH(file) -------------------------------------------------------------------------------- /swift-lib/orderbooksclient.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERBOOKSCLIENT_H 2 | #define ORDERBOOKSCLIENT_H 3 | 4 | #include 5 | #include "wampclient.h" 6 | 7 | class OrderbooksClient : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit OrderbooksClient(QObject *parent = nullptr); 12 | 13 | signals: 14 | void orderbooks( const QHash>& asks, const QHash>& bids ); 15 | public slots: 16 | void onOrderBooks(const QJsonObject& j_books); 17 | void onWampSession( Wamp::Session * sess ); 18 | void stopClient(); 19 | void startClient( const QList& filter = QList() ); 20 | private: 21 | QList _filtered_pairs; 22 | WampClient * orderbooks_client; 23 | Wamp::Session * session; 24 | }; 25 | 26 | #endif // ORDERBOOKSCLIENT_H 27 | -------------------------------------------------------------------------------- /qmsgpack/qmsgpack.pri: -------------------------------------------------------------------------------- 1 | QT += core 2 | QT -= gui 3 | INCLUDEPATH += $$PWD/src 4 | 5 | SOURCES += \ 6 | $$PWD/src/msgpack.cpp \ 7 | $$PWD/src/msgpackcommon.cpp \ 8 | $$PWD/src/private/pack_p.cpp \ 9 | $$PWD/src/private/unpack_p.cpp \ 10 | $$PWD/src/msgpackstream.cpp 11 | 12 | HEADERS += \ 13 | $$PWD/src/msgpack.h \ 14 | $$PWD/src/private/pack_p.h \ 15 | $$PWD/src/private/unpack_p.h \ 16 | $$PWD/src/endianhelper.h \ 17 | $$PWD/src/msgpackcommon.h \ 18 | $$PWD/src/msgpack_export.h \ 19 | $$PWD/src/msgpackstream.h 20 | 21 | !contains(DEFINES, MSGPACK_NO_PACKTYPES) { 22 | SOURCES += \ 23 | $$PWD/src/private/qt_types_p.cpp \ 24 | $$PWD/src/stream/time.cpp \ 25 | $$PWD/src/stream/geometry.cpp 26 | 27 | HEADERS += \ 28 | $$PWD/src/private/qt_types_p.h \ 29 | $$PWD/src/stream/time.h \ 30 | $$PWD/src/stream/geometry.h 31 | } 32 | -------------------------------------------------------------------------------- /workers/dbwriter.h: -------------------------------------------------------------------------------- 1 | #ifndef DBWRITER_H 2 | #define DBWRITER_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | class DbWriter : public QObject 18 | { 19 | Q_OBJECT 20 | public: 21 | explicit DbWriter(QObject *parent = nullptr); 22 | 23 | signals: 24 | void storedOrders( const QJsonArray& j_arr ); 25 | public slots: 26 | void onSaveOrder( const QJsonObject &jitm ); 27 | void onSaveOrderState( const QJsonObject &jitm ); 28 | void onThreadStarted(); 29 | void loadTodayOrders(); 30 | void deleteOrderRec( const QJsonObject&j); 31 | private: 32 | QSqlQuery saveOrder; 33 | QSqlDatabase _db; 34 | QMutex m; 35 | }; 36 | 37 | #endif // DBWRITER_H 38 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserhuobi.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERHUOBI_H 2 | #define SWIFTAPIPARSERHUOBI_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserHuobi : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiParserHuobi(QObject *parent = nullptr); 12 | 13 | // SwiftApiParser interface 14 | 15 | QString getExchangeName() const override; 16 | 17 | public slots: 18 | void parseResponse( const quint64& uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 19 | 20 | private: 21 | QString orderStatus(const QString& status) const; 22 | QString withdrawStatus(const QString& status) const; 23 | QString depositStatus(const QString& status) const; 24 | QString sideValue(const QString& side) const; 25 | QString cropDoubleStr(const QString &s, bool onlyPos=false) const; 26 | }; 27 | 28 | #endif // SWIFTAPIPARSERHUOBI_H 29 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserokcoin.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSEROKCOIN_H 2 | #define SWIFTAPIPARSEROKCOIN_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | #include 7 | 8 | class SwiftApiParserOkcoin : public SwiftApiParser 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit SwiftApiParserOkcoin(QObject *parent = nullptr); 13 | 14 | // SwiftApiParser interface 15 | 16 | QString getExchangeName() const override; 17 | 18 | public slots: 19 | void parseResponse( const quint64& uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 20 | 21 | private: 22 | QString orderStatusParse(int status) const; 23 | QString withdrawStatusParse(int status) const; 24 | QString depositStatusParse(int status) const; 25 | QString depositTypeParse(int status) const; 26 | QString fromISOToStr(const QString& time_iso) const; 27 | }; 28 | 29 | #endif // SWIFTAPIPARSEROKCOIN_H 30 | -------------------------------------------------------------------------------- /qmsgpack/src/stream/time.h: -------------------------------------------------------------------------------- 1 | #ifndef TIME_H 2 | #define TIME_H 3 | 4 | #include "../msgpack_export.h" 5 | #include "../msgpackstream.h" 6 | 7 | #include 8 | 9 | MSGPACK_EXPORT MsgPackStream &operator<<(MsgPackStream& s, const QTime &time); 10 | MSGPACK_EXPORT MsgPackStream& operator>>(MsgPackStream& s, QTime &time); 11 | 12 | MSGPACK_EXPORT MsgPackStream &operator<<(MsgPackStream& s, const QDate &date); 13 | MSGPACK_EXPORT MsgPackStream& operator>>(MsgPackStream& s, QDate &date); 14 | 15 | MSGPACK_EXPORT MsgPackStream &operator<<(MsgPackStream& s, const QDateTime &dt); 16 | MSGPACK_EXPORT MsgPackStream& operator>>(MsgPackStream& s, QDateTime &dt); 17 | 18 | namespace MsgPackPrivate { 19 | void pack_qtime_raw(const QTime &time, quint8 *p); 20 | QTime unpack_qtime_raw(quint8 *p, bool with_ms); 21 | void pack_qdate_raw(const QDate &date, quint8 *p); 22 | QDate unpack_qdate_raw(quint8 *p); 23 | } 24 | 25 | #endif // TIME_H 26 | 27 | -------------------------------------------------------------------------------- /swift-arbitrage-api-node/procwrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef PROCWRAPPER_H 2 | #define PROCWRAPPER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class ProcWrapper : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit ProcWrapper(const QString& command, const QStringList& args = QStringList({}), QObject *parent = nullptr); 15 | QString getStatus(); 16 | signals: 17 | void procFinished( const quint32& exitcode ); 18 | void isexited(); 19 | public slots: 20 | void stop(); 21 | void restart(); 22 | 23 | void onProcFinished( const quint32& exitcode ); 24 | void start(); 25 | void onStateChanged( QProcess::ProcessState state ); 26 | private: 27 | QString exchange_name; 28 | QString cmd; 29 | QStringList arg; 30 | QSharedPointer _proc; 31 | bool was_started; 32 | quint32 restarts_count; 33 | }; 34 | 35 | #endif // PROCWRAPPER_H 36 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserzb.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERZB_H 2 | #define SWIFTAPIPARSERZB_H 3 | 4 | #include 5 | #include "swiftapiparser.h" 6 | 7 | class SwiftApiParserZB : public SwiftApiParser 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiParserZB(QObject *parent = nullptr); 12 | 13 | // SwiftApiParser interface 14 | 15 | QString getExchangeName() const override; 16 | 17 | public slots: 18 | void parseResponse( const quint64& uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 19 | 20 | private: 21 | QString translateMsg( const QString& msg ) { 22 | if ( msg == "根据您在本站的资金综合状况,为了您的资产安全,您需要进行初级实名认证,才能继续相关资金操作。如需更大额度,可直接进行高级实名认证" ) { 23 | return "Verification required"; 24 | } 25 | return msg; 26 | } 27 | QString orderStatus(int status) const; 28 | QString withdrawStatus(int status) const; 29 | QString depositStatus(int status) const; 30 | }; 31 | 32 | #endif // SWIFTAPIPARSERZB_H 33 | -------------------------------------------------------------------------------- /qmsgpack/tests/big/big.cpp: -------------------------------------------------------------------------------- 1 | // This is an open source non-commercial project. Dear PVS-Studio, please check it. 2 | // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class Big : public QObject 11 | { 12 | Q_OBJECT 13 | 14 | private Q_SLOTS: 15 | void test_big_list(); 16 | }; 17 | 18 | void Big::test_big_list() 19 | { 20 | QVariantList list; 21 | for (int i = 0; i < 10000; ++i) 22 | list << i; 23 | QByteArray packed; 24 | QVariantList unpacked; 25 | QBENCHMARK { 26 | packed = MsgPack::pack(list); 27 | unpacked = MsgPack::unpack(packed).toList(); 28 | } 29 | bool listOk = true; 30 | for (int i = 0; i < unpacked.size(); ++i) { 31 | if (unpacked[i].toInt() != i) { 32 | listOk = false; 33 | } 34 | } 35 | QVERIFY(listOk); 36 | } 37 | 38 | 39 | QTEST_APPLESS_MAIN(Big) 40 | 41 | #include "big.moc" 42 | -------------------------------------------------------------------------------- /workers/workers.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | QT += websockets network sql 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | DEFINES += QT_DEPRECATED_WARNINGS 7 | 8 | 9 | INCLUDEPATH += $$PWD/../swift-lib $$PWD/../qmsgpack/src 10 | DEPENDPATH += $$PWD/../swift-lib $$PWD/../qmsgpack/src $$PWD/../qmsgpack/bin 11 | 12 | LIBS += -L$$OUT_PWD/../qmsgpack/bin/ -lqmsgpack -L$$OUT_PWD/../swift-lib/ -lswift-lib 13 | 14 | SOURCES += \ 15 | balancesworker.cpp \ 16 | balanceworker.cpp \ 17 | dbwriter.cpp \ 18 | logsworker.cpp \ 19 | main.cpp \ 20 | ordersworker.cpp \ 21 | orderworker.cpp \ 22 | settingshostworker.cpp \ 23 | settingsworker.cpp \ 24 | strategyworker.cpp \ 25 | userhistoryworker.cpp 26 | 27 | HEADERS += \ 28 | balancesworker.h \ 29 | balanceworker.h \ 30 | dbwriter.h \ 31 | logsworker.h \ 32 | ordersworker.h \ 33 | orderworker.h \ 34 | settingshostworker.h \ 35 | settingsworker.h \ 36 | strategyworker.h \ 37 | userhistoryworker.h 38 | -------------------------------------------------------------------------------- /qmsgpack/src/src.pro: -------------------------------------------------------------------------------- 1 | TARGET = qmsgpack 2 | VER_MAJ = 0 3 | VER_MIN = 1 4 | VER_PAT = 0 5 | QT -= gui 6 | TEMPLATE = lib 7 | DEFINES += MSGPACK_MAKE_LIB 8 | DESTDIR = $$shadowed($$PWD/../bin) 9 | TARGET = $$qtLibraryTarget($$TARGET) 10 | VERSION = $$join($$list($$VER_MAJ $$VER_MIN $$VER_PAT), .) 11 | 12 | include(../qmsgpack.pri) 13 | 14 | HEADERS_INSTALL = \ 15 | msgpack.h \ 16 | endianhelper.h \ 17 | msgpackcommon.h \ 18 | msgpack_export.h \ 19 | msgpackstream.h \ 20 | 21 | !contains(DEFINES, MSGPACK_NO_PACKTYPES) { 22 | STREAM_HEADERS_INSTALL = \ 23 | stream/geometry.h \ 24 | stream/time.h 25 | 26 | qtHaveModule(location) { 27 | STREAM_HEADERS_INSTALL += stream/location.h 28 | } 29 | } 30 | 31 | unix { 32 | header_files.files = $$HEADERS_INSTALL 33 | header_files.path = /usr/include/qmsgpack 34 | stream_header_files.files = $$STREAM_HEADERS_INSTALL 35 | stream_header_files.path = /usr/include/qmsgpack/stream 36 | target.path = /usr/lib 37 | INSTALLS += header_files stream_header_files target 38 | } 39 | -------------------------------------------------------------------------------- /qmsgpack/src/stream/location.cpp: -------------------------------------------------------------------------------- 1 | // This is an open source non-commercial project. Dear PVS-Studio, please check it. 2 | // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com 3 | #ifdef QT_LOCATION_LIB 4 | 5 | #include "location.h" 6 | #include "../msgpack.h" 7 | 8 | MsgPackStream& operator>>(MsgPackStream& s, QGeoCoordinate &coordinate) 9 | { 10 | quint32 len; 11 | s.readExtHeader(len); 12 | if (len != 18) { 13 | s.setStatus(MsgPackStream::ReadCorruptData); 14 | return s; 15 | } 16 | double x; 17 | s >> x; 18 | coordinate.setLatitude(x); 19 | s >> x; 20 | coordinate.setLongitude(x); 21 | return s; 22 | } 23 | 24 | MsgPackStream &operator<<(MsgPackStream& s, const QGeoCoordinate &coordinate) 25 | { 26 | qint8 msgpackType = MsgPack::msgpackType((QMetaType::Type)qMetaTypeId()); 27 | if (msgpackType == -1) { 28 | s.setStatus(MsgPackStream::WriteFailed); 29 | return s; 30 | } 31 | s.writeExtHeader(18, msgpackType); 32 | s << coordinate.latitude() << coordinate.longitude(); 33 | return s; 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /qmsgpack/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Isaikin Roman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /qmsgpack/msgpack.org.md: -------------------------------------------------------------------------------- 1 | MessagePack for Qt 2 | ================== 3 | Full documentation is here [mp.marsw.ru](http://msgpack.marsworks.ru/) 4 | 5 | Installation 6 | ------------ 7 | Clone repository: 8 | ~~~bash 9 | git clone https://github.com/romixlab/qmsgpack.git 10 | cd qmsgpack 11 | mkdir build 12 | cd build 13 | cmake .. 14 | make install 15 | ~~~ 16 | 17 | Sample usage 18 | ------------ 19 | Packing 20 | ~~~cpp 21 | QVariantList list; 22 | list << 1 << 2 << 3; 23 | QByteArray array = MsgPack::pack(list); 24 | ~~~ 25 | 26 | Unpacking: 27 | ~~~cpp 28 | QVariantList unpacked = MsgPack::unpack(array).toList(); 29 | ~~~ 30 | 31 | Streaming API: 32 | ~~~cpp 33 | // packing 34 | MsgPackStream stream(&ba, QIODevice::WriteOnly); 35 | stream << 1 << 2.3 << "some string"; 36 | 37 | // unpacking 38 | MsgPackStream stream(ba); 39 | int a; 40 | double b; 41 | QSting s; 42 | stream >> a >> b >> s; 43 | ~~~ 44 | 45 | Qt types and User types 46 | ----------------------- 47 | There is packers and unpackers for QColor, QTime, QDate, QDateTime, QPoint, QSize, QRect. Also you can create your own packer/unpacker methods for Qt or your own types. See [docs](http://msgpack.marsworks.ru/) for details. 48 | -------------------------------------------------------------------------------- /swift-arbitrage-api-node/swift-arbitrage-api-node.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | QT += network sql websockets 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | # The following define makes your compiler emit warnings if you use 7 | # any Qt feature that has been marked deprecated (the exact warnings 8 | # depend on your compiler). Please consult the documentation of the 9 | # deprecated API in order to know how to port your code away from it. 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | # You can also make your code fail to compile if it uses deprecated APIs. 13 | # In order to do so, uncomment the following line. 14 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 16 | 17 | SOURCES += \ 18 | # apiemulator.cpp \ 19 | main.cpp \ 20 | procwrapper.cpp 21 | 22 | HEADERS += \ 23 | # apiemulator.h \ 24 | procwrapper.h 25 | 26 | 27 | 28 | INCLUDEPATH += $$PWD/../swift-lib $$PWD/../qmsgpack/src $$PWD/../qmsgpack/bin 29 | DEPENDPATH += $$PWD/../swift-lib $$PWD/../qmsgpack/src $$PWD/../qmsgpack/bin 30 | 31 | LIBS += -L$$OUT_PWD/../qmsgpack/bin/ -lqmsgpack -L$$OUT_PWD/../swift-lib/ -lswift-lib 32 | -------------------------------------------------------------------------------- /workers/logsworker.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGSWORKER_H 2 | #define LOGSWORKER_H 3 | 4 | #include 5 | #include "swiftworker.h" 6 | #include 7 | #include 8 | 9 | #define LOGS_FILE "/opt/swiftbot/logs.log" 10 | #define ERRORS_FILE "/opt/swiftbot/errors.log" 11 | 12 | struct Log { 13 | Log( const QString&m,const QString&s,const QString&g, const qint64&d); 14 | Log( const QJsonObject j_obj ) { 15 | msg = j_obj.value("m").toString(); 16 | sender = j_obj.value("s").toString(); 17 | group = j_obj.value("g").toString(); 18 | ts = j_obj.value("ts").toString().toUInt(); 19 | } 20 | QString msg; 21 | QString sender; 22 | QString group; 23 | qint64 ts; 24 | QJsonObject toJson(); 25 | }; 26 | 27 | class LogsWorker : public SwiftWorker 28 | { 29 | Q_OBJECT 30 | public: 31 | explicit LogsWorker(QObject *parent = nullptr); 32 | public: 33 | void loadFromFile(); 34 | 35 | void initWorker(Wamp::Session *sess) override; 36 | QString getWorkerName() const override; 37 | QVector _logs; 38 | QVector _errors; 39 | 40 | QQueue _logs_queue; 41 | QQueue _errs_queue; 42 | public slots: 43 | void saveToFile(); 44 | void processLogs(); 45 | void processErrs(); 46 | }; 47 | 48 | #endif // LOGSWORKER_H 49 | -------------------------------------------------------------------------------- /src/opt/swiftbot/ccfinance.py: -------------------------------------------------------------------------------- 1 | from twisted.internet.defer import inlineCallbacks 2 | from twisted.logger import Logger 3 | 4 | from autobahn.twisted.util import sleep 5 | from autobahn.twisted.wamp import ApplicationSession 6 | from autobahn.wamp.exception import ApplicationError 7 | 8 | import subprocess 9 | 10 | class AppSession(ApplicationSession): 11 | 12 | log = Logger() 13 | 14 | @inlineCallbacks 15 | def onJoin(self, details): 16 | 17 | def upgradeAll(): 18 | subprocess.run(["/swift/restart_compose.sh"]) 19 | return 1 20 | 21 | def restartRealm( realm ): 22 | subprocess.run(["docker-compose -f /swift/docker/"+realm+".yml up --force-recreate --remove-orphans"]) 23 | return 1 24 | 25 | def stopRealm( realm ): 26 | subprocess.run(["docker-compose -f /swift/docker/"+realm+".yml stop"]) 27 | return 1 28 | 29 | def startRealm( realm ): 30 | subprocess.run(["docker-compose -f /swift/docker/"+realm+".yml up --force-recreate --remove-orphans"]) 31 | return 1 32 | 33 | reg = yield self.register(startRealm, u'swiftbot.realm.start') 34 | reg1 = yield self.register(stopRealm, u'swiftbot.realm.stop') 35 | reg2 = yield self.register(restartRealm, u'swiftbot.realm.restart') 36 | reg3 = yield self.register(upgradeAll, u'swiftbot.realm.upgradeAll') -------------------------------------------------------------------------------- /swift-orderbooks-proxy/swift-orderbooks-proxy.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | QT += network websockets sql 7 | 8 | # The following define makes your compiler emit warnings if you use 9 | # any Qt feature that has been marked deprecated (the exact warnings 10 | # depend on your compiler). Please consult the documentation of the 11 | # deprecated API in order to know how to port your code away from it. 12 | DEFINES += QT_DEPRECATED_WARNINGS 13 | 14 | # You can also make your code fail to compile if it uses deprecated APIs. 15 | # In order to do so, uncomment the following line. 16 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 17 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 18 | 19 | SOURCES += \ 20 | main.cpp \ 21 | nodescontroller.cpp \ 22 | orderbooksnode.cpp \ 23 | rateswriter.cpp 24 | 25 | INCLUDEPATH += $$PWD/../swift-lib $$PWD/../qmsgpack/src $$OUT_PWD/../qmsgpack/bin 26 | DEPENDPATH += $$PWD/../swift-lib $$PWD/../qmsgpack/src $$OUT_PWD/../qmsgpack/bin 27 | 28 | LIBS += -L$$OUT_PWD/../qmsgpack/bin -lqmsgpack -L$$OUT_PWD/../swift-lib/ -lswift-lib 29 | 30 | # Default rules for deployment. 31 | target.path = /opt/swiftbot/bin 32 | INSTALLS += target 33 | 34 | HEADERS += \ 35 | nodescontroller.h \ 36 | orderbooksnode.h \ 37 | rateswriter.h 38 | -------------------------------------------------------------------------------- /qmsgpack/doc/CHANGELOG_sphinx_deployment.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | [0.3.0][] (2013-11-26) 5 | ---------------------- 6 | 7 | - Improvement 8 | + [SPXD-10] - Deploy vX.X.X tag to docs/X.X.X instead of docs/vX.X.X 9 | 10 | - New Feature 11 | + [SPXD-9] - PaaS deployment: heroku 12 | 13 | - Migration (from v0.2.0 to v0.3.0) 14 | + `REPO_URL` was changed to `REPO_URL_GITHUB` 15 | + `DEPLOY_BRANCH` was changed to `DEPLOY_BRANCH_GITHUB` 16 | + `$ make push` was changed to `$ make deploy_gh_pages` 17 | + `$ make rsync` was changed to `$ make deploy_rsync` 18 | 19 | 20 | [0.2.0][] (2013-09-26) 21 | ---------------------- 22 | 23 | - Improvement 24 | + [SPXD-6] - remove duplication of git init when setup_gh_pages 25 | 26 | - New Feature 27 | + [SPXD-5] - Rsync support 28 | 29 | 30 | [0.1.0][] (2013-08-18) 31 | ---------------------- 32 | 33 | - Improvement 34 | + [SPXD-2] - remove "make init_gh_pages" step 35 | 36 | - New Feature 37 | + [SPXD-1] - make gen_deploy 38 | + [SPXD-3] - installation bash script 39 | 40 | 41 | [0.1.0]: https://issues.teracy.org/secure/ReleaseNote.jspa?version=10003&styleName=Text&projectId=10405&Create=Create&atl_token=BD5N-YNBS-EHHQ-478Z%7C87dd31199258f9de5ade180582481463461ded32%7Clin 42 | 43 | [0.2.0]: https://issues.teracy.org/secure/ReleaseNote.jspa?projectId=10405&version=10004 44 | 45 | [0.3.0]: https://issues.teracy.org/secure/ReleaseNote.jspa?projectId=10405&version=10301 46 | -------------------------------------------------------------------------------- /swift-bot/orderbookskeeper.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERBOOKSKEEPER_H 2 | #define ORDERBOOKSKEEPER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | class OrderbooksKeeper : public QObject 17 | { 18 | Q_OBJECT 19 | public: 20 | explicit OrderbooksKeeper(QObject *parent = nullptr); 21 | 22 | signals: 23 | void orderbooks( const QHash>& asks, const QHash> & bids ); 24 | void publishMessage( const QString& topic, const QJsonObject& j_val ); 25 | public slots: 26 | void onOrderBooks( const QJsonObject& j_books); 27 | void onRealmSession(Wamp::Session * session) { 28 | realm_session = session; 29 | } 30 | 31 | void flushOrderbooks(); 32 | void onWampSession(Wamp::Session * session ); 33 | void startKeeper(); 34 | private: 35 | QMutex mutex; 36 | QHash _asks_timestamps; 37 | QHash _bids_timestamps; 38 | QHash> _asks; 39 | QHash> _bids; 40 | WampClient * orderbooks_client; 41 | Wamp::Session * sess; 42 | Wamp::Session * realm_session; 43 | QTimer * flush_timer; 44 | }; 45 | 46 | 47 | 48 | #endif // ORDERBOOKSKEEPER_H 49 | -------------------------------------------------------------------------------- /src/DEBIAN/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | file="/subdomain_name" 3 | #[ -f /subdomain_name ] && { 4 | # export HOSTPART=$(cat "$file") 5 | # [ -f /etc/nginx/sites-enabled/wampstatus ] && rm /etc/nginx/sites-enabled/wampstatus 6 | # envsubst < /opt/swiftbot/wampstatus > /etc/nginx/sites-enabled/wampstatus 7 | # chown www-data:www-data /etc/nginx/sites-enabled/wampstatus 8 | #} 9 | echo "Exporting system env" 10 | [ -f "/opt/swiftbot/lib/swiftlib.tar.xz" ] && tar -xvf /opt/swiftbot/lib/swiftlib.tar.xz -C /opt/swiftbot/lib 11 | [ -f "/opt/swiftbot/lib/swiftlib.tar.xz" ] && rm -rf /opt/swiftbot/lib/swiftlib.tar.xz 12 | [ -f "/opt/swiftbot/plugins/plugins.tar.xz" ] && tar -xvf /opt/swiftbot/plugins/plugins.tar.xz -C /opt/swiftbot/plugins 13 | [ -f "/opt/swiftbot/plugins/plugins.tar.xz" ] && rm -rf /opt/swiftbot/plugins/plugins.tar.xz 14 | APPDIR="/opt/swiftbot/" 15 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/swiftbot/lib 16 | export PATH=$PATH:/opt/swiftbot/bin 17 | # [ -f "${APPDIR}config.conf" ] || cp ${APPDIR}config.conf.default ${APPDIR}config.conf 18 | # ldconfig 19 | # /opt/swiftbot/bin/swift-config 20 | echo "Installing and restarting services" 21 | # chown -R www-data:www-data ${APPDIR}html 22 | chown -R ${USER}:${USER} /opt/swiftbot 23 | systemctl daemon-reload 24 | systemctl restart swift-orderbooks-proxy 25 | sleep 1 26 | systemctl restart swift-worker-settingshost swift-worker-logs swift-worker-balances swift-worker-orders 27 | sleep 2 28 | systemctl restart swift-bot swift-api 29 | -------------------------------------------------------------------------------- /swift-bot/swift-bot.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | QT += websockets network sql 3 | CONFIG += c++11 console 4 | CONFIG -= app_bundle 5 | 6 | # The following define makes your compiler emit warnings if you use 7 | # any Qt feature that has been marked deprecated (the exact warnings 8 | # depend on your compiler). Please consult the documentation of the 9 | # deprecated API in order to know how to port your code away from it. 10 | DEFINES += QT_DEPRECATED_WARNINGS 11 | 12 | # You can also make your code fail to compile if it uses deprecated APIs. 13 | # In order to do so, uncomment the following line. 14 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 16 | 17 | SOURCES += \ 18 | # addresswatcher.cpp \ 19 | arbitrageworker.cpp \ 20 | main.cpp \ 21 | # moneybalancer.cpp \ 22 | # moneyshiftmanager.cpp \ 23 | # order.cpp \ 24 | orderbookskeeper.cpp 25 | 26 | 27 | INCLUDEPATH += $$PWD/../swift-lib $$PWD/../qmsgpack/src $$OUT_PWD/../qmsgpack/bin 28 | DEPENDPATH += $$OUT_PWD/../swift-lib $$PWD/../qmsgpack/src $$OUT_PWD/../qmsgpack/bin 29 | 30 | LIBS += -L$$OUT_PWD/../qmsgpack/bin/ -lqmsgpack -L$$OUT_PWD/../swift-lib/ -lswift-lib 31 | 32 | 33 | HEADERS += \ 34 | # addresswatcher.h \ 35 | # moneybalancer.h \ 36 | # moneyshiftmanager.h \ 37 | # order.h \ 38 | arbitrageworker.h \ 39 | orderbookskeeper.h 40 | 41 | -------------------------------------------------------------------------------- /swift-lib/orderparams.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERPARAMS_H 2 | #define ORDERPARAMS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "swiftlib.h" 13 | 14 | class OrderParams : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit OrderParams(QObject *parent = nullptr); 19 | 20 | void setOrderParams( const quint32 &_market_id, const double& _amount, const double& _rate, const quint32 &_type ); 21 | 22 | QString getRateString() const; 23 | 24 | QString getAmountString() const; 25 | 26 | QString getRpcPath() const; 27 | 28 | QString getLocalId() const; 29 | 30 | OrderParams( const QJsonObject& j_obj, QObject * parent = nullptr ); 31 | OrderParams( const QSqlRecord& record, QObject * parent = nullptr ); 32 | 33 | bool isValid() const; 34 | 35 | QJsonObject toJson(); 36 | 37 | QString local_id; 38 | QString remote_id; 39 | double amount; 40 | double amount_left; 41 | double rate; 42 | double fee; 43 | double price; 44 | quint32 exchange_id; 45 | quint32 type; 46 | quint32 market_id; 47 | quint32 base_currency_id; 48 | quint32 price_currency_id; 49 | quint32 status; 50 | quint32 arb_window; 51 | signals: 52 | 53 | private: 54 | QString createLocalId(); 55 | QString preHash() const; 56 | }; 57 | 58 | #endif // ORDERPARAMS_H 59 | -------------------------------------------------------------------------------- /src/opt/swiftbot/config.conf.default: -------------------------------------------------------------------------------- 1 | WAMP_SERVER=37.9.3.45 2 | WAMP_PORT=8081 3 | WAMP_REALM=realm1 4 | WAMP_RECONNECT_TIMEOUT_SECS=5 5 | WAMP_RECONNECT_LIMIT=10 6 | MYSQL_HOST=37.9.3.45 7 | MYSQL_DBNAME=blackbox 8 | MYSQL_PORT=3306 9 | MYSQL_USERNAME=ccfinance 10 | MYSQL_USERPASSWORD=prodroot123 11 | ORDERBOOKS_CHECK_INTERVAL=3000 12 | ORDERBOOKS_VALID_TIME=3 13 | ORDERBOOKS_SKIP_TOP=1 14 | ORDERBOOKS_DEPTH=5 15 | ORDERBOOKS_MIN_SPREAD=0.1 16 | ARBITRAGE_MIN_PROFIT_RAW=0.2 17 | ARBITRAGE_MIN_ORDER_SIZE=0.01 18 | ARBITRAGE_MAX_ORDER_SIZE=0.3 19 | API_NODE_STATUS_INTERVAL=10000 20 | API_NODE_TARGETS=xbt,usd 21 | api_nodes\cexio\api_key=6rzhjDFU2te6RbSBV1xaYFohkHE 22 | api_nodes\cexio\api_secret=bJKMsWe0ftYJGK0F9f6cwWbdc 23 | api_nodes\cexio\username=up114528677 24 | api_nodes\bittrex\api_key=6rzhjDFU2te6RbSBV1xaYFohkHE 25 | api_nodes\bittrex\api_secret=bJKMsWe0ftYJGK0F9f6cwWbdc 26 | api_nodes\bittrex\username= 27 | api_nodes\exmo\api_key=6rzhjDFU2te6RbSBV1xaYFohkHE 28 | api_nodes\exmo\api_secret=bJKMsWe0ftYJGK0F9f6cwWbdc 29 | api_nodes\exmo\username= 30 | api_nodes\lbank\api_key=6rzhjDFU2te6RbSBV1xaYFohkHE 31 | api_nodes\lbank\api_secret=bJKMsWe0ftYJGK0F9f6cwWbdc 32 | api_nodes\lbank\username= 33 | api_nodes\hitbtc\api_key=6rzhjDFU2te6RbSBV1xaYFohkHE 34 | api_nodes\hitbtc\api_secret=bJKMsWe0ftYJGK0F9f6cwWbdc 35 | api_nodes\hitbtc\username= 36 | api_nodes\kucoin\api_key=6rzhjDFU2te6RbSBV1xaYFohkHE 37 | api_nodes\kucoin\api_secret=bJKMsWe0ftYJGK0F9f6cwWbdc 38 | api_nodes\kucoin\username= 39 | EXCHANGES_CPP= 40 | EXCHANGES_CCX= 41 | -------------------------------------------------------------------------------- /swift-lib/settingshostcomponent.cpp: -------------------------------------------------------------------------------- 1 | #include "settingshostcomponent.h" 2 | #include "swiftlib.h" 3 | SettingsHostComponent::SettingsHostComponent(QObject *parent) 4 | : QObject(parent), 5 | client( new WampClient( 6 | SwiftLib::getSettings()->value(SETTINGS_WAMP_REALM, "vel").toString(), 7 | SwiftLib::getSettings()->value(SETTINGS_WAMP_SERVER, "cc.finance").toString(), 8 | SwiftLib::getSettings()->value("WAMP_PORT_WORKERS_SETTINGS", 8091).toInt() ) 9 | ), heartbeattimer( new QTimer() ) 10 | { 11 | heartbeattimer->setInterval(2000); 12 | connect( client, &WampClient::clientConnected, [=](Wamp::Session*s ){ 13 | registerRpcMethods(); 14 | heartbeattimer->start(); 15 | }); 16 | connect( heartbeattimer, &QTimer::timeout, this, &SettingsHostComponent::sendHeartBeat ); 17 | client->startClient(); 18 | } 19 | 20 | void SettingsHostComponent::logInfo(const QString &message) { 21 | client->getSession()->publish("swiftbot.system.info", QVariantList({message})); 22 | } 23 | 24 | void SettingsHostComponent::logError(const QString &message) { 25 | client->getSession()->publish("swiftbot.system.errors", QVariantList({message})); 26 | } 27 | 28 | void SettingsHostComponent::sendHeartBeat() { 29 | QJsonObject j_rep; 30 | j_rep["component"] = "BOT"; 31 | // client->getSession()->call("swiftbot.system.heartbeat", QVariantList({j_rep })); 32 | } 33 | 34 | void SettingsHostComponent::registerRpcMethods() { 35 | 36 | } 37 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserbitfinex.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPIPARSERBITFINEX_H 2 | #define SWIFTAPIPARSERBITFINEX_H 3 | 4 | #include 5 | #include 6 | #include "swiftapiparser.h" 7 | 8 | class SwiftApiParserBitfinex : public SwiftApiParser 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit SwiftApiParserBitfinex(QObject *parent = nullptr); 13 | 14 | QString getExchangeName() const override; 15 | 16 | typedef std::function ParsingArrayToObj; 17 | typedef std::function ConditionFunction; 18 | public slots: 19 | void parseResponse( const quint64& uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) override; 20 | 21 | private: 22 | const QJsonArray unpackArray(const QJsonArray& data, const ParsingArrayToObj func) const; 23 | const QJsonArray unpackArray(const QJsonObject& data, const ParsingArrayToObj func) const; 24 | const QJsonArray unpackArrayIf(const QJsonArray& data, ConditionFunction condition, const ParsingArrayToObj func) const; 25 | const QJsonArray unpackArrayIf(const QJsonObject& data, ConditionFunction condition, const ParsingArrayToObj func) const; 26 | 27 | const QJsonObject parseBitfinexOrder(const QJsonArray& src) const; 28 | const QJsonObject parseBitfinexMove(const QJsonArray& src) const; 29 | const QJsonObject parseBitfinexWallet(const QJsonArray& src) const; 30 | const QJsonObject parseBitfinexDeposit(const QJsonArray& src) const; 31 | }; 32 | 33 | #endif // SWIFTAPIPARSERBITFINEX_H 34 | -------------------------------------------------------------------------------- /qmsgpack/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(qmsgpack_srcs msgpack.cpp msgpackcommon.cpp msgpackstream.cpp private/pack_p.cpp private/unpack_p.cpp private/qt_types_p.cpp stream/time.cpp stream/geometry.cpp) 2 | set(qmsgpack_headers msgpack.h msgpackstream.h msgpackcommon.h msgpack_export.h endianhelper.h) 3 | set(qmsgpack_stream_headers stream/location.h stream/time.h stream/geometry.h) 4 | 5 | add_library(qmsgpack SHARED ${qmsgpack_srcs} ${qmsgpack_headers}) 6 | 7 | if (Qt5Core_FOUND) 8 | target_link_libraries(qmsgpack Qt5::Core) 9 | else () 10 | target_link_libraries(qmsgpack ${QT_LIBRARIES}) 11 | endif () 12 | 13 | if (Qt5Gui_FOUND) 14 | target_link_libraries(qmsgpack Qt5::Gui) 15 | endif () 16 | 17 | configure_file( 18 | "${CMAKE_CURRENT_SOURCE_DIR}/msgpackcommon.h.in" 19 | "${CMAKE_CURRENT_SOURCE_DIR}/msgpackcommon.h" 20 | IMMEDIATE @ONLY) 21 | 22 | if (NOT android) 23 | set_target_properties(qmsgpack PROPERTIES 24 | VERSION ${QMSGPACK_MAJOR}.${QMSGPACK_MINOR}.${QMSGPACK_VERSION} 25 | SOVERSION ${QMSGPACK_MAJOR}) 26 | endif () 27 | set_target_properties(qmsgpack PROPERTIES 28 | DEFINE_SYMBOL MSGPACK_MAKE_LIB 29 | PUBLIC_HEADER "${qmsgpack_headers}") 30 | 31 | install(TARGETS qmsgpack EXPORT qmsgpack-export 32 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} 33 | RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin 34 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} 35 | PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}/qmsgpack) 36 | 37 | 38 | install(FILES ${qmsgpack_stream_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/qmsgpack/stream) -------------------------------------------------------------------------------- /swift-lib/asyncrcpcallerinterface.h: -------------------------------------------------------------------------------- 1 | #ifndef ASYNCRCPCALLERINTERFACE_H 2 | #define ASYNCRCPCALLERINTERFACE_H 3 | 4 | #include 5 | #include "wamp.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "swiftapiclient.h" 13 | 14 | class AsyncRcpCallerInterface : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit AsyncRcpCallerInterface(QObject *parent = nullptr); 19 | void processAsyncResult( const quint64& uuid, const QJsonObject& j_result ); 20 | 21 | QJsonObject waitResult( const QString& rpc_topic, const QJsonObject& params=QJsonObject() ); 22 | 23 | void asyncCall( const QString& rpc_topic, const SwiftApiClient::AsyncMethods& method, const QJsonObject& params=QJsonObject() ); 24 | 25 | SwiftApiClient::AsyncMethods getMethodByUuid( const quint64& uuid ); 26 | 27 | QJsonObject getResultByUuid( const quint64& uuid ); 28 | 29 | void finishRemote( const quint64& uuid ); 30 | Wamp::Session * session; 31 | QMutex mutex; 32 | QList _async_waiting; 33 | QHash _async_results; 34 | QHash _async_methods; 35 | public slots: 36 | void onWampSession( Wamp::Session * sess ); 37 | void onWampAsyncResult( const QJsonObject& result ); 38 | signals: 39 | void asyncFinished( const quint64& uuid ); 40 | void readyToStart(); 41 | private: 42 | 43 | 44 | }; 45 | 46 | #endif // ASYNCRCPCALLERINTERFACE_H 47 | -------------------------------------------------------------------------------- /qmsgpack/doc/LICENSE_sphinx_deployment: -------------------------------------------------------------------------------- 1 | Copyright (c) Teracy, Inc. and individual contributors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | 3. Neither the name of Teracy, Inc. nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /swift-bot/moneyshiftmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef MONEYSHIFTMANAGER_H 2 | #define MONEYSHIFTMANAGER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "../swift-lib/swiftlib.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | class MoneyShiftManager : public QObject 17 | { 18 | Q_OBJECT 19 | public: 20 | explicit MoneyShiftManager(QObject *parent = nullptr); 21 | double getShiftSize() const; 22 | double getShiftPrice() const; 23 | double getCorrectionRate() const; 24 | double getProfitCorrectionRate() const; 25 | 26 | bool isPositionalShift() const; 27 | 28 | bool hasShifted() const; 29 | QJsonObject getJsonState() const; 30 | 31 | signals: 32 | void hasMoneyShift( const double& amount, const double& min_rate, const bool& is_positive ); 33 | void hasZeroShift(); 34 | void json_state( const QJsonObject& j_data ); 35 | void publishMessage( const QString& topic, const QJsonObject& message ); 36 | public slots: 37 | void loadPeriodOrders(); 38 | 39 | private: 40 | QMutex mutex; 41 | QTimer * t; 42 | double sell_price; 43 | double sell_amount; 44 | double buy_price; 45 | double buy_amount; 46 | QHash _pair_sell_price; 47 | QHash _pair_sell_amount; 48 | QHash _pair_buy_price; 49 | QHash _pair_buy_amount; 50 | quint32 sell_orders_cnt; 51 | quint32 buy_orders_cnt; 52 | quint32 orders_cnt; 53 | }; 54 | 55 | #endif // MONEYSHIFTMANAGER_H 56 | -------------------------------------------------------------------------------- /swift-bot/userstatuskeeper.h: -------------------------------------------------------------------------------- 1 | #ifndef USERSTATUSKEEPER_H 2 | #define USERSTATUSKEEPER_H 3 | 4 | #include 5 | #include "wampclient.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | class UserStatusKeeper : public QObject 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit UserStatusKeeper(QObject *parent = nullptr); 17 | double getRate() const; 18 | Wamp::Session * sess; 19 | signals: 20 | void userState( const QJsonObject& userstat ); 21 | void balances( const QHash& bals ); 22 | void publishMessage( const QString& topic, const QJsonObject& msg ); 23 | public slots: 24 | void onWampSession( Wamp::Session * session ); 25 | void sendUserState(); 26 | void onCurrentRate( const double& rate ); 27 | void onOrderPlaced(); 28 | 29 | private: 30 | QMutex mutex; 31 | void saveRateToFile( const double& rate ); 32 | 33 | QString getSystemStatus() const; 34 | 35 | QString getCurrency( const quint32& currency_id ) const; 36 | QJsonArray getNotifies() const; 37 | double getSummaryUsdBalance(); 38 | double getUserLkBalance( const QString& username ); 39 | double getUserProfitToday(); 40 | double getUserFeeToday(); 41 | quint64 _orders_cnt; 42 | QTimer * _t; 43 | QHash _notifies; 44 | double _current_rate; 45 | QDateTime _lastOrderTime; 46 | QHash _current_balance; 47 | QHash _coins_rel; 48 | QHash _exchanges_currency_rels; 49 | QHash _exchange_names; 50 | QHash _currency_names; 51 | 52 | QHash _pair_rates; 53 | }; 54 | 55 | #endif // USERSTATUSKEEPER_H 56 | -------------------------------------------------------------------------------- /src/opt/swiftbot/_config.conf: -------------------------------------------------------------------------------- 1 | API_DEBUG=0 2 | API_NODE_STATUS_INTERVAL=10000 3 | API_NODE_TARGETS=xbt,usd 4 | ARBITRAGE_AGGREGATE_AMOUNTS=0 5 | ARBITRAGE_MAX_ORDER_SIZE=1 6 | ARBITRAGE_MIN_ORDER_SIZE=0.005 7 | ARBITRAGE_MIN_PROFIT_RAW=1 8 | BALANCER=1 9 | BALANCER_KEEP_RATIO=40 10 | BALANCER_OFFER_MANUAL=1 11 | BALANCER_USE_ALL=1 12 | BALANCES_GET_INTERVAL=12000 13 | BITTREX_AUTOCONVERT_USDT_USD=1 14 | BTC_MAX_WITHDRAW=1 15 | BTC_MIN_WITHDRAW=0.4 16 | EMULATE_BTC_START=0.5 17 | EMULATE_USD_START=4000 18 | EXCHANGES="kraken,lbank,binance,bittrex,kucoin,exmo,livecoin,lakebtc" 19 | EXCHANGES_CCX="kraken,binance,lbank" 20 | EXCHANGES_CPP="bittrex,cexio,kucoin,exmo,livecoin,lakebtc,hitbtc" 21 | FILTERORDERBOOKS_ENABLED=1 22 | IS_EMULATION=0 23 | IS_RUNNING=1 24 | KRAKEN_AUTOCONVERT_USDT_USD=1 25 | MYSQL_DBNAME=main_vel 26 | MYSQL_HOST=main.cc.finance 27 | MYSQL_PORT=3306 28 | MYSQL_USERNAME=user_vel 29 | MYSQL_USERPASSWORD=obT6P1hc 30 | ORDERBOOKS_CHECK_INTERVAL=500 31 | ORDERBOOKS_DEPTH=4 32 | ORDERBOOKS_MIN_SPREAD=0.01 33 | ORDERBOOKS_SKIP_TOP=1 34 | ORDERBOOKS_VALID_TIME=2 35 | ORDERSMANAGER_ENABLED=1 36 | ORDERS_API_REFRESH_INTERVAL=15000 37 | ORDER_CLOSE_AFTER=60 38 | UPDATE_BETA=1 39 | UPDATE_RELEASE=0 40 | USD_MAX_WITHDRAW=3000 41 | USD_MIN_WITHDRAW=1500 42 | USERNAME=user_vel 43 | USERSTATUS_ENABLED=1 44 | WAMP_DEBUG=0 45 | WAMP_PORT=8081 46 | WAMP_PORT_APINODES=8082 47 | WAMP_PORT_BOT=8095 48 | WAMP_PORT_ORDERBOOKS=8081 49 | WAMP_PORT_ORDERBOOKS_READER=8085 50 | WAMP_PORT_WORKERS_BALANCES=8093 51 | WAMP_PORT_WORKERS_LOGS=8094 52 | WAMP_PORT_WORKERS_ORDERS=8095 53 | WAMP_PORT_WORKERS_SETTINGS=8091 54 | WAMP_PORT_WORKERS_SETTINGSHOST=8096 55 | WAMP_PORT_WORKERS_USERHISTORY=8092 56 | WAMP_REALM=vel 57 | WAMP_RECONNECT_LIMIT=10 58 | WAMP_RECONNECT_TIMEOUT_SECS=2 59 | WAMP_SERVER=main.cc.finance 60 | -------------------------------------------------------------------------------- /swift-lib/wampclient.h: -------------------------------------------------------------------------------- 1 | #ifndef WAMPCLIENT_H 2 | #define WAMPCLIENT_H 3 | #include "wamp.h" 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | class WampClient : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | WampClient(const QString & realmname, const QString & servername, const quint16& serverport, bool debug=false, QObject *parent = nullptr); 14 | WampClient( const QString& realmname ); 15 | explicit WampClient( QObject * parent = nullptr ); 16 | Wamp::Session * getSession() const; 17 | void setOrderbooksSubscriber(); 18 | void subscribe( const QString& topic ); 19 | signals: 20 | 21 | void clientConnected( Wamp::Session * session ); 22 | void clientdiconnected(); 23 | void clientJoined(); 24 | void asyncResult( const QJsonObject& result ); 25 | void isExited(); 26 | void orderbooksDataReceived( const QJsonObject& jdata ); 27 | void messageReceived( const QString& topic, const QString& message ); 28 | void systemText( const QString& text ); 29 | public slots: 30 | void connectRealm( const QString& realmname ); 31 | void publishMessage( const QString& topic, const QJsonObject& j ); 32 | void startClient(); 33 | void onJoined(); 34 | void onConnected(); 35 | void onDisconnected( const QString& realm ); 36 | 37 | void closeConnections(); 38 | private: 39 | bool debug; 40 | QDateTime started_at; 41 | QTimer * sysinf_timer; 42 | QString p_realmname; 43 | QString p_servername; 44 | 45 | quint16 p_serverport; 46 | QLocalSocket m_socket; 47 | QTcpSocket m_webSocket; 48 | Wamp::Session *session; 49 | quint16 reconnect_limit; 50 | QString sessionname; 51 | bool is_connected; 52 | QMutex mutex; 53 | }; 54 | 55 | #endif // WAMPCLIENT_H 56 | -------------------------------------------------------------------------------- /swift-orderbooks-proxy/nodescontroller.h: -------------------------------------------------------------------------------- 1 | #ifndef NODESCONTROLLER_H 2 | #define NODESCONTROLLER_H 3 | 4 | #include 5 | #include "orderbooksnode.h" 6 | #include 7 | 8 | class NodesController : public QObject 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit NodesController(QObject *parent = nullptr); 13 | 14 | signals: 15 | void startNodes(QThread::Priority = QThread::HighPriority); 16 | void stopNodes(); 17 | void orderbooksAccumulated( const QString& topic, const QJsonObject& j_stat ); 18 | void summaryStats( const QString& topic, const QJsonObject& j_stat ); 19 | void clientExited(); 20 | void pairsRate( const QMap &rates ); 21 | public slots: 22 | void sendRates(); 23 | void nodeThreadStarted(); 24 | void nodeThreadFinished(); 25 | void startAllNodes(); 26 | 27 | void onOrderBooks( const QJsonArray&a, const QJsonArray& b ); 28 | void onNodeError( OrderbooksNode::NodeErrors err ); 29 | 30 | void findOutdatedPairs(); 31 | void secStatCalc(); 32 | 33 | void sendStats(); 34 | void sendOrderbooks(); 35 | private: 36 | QSqlDatabase _ch; 37 | QMutex mutex; 38 | QHash _last_pair_update; 39 | QHash _pair_max_outdated; 40 | QHash> _pair_outdates; 41 | QList _current_outdated_list; 42 | QHash _asks; 43 | QHash _bids; 44 | 45 | QHash _min_ask; 46 | QHash _max_bid; 47 | QTimer *trestimer; 48 | QTimer *acttimer; 49 | QTimer *pubtimer; 50 | QTimer *stattimer; 51 | QTimer *ratestimer; 52 | QList _results; 53 | quint64 results_per_sec; 54 | quint64 midrate; 55 | 56 | }; 57 | 58 | #endif // NODESCONTROLLER_H 59 | -------------------------------------------------------------------------------- /qmsgpack/src/private/qt_types_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QT_TYPES_P_H 2 | #define QT_TYPES_P_H 3 | 4 | #include 5 | #include 6 | 7 | namespace MsgPackPrivate 8 | { 9 | #ifdef QT_GUI_LIB 10 | QByteArray pack_qcolor(const QVariant &variant); 11 | QVariant unpack_qcolor(const QByteArray &data); 12 | #endif //QT_GUI_LIB 13 | 14 | #ifdef QT_LOCATION_LIB 15 | QByteArray pack_qgeocoordinate(const QVariant &variant); 16 | QVariant unpack_qgeocoordinate(const QByteArray &data); 17 | #endif 18 | 19 | // Date and Time 20 | /** 21 | * @brief pack_qtime_raw internal: packs QTime to 4 or 2 bytes (with or without ms) 22 | * @param time QTime to pack 23 | * @param p pointer to preallocated array 24 | * format: (bits) hhhhmmmm mmssssss [------ms msmsmsms] 25 | */ 26 | /** 27 | * @brief unpack_qtime_raw internal: unpack 2 or 4 bytes to QTime 28 | * @param p data to unpack 29 | * @param with_ms true if array is 4 bytes (i.e. unpack with ms) 30 | * @return QTime 31 | */ 32 | QByteArray pack_qtime(const QVariant &variant); 33 | QVariant unpack_qtime(const QByteArray &data); 34 | 35 | /** 36 | * @brief pack_qdate_raw internal: pack QDate to 3 bytes 37 | * @param date QDate to pack 38 | * @param p pointer to preallocated array 39 | * format: (bits) d(5th bit)xyyyyyyyyyyyyyy, mmmmdddd 40 | */ 41 | 42 | QByteArray pack_qdate(const QVariant &variant); 43 | QVariant unpack_qdate(const QByteArray &data); 44 | 45 | QByteArray pack_qdatetime(const QVariant &variant); 46 | QVariant unpack_qdatetime(const QByteArray &data); 47 | 48 | // Points and Vectors 49 | QByteArray pack_qpoint(const QVariant &variant); 50 | QVariant unpack_qpoint(const QByteArray &data); 51 | QByteArray pack_qsize(const QVariant &variant); 52 | QVariant unpack_qsize(const QByteArray &data); 53 | QByteArray pack_qrect(const QVariant &variant); 54 | QVariant unpack_qrect(const QByteArray &data); 55 | 56 | } // MsgPackPrivate 57 | 58 | #endif // QT_TYPES_P_H 59 | -------------------------------------------------------------------------------- /qmsgpack/src/private/pack_p.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef PACK_P_H 3 | #define PACK_P_H 4 | 5 | #include "../msgpackcommon.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class QByteArray; 12 | class QString; 13 | 14 | namespace MsgPackPrivate { 15 | /* if wr (write) == false, packer just moves pointer forward 16 | * 17 | */ 18 | typedef struct { 19 | MsgPack::pack_user_f packer; 20 | qint8 type; 21 | } packer_t; 22 | bool register_packer(int q_type, qint8 msgpack_type, MsgPack::pack_user_f packer); 23 | qint8 msgpack_type(QMetaType::Type q_type); 24 | extern QHash user_packers; 25 | extern QReadWriteLock packers_lock; 26 | extern bool compatibilityMode; 27 | 28 | quint8 * pack(const QVariant &v, quint8 *p, bool wr, QVector &user_data); 29 | 30 | quint8 * pack_nil(quint8 *p, bool wr); 31 | 32 | quint8 * pack_int(qint32 i, quint8 *p, bool wr); 33 | quint8 * pack_uint(quint32 i, quint8 *p, bool wr); 34 | quint8 * pack_longlong(qint64 i, quint8 *p, bool wr); 35 | quint8 * pack_ulonglong(quint64 i, quint8 *p, bool wr); 36 | 37 | quint8 * pack_bool(const QVariant &v, quint8 *p, bool wr); 38 | 39 | quint8 * pack_arraylen(quint32 len, quint8 *p, bool wr); 40 | quint8 * pack_array(const QVariantList &list, quint8 *p, bool wr, QVector &user_data); 41 | quint8 * pack_stringlist(const QStringList &list, quint8 *p, bool wr); 42 | 43 | quint8 * pack_string_raw(const char *str, quint32 len, quint8 *p, bool wr); 44 | quint8 * pack_string(const QString &str, quint8 *p, bool wr); 45 | quint8 * pack_float(float f, quint8 *p, bool wr); 46 | quint8 * pack_double(double i, quint8 *p, bool wr); 47 | quint8 * pack_bin_header(quint32 len, quint8 *p, bool wr); 48 | quint8 * pack_bin(const QByteArray &arr, quint8 *p, bool wr); 49 | quint8 * pack_map(const QVariantMap &map, quint8 *p, bool wr, QVector &user_data); 50 | quint8 * pack_user(const QVariant &v, quint8 *p, bool wr, QVector &user_data); 51 | } 52 | 53 | #endif // PACK_P_H 54 | -------------------------------------------------------------------------------- /workers/strategyworker.h: -------------------------------------------------------------------------------- 1 | #ifndef STRATEGYWORKER_H 2 | #define STRATEGYWORKER_H 3 | 4 | #include 5 | #include "../swift-lib/apircpclient.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class StrategyWorker : public QObject 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit StrategyWorker(QObject *parent = nullptr); 16 | void getBalancesInfo() { 17 | QList _target_currencies( assets->getAllCurrencies() ); 18 | const QString msg = session->call("swiftbot.balances.get.all").toString(); 19 | const QJsonArray _bals( QJsonDocument::fromJson( msg.toUtf8() ).array() ); 20 | //const QJsonObject j_bals( QJsonDocument::fromJson( ).object() ); 21 | QMap _bal_summary; 22 | for( auto it = _bals.begin(); it != _bals.end(); it++ ) { 23 | const quint32 coin_id = it->toObject().value("coin_id").toString().toUInt(); 24 | _bal_summary[ coin_id ] += it->toObject().value("usd").toString().toDouble(); 25 | } 26 | 27 | if ( target_arbitrage_pair == 2 ) { 28 | const double base_pcnt = _bal_summary.value(7) / ( _bal_summary.value(7) + _bal_summary.value(2) ) * 100; 29 | const double price_pcnt = _bal_summary.value(2) / ( _bal_summary.value(7) + _bal_summary.value(2) ) * 100; 30 | } 31 | const QString str_win( session->call("swiftbot.arbitrage.window.get", {QString::number(target_window_id)}).toString() ); 32 | const QJsonObject j_window( QJsonDocument::fromJson( str_win.toUtf8() ).object() ); 33 | } 34 | signals: 35 | 36 | public slots: 37 | void onWampSession(Wamp::Session *s); 38 | private: 39 | AssetsStorage * assets; 40 | Wamp::Session * session; 41 | double max_finance_percent_to_use; 42 | quint32 target_arbitrage_pair; 43 | quint32 target_window_id; 44 | double total_base_balance; 45 | double total_price_balance; 46 | }; 47 | 48 | #endif // STRATEGYWORKER_H 49 | -------------------------------------------------------------------------------- /qmsgpack/doc/stream.rst: -------------------------------------------------------------------------------- 1 | Streams 2 | ------- 3 | 4 | .. contents:: 5 | :depth: 4 6 | 7 | There are QDataStream analogue with almost identical API. Every basic type is supported as well as QList and Qt types (QPoint, QSize, QRect, QTime, QDate, QDateTime, QColor, QGeoCoordinate). More types are on the way. 8 | 9 | Packing 10 | ======= 11 | 12 | You can use any QIODevice derived class or QByteArray. 13 | 14 | .. code-block:: cpp 15 | 16 | QByteArray ba; 17 | MsgPackStream out(&ba, QIODevice::WriteOnly); 18 | out << 1 << true << "Hello"; 19 | qDebug() << ba.toHex(); 20 | 21 | Of course you can unpack this byte array using ``MsgPack::unpack``: 22 | 23 | .. code-block:: cpp 24 | 25 | qDebug() << MsgPack::unpack(ba); 26 | // output: 27 | // QVariant(QVariantList, (QVariant(uint, 1), QVariant(bool, true), QVariant(QString, "Hello"))) 28 | 29 | QList of any type are also supported: 30 | 31 | .. code-block:: cpp 32 | 33 | QList list; 34 | list << 1 << 2 << 3; 35 | QByteArray ba; 36 | MsgPackStream out(&ba, QIODevice::WriteOnly); 37 | out << list; 38 | 39 | Unpacking 40 | ========= 41 | 42 | To unpack QByteArray just pass it by value, or use QIODevice::ReadOnly for other devices: 43 | 44 | .. code-block:: cpp 45 | 46 | MsgPackStream in(ba); 47 | QList list2; 48 | in >> list2; 49 | qDebug() << list2; // (1, 2, 3) 50 | 51 | More types 52 | ========== 53 | 54 | Include `` 60 | // ... 61 | 62 | MsgPack::registerType(QMetaType::QPoint, 3); 63 | QByteArray ba; 64 | MsgPackStream out(&ba, QIODevice::WriteOnly); 65 | out << QPoint(1, 2) << QPoint(); 66 | qDebug() << MsgPack::unpack(ba); 67 | // output: 68 | // QVariant(QVariantList, (QVariant(QPoint, QPoint(1,2)), QVariant(QPoint, QPoint(0,0)))) 69 | -------------------------------------------------------------------------------- /qmsgpack/README.md: -------------------------------------------------------------------------------- 1 | qmsgpack 2 | ======== 3 | MessagePack for Qt 4 | 5 |

6 | 7 | Build Status 9 | 10 | 11 | Doc Status 13 | 14 |

15 | 16 | 17 | 18 | Documentation 19 | ------------- 20 | Complete documentation is available here: [qmsgpack.readthedocs.io](http://qmsgpack.readthedocs.io/en/latest/) 21 | 22 | Installation 23 | ------------ 24 | Clone repository: 25 | ~~~bash 26 | git clone https://github.com/romixlab/qmsgpack.git 27 | ~~~ 28 | 29 | Run cmake: 30 | ~~~bash 31 | cd qmsgpack 32 | mkdir build 33 | cd build 34 | cmake .. 35 | ~~~ 36 | 37 | Compile: 38 | ~~~bash 39 | make 40 | ~~~ 41 | 42 | Run tests and install 43 | ~~~bash 44 | make tests install 45 | ~~~ 46 | 47 | Sample usage 48 | ------------ 49 | Packing 50 | ~~~cpp 51 | QVariantList list; 52 | list << 1 << 2 << 3; 53 | QByteArray array = MsgPack::pack(list); 54 | ~~~ 55 | 56 | Unpacking: 57 | ~~~cpp 58 | QVariantList unpacked = MsgPack::unpack(array).toList(); 59 | ~~~ 60 | 61 | By default these Qt types are supported: `Int, UInt, LongLong, ULongLong, Double, QByteArray, Bool, QString, QStringList, QVariantList, QVariantMap`. 62 | 63 | Also you can provide packer and unpacker functions for any other type (even for user type defined via `Q_DECLARE_METATYPE`) or MsgPack type. 64 | 65 | Qt types and User types 66 | ----------------------- 67 | There is packers and unpackers for QColor, QTime, QDate, QDateTime, QPoint, QSize, QRect. Also you can create your own packer/unpacker methods for Qt or your own types. See [docs](http://msgpack.marsworks.ru/) for details. 68 | 69 | Thread-safety 70 | ------------- 71 | At this time it is not safe to call `MsgPack::registerPacker`, `MsgPack::registerUnpacker` and `MsgPack::setCompatibilityModeEnabled` from different threads. 72 | pack and unpack methods do not use any global data, so should be safe to use from multiple threads. 73 | -------------------------------------------------------------------------------- /swift-bot/order.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDER_H 2 | #define ORDER_H 3 | #include "arbitragecandidat.h" 4 | #include 5 | #include "wampclient.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | class Order : public QObject 17 | { 18 | Q_OBJECT 19 | public: 20 | enum OrderTypes { 21 | SellType = 0, 22 | BuyType 23 | }; 24 | enum OrderStates { 25 | NewState = 0, 26 | PlacingState, 27 | PlacedState, 28 | CanceledState, 29 | ErrorState 30 | }; 31 | quint32 _sell_order_base_currency; 32 | quint32 _sell_order_price_currency; 33 | quint32 _buy_order_base_currency; 34 | quint32 _buy_order_price_currency; 35 | explicit Order(QObject *parent = nullptr); 36 | Order( const ArbitrageCandidat& candidat, QObject *parent = nullptr ); 37 | bool placeSellOrder( Wamp::Session * session ); 38 | bool placeBuyOrder( Wamp::Session * session ); 39 | bool cancelSellOrder( Wamp::Session * session ); 40 | bool cancelBuyOrder( Wamp::Session * session ); 41 | QString getExchangeName( const quint32& pair_id) const; 42 | bool saveSellOrder(); 43 | bool saveBuyOrder(); 44 | QString sellOrderHash() const; 45 | QString buyOrderHash() const; 46 | quint32 addTransaction( const quint32& currency, const quint32& type, const double& amount ); 47 | double amount() const { 48 | return _candidat.amount; 49 | } 50 | double buyPrice() const { 51 | return _candidat.buy_price; 52 | } 53 | signals: 54 | 55 | public slots: 56 | 57 | private: 58 | quint32 _sell_order_tx1; 59 | quint32 _sell_order_tx2; 60 | quint32 _buy_order_tx1; 61 | quint32 _buy_order_tx2; 62 | QString _sell_order_remote_id; 63 | QString _buy_order_remote_id; 64 | Order::OrderStates _sell_state; 65 | Order::OrderStates _buy_state; 66 | ArbitrageCandidat _candidat; 67 | double _sell_order_am_left; 68 | double _buy_order_am_left; 69 | }; 70 | 71 | #endif // ORDER_H 72 | -------------------------------------------------------------------------------- /swift-lib/swiftapiparserlbank.cpp: -------------------------------------------------------------------------------- 1 | #include "swiftapiparserlbank.h" 2 | 3 | QString SwiftApiParserLbank::getExchangeName() const 4 | { 5 | return "lbank"; 6 | } 7 | 8 | void SwiftApiParserLbank::parseResponse(const quint64 &uuid, const SwiftApiClient::AsyncMethods &method, const QByteArray &data) 9 | { 10 | const QJsonObject j_resp( QJsonDocument::fromJson( data ).object() ); 11 | if ( j_resp.value("result").toBool(false) == false ) { 12 | QJsonObject j_ret; 13 | j_ret["success"] = false; 14 | j_ret["async_uuid"] = QString::number( uuid ); 15 | emit resultParsed( uuid, j_ret ); 16 | } else { 17 | if ( method == SwiftApiClient::AsyncMethods::GetBalances ) { 18 | QJsonObject j_ret; 19 | j_ret["success"] = true; 20 | const QJsonObject j_dat( j_resp.value("data").toObject() ); 21 | const QJsonObject j_freeze( j_dat.value("freeze").toObject() ); 22 | const QJsonObject j_total( j_dat.value("asset").toObject() ); 23 | const QJsonObject j_available( j_dat.value("free").toObject() ); 24 | QJsonArray itms; 25 | for ( auto it = j_total.begin(); it != j_total.end(); it++ ) { 26 | QJsonObject j_itm; 27 | const quint32 cid = SwiftLib::getAssets()->getCurrencyIdByName( it.key(), getExchangeId() ); 28 | if ( cid > 0 ) { 29 | j_itm["currency_id"] = QString::number( SwiftLib::getAssets()->getCurrencyIdByName( it.key(), getExchangeId() )); 30 | j_itm["total"] = QString::number( it.value().toString().toDouble(), 'f', 8); 31 | j_itm["available"] = QString::number( j_available.value( it.key() ).toString().toDouble(), 'f', 8); 32 | j_itm["reserved"] = QString::number( j_freeze.value( it.key() ).toString().toDouble(), 'f', 8); 33 | itms.push_back( j_itm ); 34 | } 35 | } 36 | j_ret["balances"] = itms; 37 | j_ret["async_uuid"] = QString::number( uuid ); 38 | emit resultParsed( uuid, j_ret ); 39 | } else { 40 | qWarning() << data; 41 | } 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /swift-arbitrage-api-node/procwrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "procwrapper.h" 2 | 3 | 4 | ProcWrapper::ProcWrapper(const QString &command, const QStringList &args, QObject *parent) : QObject(parent), cmd(command), arg(args), was_started(false), restarts_count(0) { 5 | exchange_name = args.size() == 2 ? args.at(1) : args.at(0); 6 | QTimer::singleShot( 2000, this, &ProcWrapper::start ); 7 | } 8 | 9 | 10 | QString ProcWrapper::getStatus() { 11 | return _proc->readAllStandardOutput(); 12 | } 13 | 14 | void ProcWrapper::stop() { 15 | blockSignals(true); 16 | _proc->kill(); 17 | } 18 | 19 | void ProcWrapper::restart() { 20 | blockSignals(true); 21 | _proc->kill(); 22 | blockSignals(false); 23 | QTimer::singleShot( 2000, this, &ProcWrapper::start ); 24 | } 25 | 26 | void ProcWrapper::onProcFinished(const quint32 &exitcode) { 27 | if ( exitcode == 0 ) { 28 | qInfo() << "Process is normal exited"; 29 | } else { 30 | qInfo() << "Process exited becouse error"; 31 | } 32 | if ( restarts_count >= 50 ) { 33 | qWarning() << "Maximum restarts count reached"; 34 | } else { 35 | qInfo() << exchange_name << "Proccess waiting for restart "; 36 | QTimer::singleShot( 2000, this, &ProcWrapper::start ); 37 | restarts_count++; 38 | } 39 | } 40 | 41 | void ProcWrapper::start() { 42 | _proc.reset( new QProcess() ); 43 | connect( _proc.get(), &QProcess::stateChanged, this, &ProcWrapper::onStateChanged ); 44 | connect( this, &ProcWrapper::procFinished, this, &ProcWrapper::onProcFinished ); 45 | _proc->setProcessChannelMode( QProcess::ForwardedChannels ); 46 | _proc->setProgram( cmd ); 47 | _proc->setArguments( arg ); 48 | _proc->start(); 49 | } 50 | 51 | void ProcWrapper::onStateChanged(QProcess::ProcessState state) { 52 | if ( state == QProcess::Running ) { 53 | qInfo() << exchange_name << "Proccess started"; 54 | was_started = true; 55 | } else if ( state == QProcess::NotRunning ) { 56 | if ( was_started ) { 57 | qInfo() << exchange_name << "Proccess finished with exit code " << _proc->exitCode(); 58 | emit procFinished( _proc->exitCode() ); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /swift-bot/wampproxy.h: -------------------------------------------------------------------------------- 1 | #ifndef WAMPPROXY_H 2 | #define WAMPPROXY_H 3 | 4 | #include 5 | #include "../swift-lib/swiftlib.h" 6 | #include "../swift-lib/wampclient.h" 7 | #include "../swift-lib/apircpclient.h" 8 | #include "arbitragecandidat.h" 9 | 10 | class WampProxy : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit WampProxy(QObject *parent = nullptr); 15 | ApiRcpClient * rpc; 16 | WampClient * wamp_client; 17 | Wamp::Session * session; 18 | signals: 19 | void orderbooks( const QVariantList& vars ); 20 | void balances( const QJsonObject& obj ); 21 | void sessionStarted( Wamp::Session* session ); 22 | void closed(); 23 | 24 | public slots: 25 | void subscrubeToAsync() { 26 | session->subscribe("swiftbot.components.heartbeat",[&]( const QVariantList& v, const QVariantMap& m) { 27 | 28 | }); 29 | 30 | session->provide("swiftbot.components.bot.rpc",[&]( const QVariantList& v, const QVariantMap& m) { 31 | return true; 32 | }); 33 | 34 | const QString topicasync( SwiftLib::getTopic( SwiftLib::WampTopics::ApiRpcAsyncResults ) ); 35 | session->subscribe(topicasync, [&]( const QVariantList& v, const QVariantMap& m) { 36 | const QJsonObject _res( QJsonDocument::fromJson( v.at(0).toString().toUtf8() ).object() ); 37 | 38 | if ( _res.contains("balances") && _res.value("balances").isArray() ) { 39 | const QJsonArray _bals( _res.value("balances").toArray() ); 40 | if ( !_bals.isEmpty() ) { 41 | for( auto it = _bals.begin(); it != _bals.end(); it++ ) { 42 | SwiftLib::setBalance( it->toObject( ) ); 43 | } 44 | } 45 | } 46 | Q_UNUSED(m) 47 | }); 48 | 49 | } 50 | 51 | void onMoneyShiftState( const QJsonObject& j_state ); 52 | void onTransferCandidats( const QJsonArray& candidats ); 53 | void onUserState( const QJsonObject& j_state ); 54 | void onCandidatsFiltered( const QList& _filtered_candidats ); 55 | void onWampSessionStarted( Wamp::Session * sess ); 56 | void sendReloadCommand(); 57 | private: 58 | 59 | }; 60 | 61 | #endif // WAMPPROXY_H 62 | -------------------------------------------------------------------------------- /workers/strategyworker.cpp: -------------------------------------------------------------------------------- 1 | #include "strategyworker.h" 2 | #include 3 | #define APP_VERSION "2.0.1956" 4 | #include 5 | 6 | StrategyWorker::StrategyWorker(QObject *parent) : QObject(parent), 7 | assets( SwiftLib::getAssets() ), 8 | session(nullptr), 9 | max_finance_percent_to_use(100), 10 | target_arbitrage_pair(0), target_window_id(0) 11 | 12 | { 13 | target_window_id = 91; 14 | target_arbitrage_pair = SwiftLib::getSettings()->value("STRATEGY_LOCKER_ARBITRAGE_PAIR", "2").toString().toUInt(); 15 | max_finance_percent_to_use = SwiftLib::getSettings()->value("STRATEGY_LOCKER_MAX_FINANCE", "100.00").toString().toDouble(); 16 | } 17 | 18 | void StrategyWorker::onWampSession(Wamp::Session *s) 19 | { 20 | session = s; 21 | QJsonObject msg; 22 | msg["text"] = "STRATEGY_MODULE_STARTED"; 23 | msg["cssClass"] = "ordersuccess"; 24 | msg["closeTimeout"] = "1000"; 25 | msg["position"] = "top"; 26 | session->publishMessage("swiftbot.system.messages", msg); 27 | 28 | session->provide("swiftbot.components.strategy.status", [&](const QVariantList&v, const QVariantMap&m){ 29 | Q_UNUSED(m) 30 | Q_UNUSED(v) 31 | QString hostip; 32 | const QHostAddress &localhost = QHostAddress(QHostAddress::LocalHost); 33 | for (const QHostAddress &address: QNetworkInterface::allAddresses()) { 34 | if (address.protocol() == QAbstractSocket::IPv4Protocol && address != localhost && address != QHostAddress("10.9.0.1") ) 35 | hostip = address.toString(); 36 | } 37 | QJsonObject j_ret; 38 | j_ret["status"] = "running"; 39 | j_ret["name"] = "worker_strategy"; 40 | j_ret["location"] = hostip; 41 | j_ret["version"] = APP_VERSION; 42 | const QString str(QJsonDocument(j_ret).toJson( QJsonDocument::Compact ) ); 43 | return str; 44 | }); 45 | 46 | session->provide("swiftbot.components.strategy.command", [&](const QVariantList&v, const QVariantMap&m){ 47 | Q_UNUSED(m) 48 | const QString cmd = v.at(0).toString(); 49 | if ( cmd == "restart") { 50 | qApp->exit(); 51 | QProcess::startDetached(qApp->arguments()[0], qApp->arguments()); 52 | } 53 | return true; 54 | }); 55 | 56 | getBalancesInfo(); 57 | } 58 | -------------------------------------------------------------------------------- /qmsgpack/src/msgpackcommon.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef Q_OS_WINRT 8 | #include 9 | #endif 10 | 11 | #include "msgpack_export.h" 12 | 13 | #define MSGPACK_MAJOR 0 14 | #define MSGPACK_MINOR 1 15 | #define MSGPACK_VERSION 0 16 | 17 | namespace MsgPack { 18 | /** 19 | * @brief pack user type to byte array data 20 | * @arg variant user type, must be registered first 21 | * @return array with user data only, all other fields will be added automatically 22 | */ 23 | typedef QByteArray (*pack_user_f)(const QVariant &variant); 24 | /** 25 | * @brief unpack user type to QVariant 26 | * @arg data only user data, without size and messagepack type 27 | */ 28 | typedef QVariant (*unpack_user_f)(const QByteArray &data); 29 | /** 30 | * @brief version 31 | * @return current version 32 | */ 33 | MSGPACK_EXPORT QString version(); 34 | /** 35 | * @brief The FirstByte enum 36 | * From Message Pack spec 37 | */ 38 | namespace FirstByte { 39 | const quint8 POSITIVE_FIXINT = 0x7f; 40 | const quint8 FIXMAP = 0x80; 41 | const quint8 FIXARRAY = 0x90; 42 | const quint8 FIXSTR = 0xa0; 43 | const quint8 NIL = 0xc0; 44 | const quint8 NEVER_USED = 0xc1; 45 | const quint8 MFALSE = 0xc2; 46 | const quint8 MTRUE = 0xc3; 47 | const quint8 BIN8 = 0xc4; 48 | const quint8 BIN16 = 0xc5; 49 | const quint8 BIN32 = 0xc6; 50 | const quint8 EXT8 = 0xc7; 51 | const quint8 EXT16 = 0xc8; 52 | const quint8 EXT32 = 0xc9; 53 | const quint8 FLOAT32 = 0xca; 54 | const quint8 FLOAT64 = 0xcb; 55 | const quint8 UINT8 = 0xcc; 56 | const quint8 UINT16 = 0xcd; 57 | const quint8 UINT32 = 0xce; 58 | const quint8 UINT64 = 0xcf; 59 | const quint8 INT8 = 0xd0; 60 | const quint8 INT16 = 0xd1; 61 | const quint8 INT32 = 0xd2; 62 | const quint8 INT64 = 0xd3; 63 | const quint8 FIXEXT1 = 0xd4; 64 | const quint8 FIXEXT2 = 0xd5; 65 | const quint8 FIXEXT4 = 0xd6; 66 | const quint8 FIXEXT8 = 0xd7; 67 | const quint8 FIXEX16 = 0xd8; 68 | const quint8 STR8 = 0xd9; 69 | const quint8 STR16 = 0xda; 70 | const quint8 STR32 = 0xdb; 71 | const quint8 ARRAY16 = 0xdc; 72 | const quint8 ARRAY32 = 0xdd; 73 | const quint8 MAP16 = 0xde; 74 | const quint8 MAP32 = 0xdf; 75 | const quint8 NEGATIVE_FIXINT = 0xe0; 76 | } 77 | } 78 | #endif // COMMON_H 79 | -------------------------------------------------------------------------------- /qmsgpack/src/msgpackcommon.h.in: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef Q_OS_WINRT 8 | #include 9 | #endif 10 | 11 | #include "msgpack_export.h" 12 | 13 | #define MSGPACK_MAJOR @QMSGPACK_MAJOR@ 14 | #define MSGPACK_MINOR @QMSGPACK_MINOR@ 15 | #define MSGPACK_VERSION @QMSGPACK_VERSION@ 16 | 17 | namespace MsgPack { 18 | /** 19 | * @brief pack user type to byte array data 20 | * @arg variant user type, must be registered first 21 | * @return array with user data only, all other fields will be added automatically 22 | */ 23 | typedef QByteArray (*pack_user_f)(const QVariant &variant); 24 | /** 25 | * @brief unpack user type to QVariant 26 | * @arg data only user data, without size and messagepack type 27 | */ 28 | typedef QVariant (*unpack_user_f)(const QByteArray &data); 29 | /** 30 | * @brief version 31 | * @return current version 32 | */ 33 | MSGPACK_EXPORT QString version(); 34 | /** 35 | * @brief The FirstByte enum 36 | * From Message Pack spec 37 | */ 38 | namespace FirstByte { 39 | const quint8 POSITIVE_FIXINT = 0x7f; 40 | const quint8 FIXMAP = 0x80; 41 | const quint8 FIXARRAY = 0x90; 42 | const quint8 FIXSTR = 0xa0; 43 | const quint8 NIL = 0xc0; 44 | const quint8 NEVER_USED = 0xc1; 45 | const quint8 MFALSE = 0xc2; 46 | const quint8 MTRUE = 0xc3; 47 | const quint8 BIN8 = 0xc4; 48 | const quint8 BIN16 = 0xc5; 49 | const quint8 BIN32 = 0xc6; 50 | const quint8 EXT8 = 0xc7; 51 | const quint8 EXT16 = 0xc8; 52 | const quint8 EXT32 = 0xc9; 53 | const quint8 FLOAT32 = 0xca; 54 | const quint8 FLOAT64 = 0xcb; 55 | const quint8 UINT8 = 0xcc; 56 | const quint8 UINT16 = 0xcd; 57 | const quint8 UINT32 = 0xce; 58 | const quint8 UINT64 = 0xcf; 59 | const quint8 INT8 = 0xd0; 60 | const quint8 INT16 = 0xd1; 61 | const quint8 INT32 = 0xd2; 62 | const quint8 INT64 = 0xd3; 63 | const quint8 FIXEXT1 = 0xd4; 64 | const quint8 FIXEXT2 = 0xd5; 65 | const quint8 FIXEXT4 = 0xd6; 66 | const quint8 FIXEXT8 = 0xd7; 67 | const quint8 FIXEX16 = 0xd8; 68 | const quint8 STR8 = 0xd9; 69 | const quint8 STR16 = 0xda; 70 | const quint8 STR32 = 0xdb; 71 | const quint8 ARRAY16 = 0xdc; 72 | const quint8 ARRAY32 = 0xdd; 73 | const quint8 MAP16 = 0xde; 74 | const quint8 MAP32 = 0xdf; 75 | const quint8 NEGATIVE_FIXINT = 0xe0; 76 | } 77 | } 78 | #endif // COMMON_H 79 | -------------------------------------------------------------------------------- /workers/settingshostworker.h: -------------------------------------------------------------------------------- 1 | #ifndef SETTINGSHOSTWORKER_H 2 | #define SETTINGSHOSTWORKER_H 3 | #include "wampclient.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "swiftlib.h" 14 | 15 | class SettingsHostWorker : public QObject 16 | { 17 | Q_OBJECT 18 | public: 19 | explicit SettingsHostWorker(QObject *parent = nullptr); 20 | void setJsonConfig( const QString& conf ); 21 | QString getJsonConfig(); 22 | Wamp::Session * session; 23 | bool service_active; 24 | QString getMethodsStatus(); 25 | QString getDbName() const; 26 | quint32 serviceMode() const { 27 | return _current_mode; 28 | } 29 | QNetworkAccessManager * netMan; 30 | 31 | 32 | signals: 33 | void markMethodSuccess( const QString& method ); 34 | void markMethodFailed( const QString& method ); 35 | void newParam( const QString& param, const QString& value ); 36 | public slots: 37 | QJsonObject getMemUsage(); 38 | void defineServiceMode(); 39 | void onMethodSuccess( const QString& method ); 40 | void onMethodFailed( const QString& method ); 41 | 42 | void onNewParam( const QString& param, const QString& value ); 43 | void loadParams(); 44 | void loadAssets(); 45 | void onWampSession( Wamp::Session * s ); 46 | void getWithdrawFeesFromApi(); 47 | void getTradeFeesFromApi(); 48 | private: 49 | QList _async_waiters; 50 | QHash _parsers; 51 | QJsonObject getExchangesFees(); 52 | QJsonObject getCurrenciesFees(); 53 | AssetsStorage * assets; 54 | QJsonObject j_assets_cached; 55 | bool _balances_collected; 56 | bool _windows_data_collected; 57 | bool _has_small_balances; 58 | quint32 _current_mode; 59 | 60 | QString getParam( const QString& param ); 61 | QString getParamUnlocked( const QString& param ); 62 | void saveParam( const QString& param, const QString& value ); 63 | QHash _success_methods; 64 | QHash _error_methods; 65 | QMutex mutex; 66 | QHash _user_actions; 67 | 68 | QHash _cached_params; 69 | QList _active_windows; 70 | QVector> _used_chains; 71 | QString dbname; 72 | }; 73 | 74 | #endif // SETTINGSHOSTWORKER_H 75 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientlivecoin.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTLIVECOIN_H 2 | #define SWIFTAPICLIENTLIVECOIN_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | #include 7 | class SwiftApiClientLivecoin : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientLivecoin(QObject *parent = nullptr); 12 | 13 | signals: 14 | 15 | 16 | // SwiftApiClient interface 17 | public: 18 | 19 | QString getExchangeName() const override; 20 | QString getApiVersionString() override; 21 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 40 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 41 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 42 | }; 43 | 44 | #endif // SWIFTAPICLIENTLIVECOIN_H 45 | -------------------------------------------------------------------------------- /swift-lib/ordersstorage.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERSSTORAGE_H 2 | #define ORDERSSTORAGE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class OrdersStorageData; 15 | 16 | class OrdersStorage : public QObject 17 | { 18 | Q_OBJECT 19 | public: 20 | QJsonObject prepareOrderData( const QJsonObject& j_order ); 21 | explicit OrdersStorage(QObject *parent = nullptr); 22 | OrdersStorage(const OrdersStorage &); 23 | OrdersStorage &operator=(const OrdersStorage &); 24 | ~OrdersStorage(); 25 | void addOrder( const QJsonObject& order_json ); 26 | void updateOrder( const QJsonObject& order_json ); 27 | bool isExistsRemoteId( const QString& uid ) const { 28 | return _index_ext_id.contains( uid ); 29 | } 30 | bool isExistsLocalId( const QString& uid ) const { 31 | return _index_ext_id.contains( uid ); 32 | } 33 | QJsonObject getOrder( const QString& remote_uid, const QString& local_uid = "" ) const; 34 | QJsonArray getOpenOrders(); 35 | 36 | QJsonArray getClosedOrders(); 37 | QJsonArray getClosedOrdersByPair( const quint32 pair_id ); 38 | QJsonArray getClosedOrdersByPair( const quint32 pair_id, const QString& date ); 39 | QJsonArray getOopenOrdersByPair( const quint32 pair_id ); 40 | QJsonArray getUpdatedOrders(); 41 | 42 | void clearUpdated() { 43 | _index_updated_orders.clear(); 44 | } 45 | 46 | QString uniTime( const quint64& ts ) { 47 | if ( ts > static_cast( QDateTime::currentSecsSinceEpoch() ) ) { 48 | return QString::number( QDateTime::fromSecsSinceEpoch( ts / 1000, Qt::UTC ).toSecsSinceEpoch() ); 49 | } else { 50 | return QString::number( QDateTime::fromSecsSinceEpoch( ts, Qt::UTC ).toSecsSinceEpoch() ); 51 | } 52 | } 53 | 54 | QString getLocalIdByRemote( const QString& remote_id, const quint32& exchange_id ); 55 | signals: 56 | public slots: 57 | // Обслуживание хранилища 58 | void provision(); 59 | 60 | 61 | private: 62 | QMutex m; 63 | QHash _index_ext_id; 64 | QHash _index_loc_id; 65 | QMap _index_open_orders; 66 | QMap _index_closed_orders; 67 | QList _index_updated_orders; 68 | QSharedDataPointer data; 69 | }; 70 | 71 | #endif // ORDERSSTORAGE_H 72 | -------------------------------------------------------------------------------- /swift-lib/swiftworker.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTWORKER_H 2 | #define SWIFTWORKER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "wampclient.h" 12 | #include "swiftlib.h" 13 | #include 14 | #include 15 | 16 | #ifndef APP_NAME 17 | #define APP_NAME "Swift worker" 18 | #endif 19 | #ifndef APP_VERSION 20 | #define APP_VERSION "2.0.2016" 21 | #endif 22 | class SwiftWorker : public QObject 23 | { 24 | Q_OBJECT 25 | public: 26 | QString getConfigValue( const QString& param ) { 27 | if ( session != nullptr && session->isJoined() ) { 28 | const QString res = session->call("swift.assets.rpc.settings.get",{param}).toStringList().at(0); 29 | return res; 30 | } else { 31 | return "0"; 32 | } 33 | } 34 | void insertLog( const QString& group, const QString& message ) { 35 | // swift.system.rpc.logs.log [SENDER,GROUP,MESSAGE] 36 | if ( session != nullptr && session->isJoined() ) { 37 | session->call("swift.system.rpc.logs.log", {getWorkerName(), group, message }); 38 | } 39 | } 40 | void insertError( const QString& group, const QString& message ) { 41 | // swift.system.rpc.logs.error [SENDER,GROUP,MESSAGE] 42 | if ( session != nullptr && session->isJoined() ) { 43 | session->call("swift.system.rpc.logs.error", {getWorkerName(), group, message }); 44 | } 45 | } 46 | explicit SwiftWorker(QObject *parent = nullptr); 47 | 48 | virtual QStringList listenParams() { 49 | return QStringList({}); 50 | } 51 | virtual void onParamChanged( const QString& param, const QString& value ) { 52 | Q_UNUSED(param) 53 | Q_UNUSED(value) 54 | } 55 | virtual void initWorker( Wamp::Session * sess )=0; 56 | virtual QString getWorkerName() const=0; 57 | void setStatus( const quint32& stat ); 58 | quint32 getStatus() const; 59 | QSqlDatabase _ch; 60 | Wamp::Session * getSession() { 61 | return session; 62 | } 63 | 64 | Wamp::Session * session; 65 | void setIsInited(); 66 | signals: 67 | void restartRequested(); 68 | public slots: 69 | void watchdog(); 70 | void onRestart(); 71 | void onWampSession( Wamp::Session * sess ); 72 | private: 73 | quint32 status; 74 | QString hostip; 75 | QTimer * wdtimer; 76 | 77 | 78 | }; 79 | 80 | #endif // SWIFTWORKER_H 81 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientcexio.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTCEXIO_H 2 | #define SWIFTAPICLIENTCEXIO_H 3 | 4 | #include 5 | 6 | #include "swiftapiclient.h" 7 | 8 | class SwiftApiClientCexio : public SwiftApiClient 9 | { 10 | Q_OBJECT 11 | public: 12 | SwiftApiClientCexio( QObject * parent) : SwiftApiClient( parent ) 13 | { 14 | api_key = getExchangeApiKey(); 15 | api_secret = getExchangeApiSecret(); 16 | api_user = getExchangeApiAdditional(); 17 | } 18 | // SwiftApiClient interface 19 | 20 | QString getExchangeName() const override; 21 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 40 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 41 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 42 | }; 43 | 44 | #endif // SWIFTAPICLIENTCEXIO_H 45 | -------------------------------------------------------------------------------- /swift-lib/orderbooksclient.cpp: -------------------------------------------------------------------------------- 1 | #include "orderbooksclient.h" 2 | #include "swiftlib.h" 3 | OrderbooksClient::OrderbooksClient(QObject *parent) : QObject(parent), orderbooks_client(nullptr) 4 | { 5 | 6 | } 7 | 8 | void OrderbooksClient::onOrderBooks(const QJsonObject &j_books) { 9 | QHash> _new_asks, _new_bids; 10 | 11 | const QJsonArray temo_asks( j_books.value("a").toArray() ); 12 | for( auto it = temo_asks.begin(); it != temo_asks.end(); it++ ) { 13 | const QJsonArray itm( it->toArray() ); 14 | if ( !itm.isEmpty() ) { 15 | for( auto it1 = itm.begin(); it1 != itm.end(); it1++ ) { 16 | if ( _filtered_pairs.isEmpty() || _filtered_pairs.contains( it1->toArray().at(0).toString().toInt() ) ) { 17 | _new_asks[ it1->toArray().at(0).toString().toInt() ].insert( it1->toArray().at(1).toString().toDouble(), it1->toArray().at(2).toString().toDouble() ); 18 | } 19 | } 20 | } 21 | } 22 | const QJsonArray temo_bids( j_books.value("b").toArray() ); 23 | 24 | for( auto it = temo_bids.begin(); it != temo_bids.end(); it++ ) { 25 | const QJsonArray itm( it->toArray() ); 26 | if ( !itm.isEmpty() ) { 27 | for( auto it1 = itm.begin(); it1 != itm.end(); it1++ ) { 28 | if ( _filtered_pairs.isEmpty() || _filtered_pairs.contains( it1->toArray().at(0).toString().toInt() ) ) { 29 | _new_bids[ it1->toArray().at(0).toString().toInt() ].insert( it1->toArray().at(1).toString().toDouble(), it1->toArray().at(2).toString().toDouble() ); 30 | } 31 | } 32 | } 33 | 34 | } 35 | emit orderbooks( _new_asks, _new_bids ); 36 | } 37 | 38 | void OrderbooksClient::onWampSession(Wamp::Session *sess) { 39 | session = sess; 40 | session->subscribe("orderbooks", [&]( const QVariantList&v, const QVariantMap&m ) { 41 | const QJsonObject j_books( QJsonDocument::fromJson( v.at(0).toString().toUtf8() ).object() ); 42 | onOrderBooks( j_books ); 43 | Q_UNUSED(m) 44 | }); 45 | } 46 | 47 | void OrderbooksClient::stopClient() { 48 | session->stop(); 49 | } 50 | 51 | void OrderbooksClient::startClient(const QList &filter) { 52 | _filtered_pairs = QList( filter ); 53 | orderbooks_client = new WampClient("orderbooks", SwiftLib::getSettings()->value("WAMP_SERVER", "localhost").toString(),8085, false ); 54 | connect( orderbooks_client, &WampClient::clientConnected, this, &OrderbooksClient::onWampSession ); 55 | orderbooks_client->startClient(); 56 | } 57 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientlbank.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTLBANK_H 2 | #define SWIFTAPICLIENTLBANK_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | #include 7 | class SwiftApiClientLbank : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientLbank(QObject * parent); 12 | 13 | signals: 14 | 15 | 16 | // SwiftApiClient interface 17 | public: 18 | 19 | QString getExchangeName() const override; 20 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 21 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 40 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 41 | void getTimestamp(); 42 | QByteArray echostr() const; 43 | quint64 ts; 44 | public slots: 45 | void parseCustomApiResponse( const QString& method, const QByteArray& data ); 46 | 47 | }; 48 | 49 | #endif // SWIFTAPICLIENTLBANK_H 50 | -------------------------------------------------------------------------------- /src/opt/swiftbot/wampstatus: -------------------------------------------------------------------------------- 1 | 2 | upstream wsbackend { 3 | server 127.0.0.1:8080; 4 | } 5 | 6 | server { 7 | listen 80 default_server; 8 | server_name _; 9 | return 301 https://$host$request_uri; 10 | } 11 | 12 | 13 | server { 14 | ssl on; 15 | listen 443 ssl http2; 16 | ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; 17 | 18 | ssl_prefer_server_ciphers on; 19 | 20 | server_name wamp.${HOSTPART}.cc.finance; 21 | ssl_certificate /opt/swiftbot/ssl/wcert.pem; 22 | ssl_certificate_key /opt/swiftbot/ssl/wkey.pem; 23 | 24 | location /ws { 25 | proxy_pass http://wsbackend; 26 | proxy_http_version 1.1; 27 | proxy_set_header Upgrade $http_upgrade; 28 | proxy_set_header Connection "Upgrade"; 29 | } 30 | } 31 | 32 | server { 33 | ssl on; 34 | listen 443 ssl http2; 35 | ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS'; 36 | 37 | ssl_prefer_server_ciphers on; 38 | 39 | server_name monitor.${HOSTPART}.cc.finance; 40 | ssl_certificate /opt/swiftbot/ssl/cert.pem; 41 | ssl_certificate_key /opt/swiftbot/ssl/key.pem; 42 | 43 | root /opt/swiftbot/html; 44 | index index.html; 45 | 46 | auth_basic "Password required"; 47 | auth_basic_user_file /opt/swiftbot/html/.htpasswd; 48 | 49 | location / { 50 | try_files $uri $uri/ =404; 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /workers/orderworker.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERWORKER_H 2 | #define ORDERWORKER_H 3 | 4 | #include 5 | #include "swiftworker.h" 6 | #include "ordersstorage.h" 7 | #include 8 | 9 | class OrderWorker : public SwiftWorker 10 | { 11 | Q_OBJECT 12 | public: 13 | OrderWorker( QObject * parent = nullptr ); 14 | 15 | // SwiftWorker interface 16 | public: 17 | QStringList listenParams() override; 18 | void onParamChanged(const QString ¶m, const QString &value) override; 19 | void initWorker(Wamp::Session *sess) override; 20 | QString getWorkerName() const override; 21 | QJsonObject getTradingSummary( const QVariantList&v); 22 | signals: 23 | void errorOrderEvent( const QJsonObject& j_itm ); 24 | void updatedOrderEvent( const QJsonObject& j_itm ); 25 | void completedOrderEvent( const QJsonObject& j_itm ); 26 | void placedOrderEvent( const QJsonObject& j_itm ); 27 | void canceledOrderEvent( const QJsonObject& j_itm ); 28 | void historyOrderEvent( const QJsonObject& j_itm ); 29 | void activeOrderEvent( const QJsonObject& j_itm ); 30 | void saveOrder( const QJsonObject& j_itm ); 31 | void saveOrderState( const QJsonObject& j_itm ); 32 | public slots: 33 | void onOrdersFromDb(const QJsonArray &stored_); 34 | void checkUpdates() { 35 | const QJsonArray j_updated_orders( o_storage->getUpdatedOrders() ); 36 | if ( !j_updated_orders.isEmpty() ) { 37 | for( auto it = j_updated_orders.begin(); it != j_updated_orders.end(); it++ ) { 38 | emit saveOrder( it->toObject() ); 39 | } 40 | o_storage->clearUpdated(); 41 | } 42 | 43 | QTimer::singleShot( 45000, this, &OrderWorker::checkUpdates ); 44 | } 45 | void startClient(); 46 | void processActiveQueue(); 47 | void processHistoryQueue(); 48 | void requestActives(); 49 | void requestHistory(); 50 | void onErrorOrderEvent( const QJsonObject& j_itm ); 51 | void onUpdatedOrderEvent( const QJsonObject& j_itm ); 52 | void onCompletedOrderEvent( const QJsonObject& j_itm ); 53 | void onPlacedOrderEvent( const QJsonObject& j_itm ); 54 | void onCanceledOrderEvent( const QJsonObject& j_itm ); 55 | void onHistoryOrderEvent( const QJsonObject& j_itm ); 56 | void onActiveOrderEvent( const QJsonObject& j_itm ); 57 | private: 58 | QTcpSocket socket_in; 59 | QTcpSocket socket_out; 60 | OrdersStorage * o_storage; 61 | AssetsStorage * assets; 62 | QQueue> _queued_active_get; 63 | QQueue> _queued_history_get; 64 | }; 65 | 66 | #endif // ORDERWORKER_H 67 | -------------------------------------------------------------------------------- /swift-orderbooks-proxy/rateswriter.cpp: -------------------------------------------------------------------------------- 1 | #include "rateswriter.h" 2 | #include "swiftlib.h" 3 | RatesWriter::RatesWriter(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | void RatesWriter::onRates( const QMap &rates_ ) { 9 | QMutexLocker lock(&m); 10 | 11 | if ( !_db.isOpen() ) { 12 | if ( !_db.open() ) { 13 | qWarning() << _db.lastError().text(); 14 | return; 15 | } 16 | } 17 | const QMap rates( rates_ ); 18 | QStringList parts; 19 | QList _inserted; 20 | for( auto it = rates.begin(); it != rates.end(); it++ ) { 21 | if( _last_inserted_values.contains( it.key() ) ) { 22 | if ( _last_inserted_values.value( it.key(), 0 ) != it.value() ) { 23 | if ( !_inserted.contains( it.key() ) ) { 24 | parts.push_back( "("+QStringList({ QString::number( it.key() ), QString::number( it.value(), 'f', 8 )}).join(",")+")" ); 25 | _last_inserted_values[it.key()] = it.value(); 26 | _inserted.push_back( it.key() ); 27 | } 28 | } 29 | } else { 30 | if ( !_inserted.contains( it.key() ) ) { 31 | _last_inserted_values.insert( it.key(), it.value() ); 32 | parts.push_back( "("+QStringList({ QString::number( it.key() ), QString::number( it.value(), 'f', 8 )}).join(",")+")" ); 33 | _inserted.push_back( it.key() ); 34 | } 35 | } 36 | } 37 | if ( !parts.isEmpty() ) { 38 | QSqlQuery q( "INSERT IGNORE INTO `rates` (`pair_id`,`rate`) VALUES "+parts.join(","), _db ); 39 | if ( !q.exec( ) ) { 40 | qWarning() << q.lastError().text(); 41 | } 42 | q.finish(); 43 | } 44 | 45 | } 46 | 47 | void RatesWriter::onThreadStarted() { 48 | 49 | 50 | _db = QSqlDatabase::addDatabase("QMYSQL", "sepThreadwriter"); 51 | _db.setHostName( SwiftLib::getSettings()->value(SETTINGS_MYSQL_HOST ).toString() ); 52 | _db.setPort( 3306 ); 53 | 54 | _db.setUserName( SwiftLib::getSettings()->value(SETTINGS_MYSQL_USERNAME ).toString() ); 55 | _db.setPassword( SwiftLib::getSettings()->value(SETTINGS_MYSQL_USERPASSWORD ).toString() ); 56 | _db.setDatabaseName( SwiftLib::getUserDbName() ); 57 | 58 | if ( !_db.open() ) { 59 | qWarning() << _db.lastError().text(); 60 | } else { 61 | qWarning() << "Success connection to MySQL db"; 62 | QSqlQuery q(_db); 63 | if ( !q.exec("DELETE FROM rates WHERE date(ts) >= DATE(NOW()) - INTERVAL 7 DAY") ) { 64 | qWarning() << q.lastError().text(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientkucoin.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTKUCOIN_H 2 | #define SWIFTAPICLIENTKUCOIN_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | #include 7 | class SwiftApiClientKuCoin : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientKuCoin(QObject * parent); 12 | 13 | // SwiftApiClient interface 14 | QMutex innermutex; 15 | public: 16 | quint64 getInnerNoncer(); 17 | 18 | quint64 timeDiff; 19 | quint64 _inner_noncer; 20 | 21 | QString getExchangeName() const override; 22 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 40 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 41 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 42 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 43 | public slots: 44 | void transferToTrades(); 45 | 46 | void parseCustomApiResponse( const QString& method, const QByteArray& data ); 47 | void syncTimestamps(); 48 | }; 49 | 50 | #endif // SWIFTAPICLIENTKUCOIN_H 51 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientexmo.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTEXMO_H 2 | #define SWIFTAPICLIENTEXMO_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | 7 | class SwiftApiClientExmo : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientExmo(QObject *parent); 12 | 13 | QNetworkReply * sendGet(const QString& url, const QMap params ); 14 | 15 | QNetworkReply * sendPost(const QString& url, const QMap params ); 16 | quint64 noncer; 17 | quint64 getNoncer() { 18 | QMutexLocker lock( &m ); 19 | noncer++; 20 | return noncer; 21 | } 22 | QMutex m; 23 | public: 24 | QString getExchangeName() const override; 25 | QString getApiVersionString() override; 26 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 40 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 41 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 42 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 43 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 44 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 45 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 46 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 47 | }; 48 | 49 | #endif // SWIFTAPICLIENTEXMO_H 50 | -------------------------------------------------------------------------------- /workers/ordersworker.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERSWORKER_H 2 | #define ORDERSWORKER_H 3 | 4 | #include 5 | #include 6 | #include "swiftlib.h" 7 | #include 8 | #include 9 | #include 10 | 11 | class OrdersWorker : public QObject 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit OrdersWorker(QObject *parent = nullptr); 16 | OrdersWorker(const OrdersWorker &); 17 | OrdersWorker &operator=(const OrdersWorker &); 18 | ~OrdersWorker(); 19 | static QString createOrderHash(const QJsonObject& j); 20 | void register_uuid_watch( const QString& uuid ); 21 | 22 | signals: 23 | void deleteOrderRec( const QJsonObject& j); 24 | void publishMessage( const QString& topic, const QJsonObject& msg ); 25 | void saveOrder( const QJsonObject& j_order ); 26 | void saveOrderState( const QJsonObject& j_order ); 27 | void processApiHistory( const QJsonArray& j_items ); 28 | void processApiCurrent( const QJsonArray& j_items, const quint32& market_privided=0 ); 29 | 30 | void errorOrderEvent( const QJsonObject& j_itm ); 31 | void completedOrderEvent( const QJsonObject& j_itm ); 32 | void placedOrderEvent( const QJsonObject& j_itm ); 33 | void canceledOrderEvent( const QJsonObject& j_itm ); 34 | public slots: 35 | void fixWinRelations(); 36 | void checkUpdates(); 37 | void updateConfig(const QString& conf ); 38 | void startClient(); 39 | void checkIndividualOpenState(); 40 | void onProcessApiCurrent( const QJsonArray& j_items, const quint32& market_privided=0 ); 41 | void onProcessApiHistory( const QJsonArray& j_items ); 42 | 43 | void onErrorOrderEvent( const QJsonObject& j_itm ); 44 | void onCompletedOrderEvent( const QJsonObject& j_itm ); 45 | void onPlacedOrderEvent( const QJsonObject& j_itm ); 46 | void onCanceledOrderEvent( const QJsonObject& j_itm ); 47 | 48 | void onOrdersFromDb( const QJsonArray& stored_ ); 49 | 50 | void onWampConnected(quint64); 51 | void checkAwaitingUpdates(); 52 | 53 | 54 | void getOpenOrders(); 55 | void getCompletedOrders(); 56 | private: 57 | QHash _exch_last_requested_all; 58 | QStringList _loaded_history_remote_ids; 59 | QJsonObject checkState( const QJsonObject& j_obj, const quint32& state ) const; 60 | AssetsStorage * assets; 61 | QMutex mutex; 62 | 63 | // Таймеры 64 | QTimer * _update_markets_open_orders_timer; 65 | QTimer * _update_today_trade_history_timer; 66 | 67 | 68 | 69 | // WAMP 70 | Wamp::Session * session; 71 | QTcpSocket socket_in; 72 | QTcpSocket socket_out; 73 | QHash _close_timers; 74 | 75 | OrdersStorage * o_storage; 76 | }; 77 | 78 | #endif // ORDERSWORKER_H 79 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientidcm.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTIDCM_H 2 | #define SWIFTAPICLIENTIDCM_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | 7 | class SwiftApiClientIDCM : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientIDCM(QObject* parent = nullptr); 12 | 13 | // SwiftApiClient interface 14 | public: 15 | 16 | QString getExchangeName() const override; 17 | QString getApiVersionString() override; 18 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 19 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 20 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 21 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | 40 | 41 | private: 42 | QString rest_url = "https://api.IDCM.cc:8323/api/v1/"; 43 | 44 | void getHistoryOrders(const QJsonObject &j_params, const quint64 &async_uuid, const QJsonArray& orderType, const QString& methodName); 45 | void buildPostRequest_withSignature(const QString& api_path, const QJsonObject ¶ms, const quint64 &uuid); 46 | }; 47 | 48 | #endif // SWIFTAPICLIENTIDCM_H 49 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientbittrex.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTBITTREX_H 2 | #define SWIFTAPICLIENTBITTREX_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | 7 | class SwiftApiClientBittrex : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientBittrex( QObject * parent) : SwiftApiClient( parent ) 12 | { 13 | api_key = getExchangeApiKey(); 14 | api_secret = getExchangeApiSecret(); 15 | api_user = getExchangeApiAdditional(); 16 | freeze_auto_sell_usdt = false; 17 | } 18 | 19 | 20 | // SwiftApiClient interface 21 | public: 22 | QString getExchangeName() const override; 23 | QString getApiVersionString() override; 24 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 40 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 41 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 42 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 43 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 44 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 45 | public slots: 46 | 47 | private: 48 | bool beginUsdWithdraw( const double& amount ); 49 | bool freeze_auto_sell_usdt; 50 | }; 51 | 52 | #endif // SWIFTAPICLIENTBITTREX_H 53 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientbitfinex.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTBITFINEX_H 2 | #define SWIFTAPICLIENTBITFINEX_H 3 | 4 | #include 5 | #include 6 | 7 | class SwiftApiClientBitfinex : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientBitfinex(QObject* parent = nullptr); 12 | 13 | // SwiftApiClient interface 14 | public: 15 | QString getExchangeName() const override; 16 | QString getApiVersionString() override; 17 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 18 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 19 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 20 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 21 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | 39 | private: 40 | const QString url_pub = "https://api-pub.bitfinex.com"; 41 | const QString url_auth = "https://api.bitfinex.com"; 42 | 43 | void auth(QNetworkRequest& req, const QString& api_path, const QString& body_str = "") const; 44 | QNetworkReply* authPostRequest(const QUrl& url, const QString& api_path, const QString& body_str = ""); 45 | }; 46 | 47 | #endif // SWIFTAPICLIENTBITFINEX_H 48 | -------------------------------------------------------------------------------- /swift-lib/systemevent.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSTEMEVENT_H 2 | #define SYSTEMEVENT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | class SwiftEvent : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | enum EventTypes { 18 | OrderEvent = 1000, 19 | BalanceEvent, 20 | AccountEvent, 21 | SystemEvent, 22 | WithdrawEvent, 23 | DepositEvent, 24 | CustomEvent 25 | }; 26 | 27 | void setExchangeId( const quint32& eid ) { 28 | exchange_id = eid; 29 | _stored_target["exchange_id"] = QString::number( eid ); 30 | } 31 | virtual QStringList privateProperties();; 32 | 33 | explicit SwiftEvent( const EventTypes& type, const QString& event_name, const QJsonObject& j_targer, QObject *parent = nullptr); 34 | 35 | SwiftEvent( const QJsonObject& j_event, QObject *parent = nullptr ); 36 | 37 | QJsonObject toJson(); 38 | 39 | QString getEventName() const; 40 | QString toString(); 41 | 42 | 43 | QJsonObject getEventTarget() const; 44 | SwiftEvent::EventTypes getEventType( const QString& str_name ); 45 | QString getEventTypeName(); 46 | 47 | void prepareEventTarget(); 48 | signals: 49 | private: 50 | 51 | EventTypes _type; 52 | QString _name; 53 | QJsonObject _stored_target; 54 | quint64 _event_time; 55 | quint32 exchange_id; 56 | 57 | }; 58 | 59 | class DepositEvent : public SwiftEvent { 60 | public: 61 | DepositEvent( const QJsonObject& j_withdraw_data ) : SwiftEvent( j_withdraw_data ) { 62 | 63 | } 64 | DepositEvent( const QString& event_name, const QJsonObject& j_withdraw_data ) : SwiftEvent( SwiftEvent::DepositEvent, event_name, j_withdraw_data ) { 65 | 66 | } 67 | }; 68 | class WithdrawEvent : public SwiftEvent { 69 | public: 70 | WithdrawEvent( const QJsonObject& j_withdraw_data ) : SwiftEvent( j_withdraw_data ) { 71 | 72 | } 73 | WithdrawEvent( const QString& event_name, const QJsonObject& j_withdraw_data ) : SwiftEvent( SwiftEvent::WithdrawEvent, event_name, j_withdraw_data ) { 74 | 75 | } 76 | }; 77 | 78 | class OrderEvent : public SwiftEvent { 79 | public: 80 | OrderEvent( const QJsonObject& j_order ) : SwiftEvent( j_order ) { 81 | 82 | } 83 | 84 | OrderEvent( const QString& event_name, const QJsonObject& j_order ) : SwiftEvent( SwiftEvent::OrderEvent, event_name, j_order ) { 85 | 86 | } 87 | QStringList privateProperties() override { 88 | return QStringList({"exchange_id","arb_window","market_id","remote_id","local_id","amount","amount_left","type","rate","price","fee","base_currency_id","market_currency_id","status","ts","created_at","closed_at"}); 89 | } 90 | }; 91 | 92 | #endif // SYSTEMEVENT_H 93 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclienthitbtc.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTHITBTC_H 2 | #define SWIFTAPICLIENTHITBTC_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | class SwiftApiClientHitbtc : public SwiftApiClient 7 | { 8 | Q_OBJECT 9 | public: 10 | SwiftApiClientHitbtc( QObject * parent); 11 | 12 | 13 | QNetworkReply * sendRequest(const QString& url, const QString& method, const QMap params); 14 | 15 | QString getExchangeName() const override; 16 | QString getApiVersionString() override; 17 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 18 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 19 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 20 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 21 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void customMethod(const QJsonObject& j_params = QJsonObject(), const quint64& async_uuid=0) override; 39 | 40 | public slots: 41 | void transferToTrades(); 42 | }; 43 | 44 | 45 | 46 | #endif // SWIFTAPICLIENTHITBTC_H 47 | -------------------------------------------------------------------------------- /swift-arbitrage-api-node/apiemulator.h: -------------------------------------------------------------------------------- 1 | #ifndef APIEMULATOR_H 2 | #define APIEMULATOR_H 3 | 4 | #include 5 | #include "wamp.h" 6 | #include "swiftlib.h" 7 | #include "swiftapiclient.h" 8 | 9 | class ApiEmulator : public SwiftApiClient 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit ApiEmulator(const QString& exchname, QObject *parent = nullptr); 14 | Wamp::Session * session; 15 | QString exchnm; 16 | quint32 exchid; 17 | AssetsStorage * assets; 18 | signals: 19 | 20 | void resultParsed( const quint64& uuid, const QJsonObject& j_result ); 21 | public slots: 22 | 23 | public: 24 | QMutex m; 25 | QString getExchangeName() const override; 26 | QString getApiVersionString() override; 27 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 40 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 41 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 42 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 43 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 44 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 45 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 46 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 47 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 48 | QJsonArray _placed_orders; 49 | QJsonArray _open_orders; 50 | 51 | QHash _balances_in_orders_minus; 52 | QHash _balances_in_orders_plus; 53 | }; 54 | 55 | #endif // APIEMULATOR_H 56 | -------------------------------------------------------------------------------- /swift-bot/ordersmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERSMANAGER_H 2 | #define ORDERSMANAGER_H 3 | 4 | #include 5 | #include 6 | #include "../swift-lib/arbitragepair.h" 7 | #include "wampclient.h" 8 | #include "swiftlib.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | 21 | class OrdersManager : public QObject 22 | { 23 | Q_OBJECT 24 | public: 25 | explicit OrdersManager(QObject *parent = nullptr); 26 | signals: 27 | void currentRate( const double& rate ); 28 | void orderPlaced(); 29 | void requestExchangeBalances( const quint32& exchange_id ); 30 | void publishMessage( const QString& topic, const QJsonObject& message ); 31 | void asyncOrderPlaced(); 32 | void asyncTaskFinished( const quint64& uuid ); 33 | public slots: 34 | void clearLocks(); 35 | void onPlaceOrder( const quint32& pair_id, const double& amount, const double& rate, const quint32& type ); 36 | void onWampSession( Wamp::Session * sess ); 37 | void onCandidats( const QList& candidats ); 38 | 39 | void loadCurrencyTotalUsage(); 40 | void getAllOpenOrders(); 41 | 42 | private: 43 | quint32 system_mode; 44 | quint32 getMode() const { 45 | return system_mode; 46 | } 47 | QHash _lock_market_time; 48 | QHash createMoneyRefillRequests(const QList& candidats, const QHash& _balances ); 49 | 50 | QList createOrdersQueue( const QList& candidats); 51 | 52 | QList _locked_markets; 53 | 54 | QList> _used_virtual_asks; 55 | QList> _used_virtual_bids; 56 | QList _used_pairs; 57 | bool placeOrder( const ArbitrageCandidat& candidat ); 58 | QList _waitings; 59 | QHash _async_results; 60 | QJsonArray _open_orders; 61 | QHash _balances; 62 | QHash _balances_reserved; 63 | QHash _requests_counter; 64 | QHash _balances_requested; 65 | QHash _currency_in_orders; 66 | double _rate; 67 | double _rate_trend; 68 | double _rate24; 69 | double _rate1; 70 | QStringList _sell_orders_hashes; 71 | QStringList _buy_orders_hashes; 72 | Wamp::Session * session; 73 | QTimer * _rates_timer; 74 | QTimer * _open_orders_timer; 75 | QMutex m; 76 | QVector _rates; 77 | AssetsStorage* assets; 78 | bool _is_candidats_placing; 79 | 80 | 81 | }; 82 | 83 | #endif // ORDERSMANAGER_H 84 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientkraken.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTKRAKEN_H 2 | #define SWIFTAPICLIENTKRAKEN_H 3 | 4 | #include "swiftapiclient.h" 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | using namespace std; 11 | 12 | class SwiftApiClientKraken : public SwiftApiClient 13 | { 14 | Q_OBJECT 15 | public: 16 | SwiftApiClientKraken(QObject* parent = nullptr); 17 | int getCounter() const; 18 | 19 | // SwiftApiClient interface 20 | public: 21 | 22 | QString getExchangeName() const override; 23 | QString getApiVersionString() override; 24 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 40 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 41 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 42 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 43 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 44 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 45 | 46 | private: 47 | QNetworkReply* authPostRequest(const QUrl& url_path, QUrlQuery& body); 48 | inline QString sideToStr(int side) const; 49 | inline bool isRequreSecondPrice(const QString& ordertype) const; 50 | 51 | const QString url_public = "https://api.kraken.com/0/public/"; 52 | const QString url_private = "https://api.kraken.com/0/private/"; 53 | int counter; 54 | }; 55 | 56 | #endif // SWIFTAPICLIENTKRAKEN_H 57 | -------------------------------------------------------------------------------- /swift-bot/addresswatcher.h: -------------------------------------------------------------------------------- 1 | #ifndef ADDRESSWATCHER_H 2 | #define ADDRESSWATCHER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class AddressWatcher : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit AddressWatcher(const QString& address, QObject *parent = nullptr); 19 | 20 | signals: 21 | void transactionFound( const QJsonObject& transaction ); 22 | void transactionConfirmed( const QJsonObject& transaction ); 23 | 24 | public slots: 25 | void sendRequest() { 26 | QNetworkRequest r( QUrl("https://api.blockcypher.com/v1/btc/main/addrs/"+_address) ); 27 | netman->get( r ); 28 | } 29 | /* 30 | { 31 | "address": "1rundZJCMJhUiWQNFS5uT3BvisBuLxkAp", 32 | "total_received": 254847811176, 33 | "total_sent": 254847811176, 34 | "balance": 0, 35 | "unconfirmed_balance": 0, 36 | "final_balance": 0, 37 | "n_tx": 300, 38 | "unconfirmed_n_tx": 0, 39 | "final_n_tx": 300, 40 | "txrefs": [ 41 | { 42 | "tx_hash": "b7e5a1d0e7b780e1afc7d48132cef60c10a967e0b3853c0b0e6a9b823e301dcb", 43 | "block_height": 504696, 44 | "tx_input_n": 82, 45 | "tx_output_n": -1, 46 | "value": 389000000, 47 | "ref_balance": 0, 48 | "confirmations": 102055, 49 | "confirmed": "2018-01-17T18:05:32Z", 50 | "double_spend": false 51 | }, 52 | */ 53 | void onResponse( QNetworkReply * reply ) { 54 | const QByteArray data( reply->readAll().constData() ); 55 | const QJsonObject res( QJsonDocument::fromJson( data ).object() ); 56 | transactions_count = res.value("n_tx").toInt(); 57 | transactions_unconfirmed_count = res.value("unconfirmed_n_tx").toInt(); 58 | transactions_confirmed_count = res.value("final_n_tx").toInt(); 59 | const QJsonArray txs( res.value("txrefs").toArray() ); 60 | if ( !txs.isEmpty() ) { 61 | for ( auto it = txs.begin(); it != txs.end(); it++ ) { 62 | const QJsonObject tr( it->toObject() ); 63 | QHash _tdata; 64 | _tdata["hash"] = tr.value("tx_hash").toString(); 65 | _tdata["confirmations"] = tr.value("confirmations").toInt(); 66 | _tdata["value"] = QString::number( tr.value("value").toInt() / 10000000, 'f', 8 ); 67 | _transactions[ tr.value("tx_hash").toString() ] = _tdata; 68 | } 69 | } 70 | reply->deleteLater(); 71 | } 72 | private: 73 | QString _address; 74 | quint32 transactions_count; 75 | quint32 transactions_unconfirmed_count; 76 | quint32 transactions_confirmed_count; 77 | QHash> _transactions; 78 | QNetworkAccessManager * netman; 79 | QTimer * t; 80 | }; 81 | 82 | #endif // ADDRESSWATCHER_H 83 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientokcoin.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTOKCOIN_H 2 | #define SWIFTAPICLIENTOKCOIN_H 3 | 4 | #include "swiftapiclient.h" 5 | #include "orderparams.h" 6 | 7 | class SwiftApiClientOkcoin : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit SwiftApiClientOkcoin(QObject* parent = nullptr); 12 | 13 | public: 14 | 15 | QString getExchangeName() const override; 16 | QString getApiVersionString() override; 17 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 18 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 19 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 20 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 21 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | 39 | private: 40 | const QString url_public = "https://www.okcoin.com/api"; 41 | const QString url_private = "https://www.okcoin.com/api"; 42 | const QString path_account = "/account/v3/"; 43 | const QString path_spot = "/spot/v3/"; 44 | 45 | int counter; 46 | 47 | QNetworkRequest buildAuth(const QUrl &url, const QByteArray &method, const QByteArray &body = "") const; 48 | QNetworkReply* sendPostAuth(const QUrl &url, QUrlQuery &body); 49 | QNetworkReply* sendGetAuth(const QUrl& url, const QByteArray &body = ""); 50 | inline QString sideToStr(int side) const; 51 | }; 52 | 53 | #endif // SWIFTAPICLIENTOKCOIN_H 54 | -------------------------------------------------------------------------------- /qmsgpack/doc/install.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ------------ 3 | 4 | .. contents:: 5 | :depth: 4 6 | 7 | qmsgpack is a pure Qt library (Qt4 and Qt5 supported), so you can build it for almost any platform Qt supports. 8 | There are two build methods: 9 | 10 | - CMake 11 | - qmake 12 | 13 | And two ways of using it: build separately and include to your project, or build with your project (qmake subdirs) 14 | 15 | Build 16 | ===== 17 | 18 | CMake 19 | ^^^^^ 20 | 21 | Get the latest qmsgpack version by grabbing the source code from GitHub: 22 | 23 | .. code-block:: bash 24 | 25 | $ git clone https://github.com/romixlab/qmsgpack.git 26 | 27 | Now build and install it: 28 | 29 | .. code-block:: bash 30 | 31 | cd qmsgpack 32 | mkdir build && cd build 33 | cmake .. 34 | make 35 | sudo make install 36 | 37 | There are several useful cmake options available: 38 | 39 | .. cmdoption:: -DBUILD_TESTS=True 40 | 41 | Build all the tests, run with ``make tests`` 42 | 43 | .. cmdoption:: -DCMAKE_INSTALL_PREFIX=/usr 44 | 45 | Change install location to `/usr` 46 | 47 | .. cmdoption:: -DCMAKE_BUILD_TYPE=Debug 48 | 49 | Change build type to debug mode (default is `Release`), could be very useful if something goes wrong 50 | 51 | .. cmdoption:: -DWITH_GUI_TYPES=True 52 | 53 | Build with support for QtGui types (QColor) 54 | 55 | .. cmdoption:: -DWITH_LOCATION_TYPES=True 56 | 57 | Build with support for QtLocation types(QGeoCoordinate). Might not work, because CMake seems to be failing to find QtLocation, in this case you can try qmake instead. 58 | 59 | Add options before ``..`` as follow: 60 | 61 | .. code-block:: bash 62 | 63 | cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_TESTS=True .. 64 | 65 | Custom Qt installation 66 | """""""""""""""""""""" 67 | 68 | If you installed Qt with online installer, cmake will most likely not find it, in this case try adding following lines to CMakeLists.txt: 69 | 70 | .. code-block:: cmake 71 | 72 | set(Qt5Core_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Core") 73 | set(Qt5Test_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Test") 74 | set(Qt5_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Core") 75 | set(QT_QMAKE_EXECUTABLE "/opt/Qt5.6.0/5.6/gcc_64/bin/qmake") 76 | 77 | qmake 78 | ^^^^^ 79 | 80 | Get the latest qmsgpack version by grabbing the source code from GitHub: 81 | 82 | .. code-block:: bash 83 | 84 | $ git clone https://github.com/romixlab/qmsgpack.git 85 | 86 | Now build and install it: 87 | 88 | .. code-block:: bash 89 | 90 | cd qmsgpack 91 | qmake 92 | make 93 | sudo make install 94 | 95 | Also you can just open ``qmsgpack.pro`` in Qt Creator and build it from there. 96 | 97 | Use it 98 | ====== 99 | 100 | Just add following lines to your .pro file: 101 | 102 | .. code-block:: makefile 103 | 104 | LIBS += -lqmsgpack 105 | 106 | On Windows you may also set the ``INCLUDEPATH`` variable to appropriate location 107 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientzb.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTZB_H 2 | #define SWIFTAPICLIENTZB_H 3 | 4 | #include 5 | #include 6 | 7 | class SwiftApiClientZB : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientZB(QObject* parent = nullptr); 12 | 13 | // SwiftApiClient interface 14 | public: 15 | 16 | QString getExchangeName() const override; 17 | QString getApiVersionString() override; 18 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 19 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 20 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 21 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 39 | 40 | private: 41 | 42 | void buildAuthRequest(const quint64 &uuid, const QString& method_url, const QMap& params); 43 | 44 | const QString publicPrefix = "http://api.zb.live/data/v1"; 45 | const QString privatePrefix = "https://trade.zb.com/api"; 46 | bool isParamExist(const QStringList ¶ms, const QJsonObject &j_params, QString& error); 47 | bool isUintValid(quint32 id, QString &error, const QString &id_name = "market_id"); 48 | bool isPriceValid(double price, QString &error); 49 | bool isAmountValid(double amount, QString &error); 50 | bool isSideValid(const QString &side, QString &error); 51 | QString buildSignature(const QString ¶ms) const; 52 | 53 | 54 | }; 55 | 56 | #endif // SWIFTAPICLIENTZB_H 57 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclienthuobi.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTHUOBI_H 2 | #define SWIFTAPICLIENTHUOBI_H 3 | 4 | #include 5 | #include 6 | 7 | class SwiftApiClientHuobi : public SwiftApiClient 8 | { 9 | Q_OBJECT 10 | public: 11 | SwiftApiClientHuobi(QObject* parent = nullptr); 12 | 13 | // SwiftApiClient interface 14 | public: 15 | QString getExchangeName() const override; 16 | QString getApiVersionString() override; 17 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 18 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 19 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 20 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 21 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | 39 | 40 | private: 41 | QString rest_url = "https://api.huobi.pro"; 42 | 43 | QByteArray buildSignature(const QByteArray &method, const QByteArray &api_path, const QByteArray &ordered_params) const; 44 | 45 | 46 | void buildGetRequest_withSignature(const QString &api_path, QMap ¶ms, const quint64 &uuid); 47 | void buildPostRequest_withSignature(const QString& api_path, QUrlQuery &body, const quint64 &uuid); 48 | 49 | // SwiftApiClient interface 50 | public: 51 | QString parseStatus( const QString& stat ); 52 | void customParser(const SwiftApiClient::AsyncMethods &method, const QJsonObject &j_result) override; 53 | void customMethod(const QJsonObject &j_params, const quint64 &async_uuid) override; 54 | }; 55 | 56 | #endif // SWIFTAPICLIENTHUOBI_H 57 | -------------------------------------------------------------------------------- /swift-lib/swiftapiclientlakebtc.h: -------------------------------------------------------------------------------- 1 | #ifndef SWIFTAPICLIENTLAKEBTC_H 2 | #define SWIFTAPICLIENTLAKEBTC_H 3 | 4 | #include 5 | #include "swiftapiclient.h" 6 | #include "orderparams.h" 7 | 8 | class SwiftApiClientLakeBTC : public SwiftApiClient 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit SwiftApiClientLakeBTC(QObject* parent = nullptr); 13 | 14 | 15 | QString getExchangeName() const override; 16 | QString getApiVersionString() override; 17 | void getCurrencies(const QJsonObject &j_params, const quint64 &async_uuid) override; 18 | void getMarkets(const QJsonObject &j_params, const quint64 &async_uuid) override; 19 | void getOrderbooks(const QJsonObject &j_params, const quint64 &async_uuid) override; 20 | void orderPlace(const QJsonObject &j_params, const quint64 &async_uuid) override; 21 | void orderCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 22 | void orderGet(const QJsonObject &j_params, const quint64 &async_uuid) override; 23 | void orderReplace(const QJsonObject &j_params, const quint64 &async_uuid) override; 24 | void withdrawGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 25 | void withdrawList(const QJsonObject &j_params, const quint64 &async_uuid) override; 26 | void withdrawHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 27 | void withdrawCancel(const QJsonObject &j_params, const quint64 &async_uuid) override; 28 | void withdrawCreate(const QJsonObject &j_params, const quint64 &async_uuid) override; 29 | void withdrawInner(const QJsonObject &j_params, const quint64 &async_uuid) override; 30 | void withdrawGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 31 | void getBalances(const QJsonObject &j_params, const quint64 &async_uuid) override; 32 | void getDeposits(const QJsonObject &j_params, const quint64 &async_uuid) override; 33 | void getDepositAddress(const QJsonObject &j_params, const quint64 &async_uuid) override; 34 | void tradeHistory(const QJsonObject &j_params, const quint64 &async_uuid) override; 35 | void tradeOpenOrders(const QJsonObject &j_params, const quint64 &async_uuid) override; 36 | void tradeGetFee(const QJsonObject &j_params, const quint64 &async_uuid) override; 37 | void tradeGetLimits(const QJsonObject &j_params, const quint64 &async_uuid) override; 38 | 39 | private: 40 | const QString url_path = "https://api.lakebtc.com/api_v2"; 41 | 42 | bool paramValidate(const QJsonObject& j_params, const QStringList& mandatoryParams, bool isOrderCheck); 43 | QString buildGetParamStr(const QJsonObject& j_params, const QStringList& params) const; 44 | QString buildPostParamStr(const QJsonObject& j_params, const QStringList& params) const; 45 | QByteArray buildSignature(const QUrlQuery& body) const; 46 | QUrlQuery buildBody(qint64 nonce, const QString& method, const QString& paramsString) const; 47 | void authPostRequest(const QUrl& url, const QString& method, const QString& paramsString, const quint64 &async_uuid); 48 | void publicGetRequest(const QUrl& url, const quint64 &async_uuid); 49 | }; 50 | 51 | #endif // SWIFTAPICLIENTLAKEBTC_H 52 | -------------------------------------------------------------------------------- /qmsgpack/src/private/unpack_p.h: -------------------------------------------------------------------------------- 1 | #ifndef MSGPACK_P_H 2 | #define MSGPACK_P_H 3 | 4 | #include "../msgpackcommon.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace MsgPackPrivate 11 | { 12 | /* unpack functions: 13 | * quint8 * _type_(QVariant &v, quint8 *p); 14 | * parses some type, which data is stored at p 15 | * type data goes to v 16 | * return pointer to last byte + 1 17 | */ 18 | typedef quint8 * (* type_parser_f)(QVariant &v, quint8 *p); 19 | extern type_parser_f unpackers[32]; 20 | 21 | bool register_unpacker(qint8 msgpack_type, MsgPack::unpack_user_f unpacker); 22 | extern QHash user_unpackers; 23 | extern QReadWriteLock unpackers_lock; 24 | 25 | // goes from p to end unpacking types with unpack_type function below 26 | QVariant unpack(const quint8 *p, const quint8 *end); 27 | // unpack some type, can be called recursively from other unpack functions 28 | quint8 * unpack_type(QVariant &v, quint8 *p); 29 | 30 | quint8 * unpack_nil(QVariant &v, quint8 *p); 31 | quint8 * unpack_never_used(QVariant &v, quint8 *p); 32 | quint8 * unpack_false(QVariant &v, quint8 *p); 33 | quint8 * unpack_true(QVariant &v, quint8 *p); 34 | 35 | quint8 * unpack_positive_fixint(QVariant &v, quint8 *p); 36 | quint8 * unpack_negative_fixint(QVariant &v, quint8 *p); 37 | quint8 * unpack_uint8(QVariant &v, quint8 *p); 38 | quint8 * unpack_uint16(QVariant &v, quint8 *p); 39 | quint8 * unpack_uint32(QVariant &v, quint8 *p); 40 | quint8 * unpack_uint64(QVariant &v, quint8 *p); 41 | quint8 * unpack_int8(QVariant &v, quint8 *p); 42 | quint8 * unpack_int16(QVariant &v, quint8 *p); 43 | quint8 * unpack_int32(QVariant &v, quint8 *p); 44 | quint8 * unpack_int64(QVariant &v, quint8 *p); 45 | 46 | quint8 * unpack_float32(QVariant &v, quint8 *p); 47 | quint8 * unpack_float64(QVariant &v, quint8 *p); 48 | 49 | quint8 * unpack_fixstr(QVariant &v, quint8 *p); 50 | quint8 * unpack_str8(QVariant &v, quint8 *p); 51 | quint8 * unpack_str16(QVariant &v, quint8 *p); 52 | quint8 * unpack_str32(QVariant &v, quint8 *p); 53 | 54 | quint8 * unpack_bin8(QVariant &v, quint8 *p); 55 | quint8 * unpack_bin16(QVariant &v, quint8 *p); 56 | quint8 * unpack_bin32(QVariant &v, quint8 *p); 57 | 58 | quint8 * unpack_array_len(QVariant &v, quint8 *p, quint32 len); 59 | quint8 * unpack_fixarray(QVariant &v, quint8 *p); 60 | quint8 * unpack_array16(QVariant &v, quint8 *p); 61 | quint8 * unpack_array32(QVariant &v, quint8 *p); 62 | 63 | quint8 * unpack_map_len(QVariant &v, quint8 *p, quint32 len); 64 | quint8 * unpack_fixmap(QVariant &v, quint8 *p); 65 | quint8 * unpack_map16(QVariant &v, quint8 *p); 66 | quint8 * unpack_map32(QVariant &v, quint8 *p); 67 | 68 | quint8 * unpack_ext(QVariant &v, quint8 *p, qint8 type, quint32 len); 69 | quint8 * unpack_fixext1(QVariant &v, quint8 *p); 70 | quint8 * unpack_fixext2(QVariant &v, quint8 *p); 71 | quint8 * unpack_fixext4(QVariant &v, quint8 *p); 72 | quint8 * unpack_fixext8(QVariant &v, quint8 *p); 73 | quint8 * unpack_fixext16(QVariant &v, quint8 *p); 74 | 75 | quint8 * unpack_ext8(QVariant &v, quint8 *p); 76 | quint8 * unpack_ext16(QVariant &v, quint8 *p); 77 | quint8 * unpack_ext32(QVariant &v, quint8 *p); 78 | } 79 | 80 | #endif // MSGPACK_P_H 81 | -------------------------------------------------------------------------------- /swift-lib/systemevent.cpp: -------------------------------------------------------------------------------- 1 | #include "systemevent.h" 2 | 3 | 4 | QStringList SwiftEvent::privateProperties(){ return QStringList(); } 5 | 6 | SwiftEvent::SwiftEvent(const SwiftEvent::EventTypes &type, const QString &event_name, const QJsonObject &j_targer, QObject *parent) 7 | : QObject( parent ), 8 | _type(type), 9 | _name(event_name), 10 | _stored_target( j_targer ), 11 | _event_time( QDateTime::currentSecsSinceEpoch() ), 12 | exchange_id( j_targer.value("exchange_id").toString().toUInt() ){ 13 | } 14 | 15 | SwiftEvent::SwiftEvent(const QJsonObject &j_event, QObject *parent) 16 | : QObject(parent), 17 | _type( getEventType( j_event.value("event").toString() ) ), 18 | _name( j_event.value("name").toString()), 19 | _stored_target( j_event.value("target").toObject() ), 20 | _event_time( j_event.value("time").toString().toULongLong() ), 21 | exchange_id( j_event.value("target").toObject().value("exchange_id").toString().toUInt() ){ 22 | 23 | } 24 | 25 | QJsonObject SwiftEvent::toJson() { 26 | QJsonObject j_obj; 27 | j_obj["event"] = getEventTypeName(); 28 | j_obj["name"] = _name; 29 | j_obj["time"] = QString::number( _event_time ); 30 | j_obj["target"] = getEventTarget(); 31 | 32 | j_obj["exchange_id"] = QString::number( exchange_id ); 33 | return j_obj; 34 | } 35 | 36 | QString SwiftEvent::getEventName() const { 37 | return _name; 38 | } 39 | 40 | QString SwiftEvent::toString() { 41 | const QString _ret( QJsonDocument( toJson() ).toJson( QJsonDocument::Compact ) ); 42 | return _ret; 43 | } 44 | 45 | QJsonObject SwiftEvent::getEventTarget() const { 46 | return _stored_target; 47 | } 48 | 49 | SwiftEvent::EventTypes SwiftEvent::getEventType(const QString &str_name) { 50 | if ( str_name == "order" ) { 51 | return OrderEvent; 52 | } else if ( str_name == "balance" ) { 53 | return BalanceEvent; 54 | } else if ( str_name == "account" ) { 55 | return AccountEvent; 56 | } else if ( str_name == "system" ) { 57 | return SystemEvent; 58 | } else if ( str_name == "withdraw" ) { 59 | return WithdrawEvent; 60 | } else if ( str_name == "deposit" ) { 61 | return DepositEvent; 62 | } 63 | return CustomEvent; 64 | } 65 | 66 | QString SwiftEvent::getEventTypeName() { 67 | if ( _type == OrderEvent ) { 68 | return "order"; 69 | } else if ( _type == BalanceEvent ) { 70 | return "balance"; 71 | } else if ( _type == AccountEvent ) { 72 | return "account"; 73 | } else if ( _type == SystemEvent ) { 74 | return "system"; 75 | } else if ( _type == WithdrawEvent ) { 76 | return "withdraw"; 77 | } else if ( _type == DepositEvent ) { 78 | return "deposit"; 79 | } 80 | return "custom"; 81 | } 82 | 83 | void SwiftEvent::prepareEventTarget() { 84 | const QStringList _params( privateProperties() ); 85 | const QJsonObject __target( _stored_target ); 86 | QJsonObject _new_target_object; 87 | for( auto it = _params.begin(); it != _params.end(); it++ ) { 88 | _new_target_object[ *it ] = __target.value( *it ); 89 | } 90 | _stored_target = _new_target_object; 91 | } 92 | -------------------------------------------------------------------------------- /swift-lib/swift-lib.pro: -------------------------------------------------------------------------------- 1 | QT -= gui 2 | QT += network sql websockets 3 | TEMPLATE = lib 4 | 5 | 6 | CONFIG += c++11 7 | 8 | DEFINES += QT_DEPRECATED_WARNINGS 9 | 10 | 11 | VERSION = 2.1 12 | SOURCES += \ 13 | arbitragemanager.cpp \ 14 | arbitragepair.cpp \ 15 | assetsstorage.cpp \ 16 | asyncrcpcallerinterface.cpp \ 17 | orderbooksclient.cpp \ 18 | ordermodel.cpp \ 19 | orderparams.cpp \ 20 | ordersstorage.cpp \ 21 | swiftapiclient.cpp \ 22 | swiftapiclientbinance.cpp \ 23 | swiftapiclientbitfinex.cpp \ 24 | swiftapiclientbittrex.cpp \ 25 | swiftapiclientcexio.cpp \ 26 | swiftapiclientexmo.cpp \ 27 | swiftapiclienthitbtc.cpp \ 28 | swiftapiclienthuobi.cpp \ 29 | swiftapiclientidcm.cpp \ 30 | swiftapiclientkraken.cpp \ 31 | swiftapiclientkucoin.cpp \ 32 | swiftapiclientlakebtc.cpp \ 33 | swiftapiclientlbank.cpp \ 34 | swiftapiclientlivecoin.cpp \ 35 | swiftapiclientokcoin.cpp \ 36 | swiftapiclientzb.cpp \ 37 | swiftapiparser.cpp \ 38 | swiftapiparserbinance.cpp \ 39 | swiftapiparserbitfinex.cpp \ 40 | swiftapiparserbittrex.cpp \ 41 | swiftapiparsercexio.cpp \ 42 | swiftapiparserexmo.cpp \ 43 | swiftapiparserhitbtc.cpp \ 44 | swiftapiparserhuobi.cpp \ 45 | swiftapiparseridcm.cpp \ 46 | swiftapiparserkraken.cpp \ 47 | swiftapiparserkucoin.cpp \ 48 | swiftapiparserlakebtc.cpp \ 49 | swiftapiparserlbank.cpp \ 50 | swiftapiparserlivecoin.cpp \ 51 | swiftapiparserokcoin.cpp \ 52 | swiftapiparserzb.cpp \ 53 | swiftlib.cpp \ 54 | systemevent.cpp \ 55 | wamp.cpp \ 56 | wampclient.cpp \ 57 | apircpclient.cpp \ 58 | arbitragewindow.cpp \ 59 | withdrawparams.cpp \ 60 | swiftworker.cpp 61 | 62 | HEADERS += \ 63 | arbitragemanager.h \ 64 | arbitragepair.h \ 65 | assetsstorage.h \ 66 | asyncrcpcallerinterface.h \ 67 | orderbooksclient.h \ 68 | ordermodel.h \ 69 | orderparams.h \ 70 | ordersstorage.h \ 71 | swiftapiclient.h \ 72 | swiftapiclientbinance.h \ 73 | swiftapiclientbitfinex.h \ 74 | swiftapiclientbittrex.h \ 75 | swiftapiclientcexio.h \ 76 | swiftapiclientexmo.h \ 77 | swiftapiclienthitbtc.h \ 78 | swiftapiclienthuobi.h \ 79 | swiftapiclientidcm.h \ 80 | swiftapiclientkraken.h \ 81 | swiftapiclientkucoin.h \ 82 | swiftapiclientlakebtc.h \ 83 | swiftapiclientlbank.h \ 84 | swiftapiclientlivecoin.h \ 85 | swiftapiclientokcoin.h \ 86 | swiftapiclientzb.h \ 87 | swiftapiparser.h \ 88 | swiftapiparserbinance.h \ 89 | swiftapiparserbitfinex.h \ 90 | swiftapiparserbittrex.h \ 91 | swiftapiparsercexio.h \ 92 | swiftapiparserexmo.h \ 93 | swiftapiparserhitbtc.h \ 94 | swiftapiparserhuobi.h \ 95 | swiftapiparseridcm.h \ 96 | swiftapiparserkraken.h \ 97 | swiftapiparserkucoin.h \ 98 | swiftapiparserlakebtc.h \ 99 | swiftapiparserlbank.h \ 100 | swiftapiparserlivecoin.h \ 101 | swiftapiparserokcoin.h \ 102 | swiftapiparserzb.h \ 103 | swiftlib.h \ 104 | systemevent.h \ 105 | wamp.h \ 106 | wampclient.h \ 107 | apircpclient.h \ 108 | arbitragewindow.h \ 109 | withdrawparams.h \ 110 | swiftworker.h 111 | 112 | 113 | LIBS += -L$$OUT_PWD/../qmsgpack/bin/ -lqmsgpack 114 | 115 | INCLUDEPATH += $$PWD/../qmsgpack/src $$OUT_PWD/../qmsgpack/bin 116 | DEPENDPATH += $$PWD/../qmsgpack/src $$OUT_PWD/../qmsgpack/bin 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /swift-bot/wampproxy.cpp: -------------------------------------------------------------------------------- 1 | #include "wampproxy.h" 2 | 3 | WampProxy::WampProxy(QObject *parent) : QObject(parent), wamp_client( new WampClient( 4 | SwiftLib::getSettings()->value(SETTINGS_WAMP_REALM).toString(), 5 | "cc.finance", 6 | 8081 7 | ) ) 8 | { 9 | connect( wamp_client, &WampClient::clientConnected, this, &WampProxy::onWampSessionStarted ); 10 | 11 | } 12 | 13 | void WampProxy::onMoneyShiftState(const QJsonObject &j_state) { 14 | if ( wamp_client->getSession() != nullptr && wamp_client->getSession()->isJoined() ) { 15 | const QString _json( QJsonDocument(j_state).toJson(QJsonDocument::Compact) ); 16 | wamp_client->getSession()->publish( "money.shift.status", QVariantList({ _json }) ); 17 | } 18 | } 19 | 20 | void WampProxy::onTransferCandidats(const QJsonArray &candidats) { 21 | if ( wamp_client->getSession() != nullptr && wamp_client->getSession()->isJoined() ) { 22 | const QString candidats_json( QJsonDocument(candidats).toJson(QJsonDocument::Compact) ); 23 | wamp_client->getSession()->publish( "transfer_candidats", QVariantList({ candidats_json }) ); 24 | } 25 | } 26 | 27 | void WampProxy::onUserState(const QJsonObject &j_state) { 28 | if ( session != nullptr && session->isJoined() ) { 29 | const QString json( QJsonDocument(j_state).toJson(QJsonDocument::Compact) ); 30 | session->publish( QString::number( WampClient::ch_userstate ), QVariantList({ json }) ); 31 | } 32 | } 33 | 34 | void WampProxy::onCandidatsFiltered(const QList &_filtered_candidats) { 35 | if ( session != nullptr && session->isJoined() ) { 36 | QJsonArray _candidats_json; 37 | for( auto it = _filtered_candidats.begin(); it != _filtered_candidats.end(); it++ ) { 38 | _candidats_json.push_back( it->toJson() ); 39 | } 40 | const QString candidats_json( QJsonDocument(_candidats_json).toJson(QJsonDocument::Compact) ); 41 | session->publish( QString::number( WampClient::ch_candidats ), QVariantList({ candidats_json }) ); 42 | } 43 | } 44 | 45 | void WampProxy::onWampSessionStarted(Wamp::Session *sess) { 46 | 47 | session = sess; 48 | session->provide("crypto.addresses.get.all", [&]( const QVariantList& v, const QVariantMap& m) { 49 | QJsonObject addresses; 50 | QSqlQuery q("SELECT * FROM currencies WHERE is_enabled=1 AND deposit_address IS NOT NULL AND deposit_address !=''"); 51 | if ( q.exec() ) { 52 | while ( q.next() ) { 53 | addresses.insert( QString::number( q.value("id").toUInt()), q.value("deposit_address").toString() ); 54 | } 55 | } 56 | Q_UNUSED(v) 57 | Q_UNUSED(m) 58 | const QString res( QJsonDocument( addresses ).toJson( QJsonDocument::Compact ) ); 59 | return res; 60 | }); 61 | 62 | session->subscribe("swiftbot.orderbooks.proxy", [&]( const QVariantList& v, const QVariantMap& m) { 63 | emit orderbooks( v ); 64 | Q_UNUSED(m) 65 | }); 66 | 67 | 68 | // QTimer::singleShot( 15000, this, &WampProxy::sendReloadCommand ); 69 | 70 | 71 | emit sessionStarted( session ); 72 | subscrubeToAsync(); 73 | } 74 | 75 | void WampProxy::sendReloadCommand() { 76 | wamp_client->getSession()->publish("monitor.reload", QVariantList({true}) ); 77 | } 78 | -------------------------------------------------------------------------------- /qmsgpack/src/stream/geometry.cpp: -------------------------------------------------------------------------------- 1 | // This is an open source non-commercial project. Dear PVS-Studio, please check it. 2 | // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com 3 | #include "geometry.h" 4 | #include "../msgpack.h" 5 | #include "../msgpackstream.h" 6 | 7 | MsgPackStream &operator<<(MsgPackStream &s, const QPoint &point) 8 | { 9 | qint8 msgpackType = MsgPack::msgpackType(QMetaType::QPoint); 10 | if (msgpackType == -1) { 11 | s.setStatus(MsgPackStream::WriteFailed); 12 | return s; 13 | } 14 | QByteArray ba; 15 | MsgPackStream out(&ba, QIODevice::WriteOnly); 16 | if (point.isNull()) { 17 | quint8 p[1] = {0}; 18 | out.writeBytes((const char *)p, 1); 19 | } else { 20 | out << point.x() << point.y(); 21 | } 22 | s.writeExtHeader(ba.length(), msgpackType); 23 | s.writeBytes(ba.data(), ba.length()); 24 | return s; 25 | } 26 | 27 | MsgPackStream &operator>>(MsgPackStream &s, QPoint &point) 28 | { 29 | quint32 len; 30 | s.readExtHeader(len); 31 | if (len == 1) { 32 | point = QPoint(); 33 | return s; 34 | } 35 | QByteArray ba; 36 | ba.resize(len); 37 | s.readBytes(ba.data(), len); 38 | MsgPackStream in(ba); 39 | int x, y; 40 | in >> x >> y; 41 | point = QPoint(x, y); 42 | return s; 43 | } 44 | 45 | MsgPackStream &operator<<(MsgPackStream &s, const QSize &sz) 46 | { 47 | qint8 msgpackType = MsgPack::msgpackType(QMetaType::QSize); 48 | if (msgpackType == -1) { 49 | s.setStatus(MsgPackStream::WriteFailed); 50 | return s; 51 | } 52 | QByteArray ba; 53 | MsgPackStream out(&ba, QIODevice::WriteOnly); 54 | if (!sz.isValid()) { 55 | quint8 p[1] = {0}; 56 | out.writeBytes((const char *)p, 1); 57 | } else { 58 | out << sz.width() << sz.height(); 59 | } 60 | s.writeExtHeader(ba.length(), msgpackType); 61 | s.writeBytes(ba.data(), ba.length()); 62 | return s; 63 | } 64 | 65 | MsgPackStream &operator>>(MsgPackStream &s, QSize &sz) 66 | { 67 | quint32 len; 68 | s.readExtHeader(len); 69 | if (len == 1) { 70 | sz = QSize(); 71 | return s; 72 | } 73 | QByteArray ba; 74 | ba.resize(len); 75 | s.readBytes(ba.data(), len); 76 | MsgPackStream in(ba); 77 | int w, h; 78 | in >> w >> h; 79 | sz = QSize(w, h); 80 | return s; 81 | } 82 | 83 | MsgPackStream &operator<<(MsgPackStream &s, const QRect &rect) 84 | { 85 | qint8 msgpackType = MsgPack::msgpackType(QMetaType::QRect); 86 | if (msgpackType == -1) { 87 | s.setStatus(MsgPackStream::WriteFailed); 88 | return s; 89 | } 90 | QByteArray ba; 91 | MsgPackStream out(&ba, QIODevice::WriteOnly); 92 | if (!rect.isValid()) { 93 | quint8 p[1] = {0}; 94 | out.writeBytes((const char *)p, 1); 95 | } else { 96 | out << rect.left() << rect.top() << rect.width() << rect.height(); 97 | } 98 | s.writeExtHeader(ba.length(), msgpackType); 99 | s.writeBytes(ba.data(), ba.length()); 100 | return s; 101 | } 102 | 103 | MsgPackStream &operator>>(MsgPackStream &s, QRect &rect) 104 | { 105 | quint32 len; 106 | s.readExtHeader(len); 107 | if (len == 1) { 108 | rect = QRect(); 109 | return s; 110 | } 111 | QByteArray ba; 112 | ba.resize(len); 113 | s.readBytes(ba.data(), len); 114 | MsgPackStream in(ba); 115 | int l, t, w, h; 116 | in >> l >> t >> w >> h; 117 | rect = QRect(l, t, w, h); 118 | return s; 119 | } 120 | -------------------------------------------------------------------------------- /qmsgpack/doc/basics.rst: -------------------------------------------------------------------------------- 1 | Basics 2 | ------ 3 | 4 | .. contents:: 5 | :depth: 4 6 | 7 | Standard types 8 | ============== 9 | 10 | Below are Qt equivalents to MessagePack types listed in `spec `_: 11 | 12 | ================ ============== 13 | MessagePack type Qt or C++ type 14 | ================ ============== 15 | positive fixint quint8 16 | fixmap, map QMap, QHash 17 | fixarray,array QList 18 | fixstr, str QString 19 | nil QVariant() 20 | false, true bool 21 | bin QByteArray 22 | float 32 float 23 | float 64 double 24 | uint 8 quint8 25 | uint 16 quint16 26 | uint 32 quint32 27 | uint 64 quint64 28 | int 8 qint8 29 | int 16 qint16 30 | int 32 qint32, int 31 | int 64 qint64 32 | negative fixint qint8 33 | ================ ============== 34 | 35 | You can pack and unpack any of those types right away: 36 | 37 | Packing 38 | ^^^^^^^ 39 | 40 | Pass QVariant to ``MsgPack::pack()`` function: 41 | 42 | .. code-block:: cpp 43 | 44 | QVariant v = 123; 45 | QByteArray packed = MsgPack::pack(v); 46 | qDebug() << packed.toHex(); 47 | 48 | Of course QVariant can contain a QVarianList or a QVariantMap: 49 | 50 | .. code-block:: cpp 51 | 52 | QList list; 53 | list << 123 << 4.56 << true; 54 | QByteArray packed = MsgPack::pack(list); 55 | qDebug() << packed.toHex(); 56 | 57 | .. note:: 58 | If you want to pack QList for example see: REF TO MsgPackStream 59 | 60 | Unpacking 61 | ^^^^^^^^^ 62 | 63 | Unpacking is handled by ``MsgPack::unpack()`` function: 64 | 65 | .. code-block:: cpp 66 | 67 | QByteArray packed = MsgPack::pack("qwerty"); 68 | QVariant unpacked = MsgPack::unpack(packed); 69 | qDebug() << unpacked.toString(); 70 | 71 | .. tip:: 72 | 73 | If packed data contains only one msgpack type (fixstr of fixmap for example), unpack will return it as ``QVariant(QString())`` and ``QVariant(QMap())`` respectively. 74 | But if there are several values packed, ``QVariant(QList())`` will be returned (consider this 5 bool values packed without msgpack's list: [0xc3, 0xc3, 0xc3, 0xc3, 0xc3]) 75 | 76 | More types 77 | ========== 78 | 79 | There are built in packers and unpackers (basic and stream ones) for following types: 80 | ``QPoint, QSize, QRect, QTime, QDate, QDateTime, QColor, QGeoCoordinate``. 81 | But since there is no such types in msgpack spec, ext type is used. 82 | 83 | Example: 84 | 85 | .. code-block:: cpp 86 | 87 | MsgPack::registerType(QMetaType::QPoint, 37); // 37 is msgpack user type id 88 | QByteArray ba = MsgPack::pack(QPoint(12, 34)); 89 | qDebug() << MsgPack::unpack(ba).toPoint(); 90 | 91 | Note, that QColor and QGeoCoordinate is enabled by default only in qmake project. 92 | 93 | Thread safety 94 | ============= 95 | 96 | All methods are thread safe, except ``MsgPack::setCompatibilityModeEnabled`` which is not. 97 | 98 | ``pack()`` and ``unpack()`` do not use any global variables except user packers and unpackers, access to them is controlled via QReadLocker (and QWriteLocker when registering a new one), so readers do not block each other. 99 | 100 | .. warning:: 101 | 102 | User packers and unpackers can break thread-safety! But in most cases they are so simple, so this is not a problem. 103 | 104 | Compatibility mode 105 | ================== 106 | 107 | You can enable compatibility mode this way: ``MsgPack::setCompatibilityModeEnabled(true)``, after that there will be no str8, and QByteArray will be packed to str. -------------------------------------------------------------------------------- /qmsgpack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #set(Qt5Core_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Core") 2 | #set(Qt5Test_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Test") 3 | #set(Qt5_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Core") 4 | #set(QT_QMAKE_EXECUTABLE "/opt/Qt5.6.0/5.6/gcc_64/bin/qmake") 5 | 6 | project(qmsgpack) 7 | 8 | cmake_minimum_required(VERSION 3.1.0) 9 | set (CMAKE_CXX_STANDARD 11) 10 | 11 | set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR}) 12 | 13 | # build type 14 | if ("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*") 15 | add_definitions("-DQT_NO_DEBUG_OUTPUT") 16 | endif ("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*") 17 | 18 | # 'd' postfix on windows if debug 19 | if (WIN32) 20 | set(CMAKE_DEBUG_POSTFIX "d") 21 | endif (WIN32) 22 | 23 | option (QT4_BUILD "BUild with Qt4") 24 | if (NOT QT4_BUILD) 25 | find_package(Qt5Core QUIET) 26 | endif () 27 | 28 | if (Qt5Core_FOUND) 29 | message("Qt5 found") 30 | include_directories(${Qt5Core_INCLUDE_DIRS}) 31 | add_definitions(${Qt5Core_DEFINITIONS}) 32 | # Find includes in corresponding build directories 33 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 34 | # Instruct CMake to run moc automatically when needed. 35 | set(CMAKE_AUTOMOC ON) 36 | set(PC_Requires "Qt5Core") 37 | else () 38 | message("Qt5 not found, searching for Qt4") 39 | find_package(Qt4 REQUIRED) 40 | include(${QT_USE_FILE}) 41 | # Find includes in corresponding build directories 42 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 43 | # Instruct CMake to run moc automatically when needed. 44 | set(CMAKE_AUTOMOC ON) 45 | set(PC_Requires "QtCore") 46 | endif () 47 | 48 | option (WITH_GUI_TYPES "Build with support for QtGui types") 49 | if (WITH_GUI_TYPES) 50 | if (QT4_BUILD) 51 | find_package(Qt4 QTGUI) 52 | else () 53 | find_package(Qt5Gui QUIET) 54 | endif () 55 | endif () 56 | 57 | option (WITH_LOCATION_TYPES "Build with support for QtLocation types") 58 | if (WITH_LOCATION_TYPES) 59 | find_package(Qt5Location QUIET) 60 | endif () 61 | 62 | if (Qt5Location_FOUND) 63 | message("Qt5Location found") 64 | include_directories(${Qt5Location_INCLUDE_DIRS}) 65 | add_definitions(${Qt5Location_DEFINITIONS}) 66 | else () 67 | message("Qt5Location not found") 68 | endif () 69 | 70 | if (NOT WIN32) 71 | set(QT_DONT_USE_QTGUI TRUE) 72 | endif () 73 | 74 | #add extra search paths for libraries and includes 75 | set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) 76 | set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE STRING "Directory where lib will install") 77 | set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in") 78 | set(CMAKECONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${CMAKE_PROJECT_NAME}" CACHE PATH "Directory where to install qmsgpack.cmake") 79 | 80 | configure_file( 81 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 82 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 83 | IMMEDIATE @ONLY) 84 | 85 | set(QMSGPACK_MAJOR "0") 86 | set(QMSGPACK_MINOR "1") 87 | set(QMSGPACK_VERSION "0") 88 | 89 | set(MSGPACK_QT_LIB_VERSION_STRING "${QMSGPACK_MAJOR}.${QMSGPACK_MINOR}.${QMSGPACK_VERSION}") 90 | 91 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 92 | 93 | add_subdirectory(src) 94 | if (BUILD_TESTS) 95 | enable_testing() 96 | add_subdirectory(tests) 97 | endif () 98 | 99 | install(EXPORT qmsgpack-export DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE MsgPackQtTargets.cmake) 100 | 101 | file(RELATIVE_PATH relInstallDir ${CMAKE_INSTALL_PREFIX}/$CMAKECONFIG_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX}) 102 | 103 | add_custom_target(uninstall 104 | "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") 105 | -------------------------------------------------------------------------------- /swift-orderbooks-proxy/orderbooksnode.h: -------------------------------------------------------------------------------- 1 | #ifndef ORDERBOOKSNODE_H 2 | #define ORDERBOOKSNODE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #define SUPPORTED_EXCHANGES "cexio,bittrex,lbank,kucoin,binance,kraken,livecoin,lakebtc,exmo,hitbtc,bitfinex,okcoin,zb,huobi,idcm" 17 | #define RECORDS_LIMIT 20 18 | 19 | class OrderbooksNode : public QObject 20 | { 21 | Q_OBJECT 22 | public: 23 | enum NodeErrors { 24 | UnknownExchange, 25 | WebsocketAuthError 26 | }; 27 | 28 | enum NodeStates { 29 | NodeCreated, 30 | NodeStarting, 31 | NodeConnected, 32 | NodeError, 33 | NodeShutdown 34 | }; 35 | 36 | explicit OrderbooksNode(QObject *parent = nullptr); 37 | void setExchange( const QString& exchange_name, const QString& target_pair, const quint32& target_pair_id ); 38 | void setExchange( const QString& exchange_name, const QList>& pairs ); 39 | 40 | signals: 41 | void orderbooks( const QJsonArray& a, const QJsonArray& b ); 42 | void nodeError( OrderbooksNode::NodeErrors e ); 43 | void aboutToClose(); 44 | 45 | public slots: 46 | void stopNode(); 47 | void startNode(); 48 | void onRawOrderbooks( const QJsonArray&a, const QJsonArray&b, const quint32 &custom_pair_id = 0 ); 49 | private: 50 | quint64 last_pong; 51 | QMap getIndexedAsks() const; 52 | QMap getIndexedBids() const; 53 | bool rebuildIndexes(); 54 | 55 | QJsonArray getAsks() const; 56 | QJsonArray getBids() const; 57 | 58 | void initLakebtcInterval(); 59 | void initLivecoinInterval(); 60 | 61 | void initExmoInterval(); 62 | 63 | void initBitfinexInterval(); 64 | void initLivecoinWs() { 65 | 66 | } 67 | void initKucoinInterval(); 68 | void initZbInterval(); 69 | void initLbankInterval(); 70 | void initLbankWs(); 71 | void initBittrexInterval(); 72 | void initCexioInterval(); 73 | void initCexioWs(); 74 | void initOkCoinInterval(); 75 | void initHuobiInterval(); 76 | 77 | void initNodeExchange(); 78 | 79 | void initHitbtcInterval(); 80 | void initKrakenInterval(); 81 | void initKrakenWs(); 82 | void initBinanceInterval(); 83 | void initBinanceWs(); 84 | 85 | void initIdcmInterval(); 86 | 87 | quint32 getPairId( const QString& pairname ) { 88 | if ( _target_pairs_rels.contains( pairname ) ) { 89 | return _target_pairs_rels.value( pairname ); 90 | } else { 91 | qWarning() << pairname; 92 | return 0; 93 | } 94 | } 95 | 96 | QMutex mutex; 97 | QNetworkAccessManager * netmanager; 98 | QSharedPointer websocket; 99 | QTimer * _request_interval_timer; 100 | QTimer * _publish_interval_timer; 101 | quint64 req_noncer; 102 | quint32 _request_interval; 103 | quint32 _publish_interval; 104 | NodeStates _current_state; 105 | 106 | QString _exchange_name; 107 | QString _target_pair; 108 | quint32 _target_pair_id; 109 | QList> _target_pairs; 110 | QMap _target_pairs_rels; 111 | // Orderbooks storage 112 | QMap _asks_indexed; 113 | QMap _bids_indexed; 114 | 115 | QJsonArray _asks; 116 | QJsonArray _bids; 117 | 118 | }; 119 | 120 | #endif // ORDERBOOKSNODE_H 121 | --------------------------------------------------------------------------------