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 |
9 |
10 |
11 |
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