From 0faa25840d2887721e98a8655a549a52d0552dea Mon Sep 17 00:00:00 2001 From: Carles Tubio Date: Sun, 19 Nov 2017 15:14:31 +0000 Subject: [PATCH 1/8] Fixed typo. Free Software Free Society To support commits by ctubio, you can buy-me-a-drink with a small git tip at: 1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u I promise to drink chocolate milk in the development of the next commit. To request new features or in case this commit breaks something for you, please create a new github issue with all possible details, but never share your API Keys! Signed-off-by: Carles Tubio --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a04311d32..4cb4565ae 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ V_UV := 1.15.0 V_SQL := 3200100 V_QF := v.1.14.4 V_PVS := 6.19.23789.1731 -KZIP = 3916a5af67afc112c8c273c24c7b5842af2b40ed +KZIP = 2ecb251b6f2334312f68e0479e89fa49579219bb KARGS = -Wextra -std=c++11 -O3 -I$(KLOCAL)/include \ src/server/K.cxx -pthread -rdynamic -DUSE_LIBUV \ -DK_STAMP='"$(shell date --rfc-3339=seconds | cut -f1 -d+)"' \ From 54d5edef8dee187c9dfe9d76542c75e23d15c5a7 Mon Sep 17 00:00:00 2001 From: Carles Tubio Date: Sun, 19 Nov 2017 18:05:04 +0000 Subject: [PATCH 2/8] Fixed scientific notation displayed in widthPing/Pong inputs. Free Software Free Society To support commits by ctubio, you can buy-me-a-drink with a small git tip at: 1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u I promise to drink chocolate milk in the development of the next commit. To request new features or in case this commit breaks something for you, please create a new github issue with all possible details, but never share your API Keys! Signed-off-by: Carles Tubio --- Makefile | 2 +- src/client/models.ts | 4 ++-- src/client/pair.ts | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 4cb4565ae..387d8175a 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ V_UV := 1.15.0 V_SQL := 3200100 V_QF := v.1.14.4 V_PVS := 6.19.23789.1731 -KZIP = 2ecb251b6f2334312f68e0479e89fa49579219bb +KZIP = 45463b7cbae598f1c148db16d97bda7d16a15ad5 KARGS = -Wextra -std=c++11 -O3 -I$(KLOCAL)/include \ src/server/K.cxx -pthread -rdynamic -DUSE_LIBUV \ -DK_STAMP='"$(shell date --rfc-3339=seconds | cut -f1 -d+)"' \ diff --git a/src/client/models.ts b/src/client/models.ts index 23719936d..e31a8aa09 100644 --- a/src/client/models.ts +++ b/src/client/models.ts @@ -184,9 +184,9 @@ export enum SOP { Off, Trades, Size, TradesSize } export enum STDEV { Off, OnFV, OnFVAPROff, OnTops, OnTopsAPROff, OnTop, OnTopAPROff } export interface QuotingParameters { - widthPing?: number; + widthPing?: any; widthPingPercentage?: number; - widthPong?: number; + widthPong?: any; widthPongPercentage?: number; widthPercentage?: boolean; bestWidth?: boolean; diff --git a/src/client/pair.ts b/src/client/pair.ts index 40a77e8fe..1ec621c8f 100644 --- a/src/client/pair.ts +++ b/src/client/pair.ts @@ -25,11 +25,16 @@ class FormViewModel { this.display = JSON.parse(JSON.stringify(defaultParameter)); } + public cleanDecimal = (p: T) => { + return p; + } + public reset = () => { this.display = JSON.parse(JSON.stringify(this.master)); }; public update = (p: T) => { + p = this.cleanDecimal(p); this.master = JSON.parse(JSON.stringify(p)); this.display = JSON.parse(JSON.stringify(p)); this.pending = false; @@ -69,7 +74,11 @@ class DisplayQuotingParameters extends FormViewModel { constructor(sub: Subscribe.ISubscribe, fire: Subscribe.IFire) { - super({}, sub, fire); + super({}, sub, fire, (d: any) => { + d.widthPing = parseFloat(d.widthPing); + d.widthPong = parseFloat(d.widthPong); + return d; + }); this.availableQuotingModes = DisplayQuotingParameters.getMapping(Models.QuotingMode); this.availableQuotingSafeties = DisplayQuotingParameters.getMapping(Models.QuotingSafety); @@ -82,6 +91,12 @@ class DisplayQuotingParameters extends FormViewModel { this.availableSTDEV = DisplayQuotingParameters.getMapping(Models.STDEV); } + public cleanDecimal = (d: any) => { + d.widthPing = parseFloat(d.widthPing).toFixed(13).replace(/0+$/,'').replace(/\.$/,''); + d.widthPong = parseFloat(d.widthPong).toFixed(13).replace(/0+$/,'').replace(/\.$/,''); + return d; + } + private static getMapping(enumObject: T) { let names = []; for (let mem in enumObject) { From e82f0f5c01fd3bf1dab94666d77e0bbaaae6a7f8 Mon Sep 17 00:00:00 2001 From: Carles Tubio Date: Sun, 19 Nov 2017 18:10:32 +0000 Subject: [PATCH 3/8] Fixed scientific notation displayed in buy/sellSize inputs. Free Software Free Society To support commits by ctubio, you can buy-me-a-drink with a small git tip at: 1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u I promise to drink chocolate milk in the development of the next commit. To request new features or in case this commit breaks something for you, please create a new github issue with all possible details, but never share your API Keys! Signed-off-by: Carles Tubio --- src/client/models.ts | 4 ++-- src/client/pair.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/models.ts b/src/client/models.ts index e31a8aa09..c38e88fe2 100644 --- a/src/client/models.ts +++ b/src/client/models.ts @@ -190,10 +190,10 @@ export interface QuotingParameters { widthPongPercentage?: number; widthPercentage?: boolean; bestWidth?: boolean; - buySize?: number; + buySize?: any; buySizePercentage?: number; buySizeMax?: boolean; - sellSize?: number; + sellSize?: any; sellSizePercentage?: number; sellSizeMax?: boolean; pingAt?: PingAt; diff --git a/src/client/pair.ts b/src/client/pair.ts index 1ec621c8f..cbba63413 100644 --- a/src/client/pair.ts +++ b/src/client/pair.ts @@ -77,6 +77,8 @@ class DisplayQuotingParameters extends FormViewModel { super({}, sub, fire, (d: any) => { d.widthPing = parseFloat(d.widthPing); d.widthPong = parseFloat(d.widthPong); + d.buySize = parseFloat(d.buySize); + d.sellSize = parseFloat(d.sellSize); return d; }); @@ -94,6 +96,8 @@ class DisplayQuotingParameters extends FormViewModel { public cleanDecimal = (d: any) => { d.widthPing = parseFloat(d.widthPing).toFixed(13).replace(/0+$/,'').replace(/\.$/,''); d.widthPong = parseFloat(d.widthPong).toFixed(13).replace(/0+$/,'').replace(/\.$/,''); + d.buySize = parseFloat(d.buySize).toFixed(13).replace(/0+$/,'').replace(/\.$/,''); + d.sellSize = parseFloat(d.sellSize).toFixed(13).replace(/0+$/,'').replace(/\.$/,''); return d; } From fc9ab833f78e96586d8267a25c8a9b5709b2017b Mon Sep 17 00:00:00 2001 From: Carles Tubio Date: Sun, 19 Nov 2017 19:27:22 +0000 Subject: [PATCH 4/8] Fixed truncated decimals right before send to exchange :( to resolve #403. Free Software Free Society To support commits by ctubio, you can buy-me-a-drink with a small git tip at: 1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u I promise to drink chocolate milk in the development of the next commit. To request new features or in case this commit breaks something for you, please create a new github issue with all possible details, but never share your API Keys! Signed-off-by: Carles Tubio --- Makefile | 2 +- src/server/km.h | 17 ++++++++++++++++- src/server/og.h | 8 ++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 387d8175a..2adf22ddf 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ V_UV := 1.15.0 V_SQL := 3200100 V_QF := v.1.14.4 V_PVS := 6.19.23789.1731 -KZIP = 45463b7cbae598f1c148db16d97bda7d16a15ad5 +KZIP = fc8c033287046ba46389843a8835fa3348a3ff61 KARGS = -Wextra -std=c++11 -O3 -I$(KLOCAL)/include \ src/server/K.cxx -pthread -rdynamic -DUSE_LIBUV \ -DK_STAMP='"$(shell date --rfc-3339=seconds | cut -f1 -d+)"' \ diff --git a/src/server/km.h b/src/server/km.h index 7359ade21..fae4be965 100644 --- a/src/server/km.h +++ b/src/server/km.h @@ -379,6 +379,21 @@ namespace K { mOrder(string o, mExchange e, mPair P, mSide S, double q, mOrderType t, bool i, double p, mTimeInForce F, mORS s, bool O): orderId(o), exchangeId(""), exchange(e), pair(P), side(S), quantity(q), type(t), isPong(i), price(p), timeInForce(F), orderStatus(s), preferPostOnly(O), lastQuantity(0), time(0), computationalLatency(0) {}; + string quantity2str() { + stringstream ss; + ss << setprecision(8) << fixed << quantity; + return ss.str(); + }; + string lastQuantity2str() { + stringstream ss; + ss << setprecision(8) << fixed << lastQuantity; + return ss.str(); + }; + string price2str() { + stringstream ss; + ss << setprecision(8) << fixed << price; + return ss.str(); + }; }; static void to_json(json& j, const mOrder& k) { j = { @@ -513,7 +528,7 @@ namespace K { virtual string A() = 0; virtual void wallet() = 0, levels() = 0, - send(string oI, mSide oS, double oP, double oQ, mOrderType oLM, mTimeInForce oTIF, bool oPO, unsigned long oT) = 0, + send(string oI, mSide oS, string oP, string oQ, mOrderType oLM, mTimeInForce oTIF, bool oPO, unsigned long oT) = 0, cancel(string oI, string oE, mSide oS, unsigned long oT) = 0, cancelAll() = 0, close() = 0; diff --git a/src/server/og.h b/src/server/og.h index fedf9e8c0..1f0ee5129 100644 --- a/src/server/og.h +++ b/src/server/og.h @@ -36,7 +36,7 @@ namespace K { void waitData() { gw->evDataOrder = [&](mOrder k) { if (((CF*)config)->argDebugEvents) FN::log("DEBUG", "EV OG evDataOrder"); - if (((CF*)config)->argDebugOrders) FN::log("DEBUG", string("OG reply ") + k.orderId + "::" + k.exchangeId + " [" + to_string((int)k.orderStatus) + "]: " + to_string(k.quantity) + "/" + to_string(k.lastQuantity) + " at price " + to_string(k.price)); + if (((CF*)config)->argDebugOrders) FN::log("DEBUG", string("OG reply ") + k.orderId + "::" + k.exchangeId + " [" + to_string((int)k.orderStatus) + "]: " + k.quantity2str() + "/" + k.lastQuantity2str() + " at price " + k.price2str()); updateOrderState(k); }; }; @@ -53,8 +53,8 @@ namespace K { public: void sendOrder(mSide oS, double oP, double oQ, mOrderType oLM, mTimeInForce oTIF, bool oIP, bool oPO) { mOrder o = updateOrderState(mOrder(gw->randId(), gw->exchange, mPair(gw->base, gw->quote), oS, oQ, oLM, oIP, FN::roundSide(oP, gw->minTick, oS), oTIF, mORS::New, oPO)); - if (((CF*)config)->argDebugOrders) FN::log("DEBUG", string("OG send ") + (o.side == mSide::Bid ? "BID id " : "ASK id ") + o.orderId + ": " + to_string(o.quantity) + " " + o.pair.base + " at price " + to_string(o.price) + " " + o.pair.quote); - gw->send(o.orderId, o.side, o.price, o.quantity, o.type, o.timeInForce, o.preferPostOnly, o.time); + if (((CF*)config)->argDebugOrders) FN::log("DEBUG", string("OG send ") + (o.side == mSide::Bid ? "BID id " : "ASK id ") + o.orderId + ": " + o.quantity2str() + " " + o.pair.base + " at price " + o.price2str() + " " + o.pair.quote); + gw->send(o.orderId, o.side, o.price2str(), o.quantity2str(), o.type, o.timeInForce, o.preferPostOnly, o.time); ++((UI*)client)->orders60sec; }; void cancelOrder(string k) { @@ -334,7 +334,7 @@ namespace K { allOrdersIds[k.exchangeId] = k.orderId; allOrders[k.orderId] = k; ogMutex.unlock(); - if (((CF*)config)->argDebugOrders) FN::log("DEBUG", string("OG save ") + (k.side == mSide::Bid ? "BID id " : "ASK id ") + k.orderId + "::" + k.exchangeId + " [" + to_string((int)k.orderStatus) + "]: " + to_string(k.quantity) + " " + k.pair.base + " at price " + to_string(k.price) + " " + k.pair.quote); + if (((CF*)config)->argDebugOrders) FN::log("DEBUG", string("OG save ") + (k.side == mSide::Bid ? "BID id " : "ASK id ") + k.orderId + "::" + k.exchangeId + " [" + to_string((int)k.orderStatus) + "]: " + k.quantity2str() + " " + k.pair.base + " at price " + k.price2str() + " " + k.pair.quote); } else cleanOrder(k.orderId, k.exchangeId); if (((CF*)config)->argDebugOrders) FN::log("DEBUG", string("OG memory ") + to_string(allOrders.size()) + "/" + to_string(allOrdersIds.size())); }; From 54a4fa1e77a1380e95c16e8845de4b9b586e7533 Mon Sep 17 00:00:00 2001 From: Carles Tubio Date: Mon, 20 Nov 2017 01:44:33 +0000 Subject: [PATCH 5/8] Updated websocket to epoll threadsafe to avoid all segfaults. Free Software Free Society To support commits by ctubio, you can buy-me-a-drink with a small git tip at: 1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u I promise to drink chocolate milk in the development of the next commit. To request new features or in case this commit breaks something for you, please create a new github issue with all possible details, but never share your API Keys! Signed-off-by: Carles Tubio --- Makefile | 21 ++++++--------------- README.md | 2 -- src/server/K.cxx | 1 - src/server/ev.h | 44 +++++++++++++++++++------------------------- src/server/fn.h | 8 -------- src/server/gw.h | 10 +++++----- src/server/km.h | 1 - src/server/qe.h | 10 +++++----- src/server/ui.h | 26 ++++++++++---------------- 9 files changed, 45 insertions(+), 78 deletions(-) diff --git a/Makefile b/Makefile index 2adf22ddf..7357c3ae4 100644 --- a/Makefile +++ b/Makefile @@ -12,20 +12,18 @@ V_CURL := 7.55.1 V_NCUR := 6.0 V_JSON := v2.1.1 V_UWS := 0.14.4 -V_UV := 1.15.0 V_SQL := 3200100 V_QF := v.1.14.4 V_PVS := 6.19.23789.1731 -KZIP = fc8c033287046ba46389843a8835fa3348a3ff61 +KZIP = a2abda031cbdd155fca04184d463efcd03da691e KARGS = -Wextra -std=c++11 -O3 -I$(KLOCAL)/include \ - src/server/K.cxx -pthread -rdynamic -DUSE_LIBUV \ + src/server/K.cxx -pthread -rdynamic -DUWS_THREADSAFE \ -DK_STAMP='"$(shell date --rfc-3339=seconds | cut -f1 -d+)"' \ -DK_BUILD='"$(CHOST)"' $(KLOCAL)/include/uWS/*.cpp \ $(KLOCAL)/lib/K-$(CHOST).a $(KLOCAL)/lib/libquickfix.a \ $(KLOCAL)/lib/libsqlite3.a $(KLOCAL)/lib/libz.a \ $(KLOCAL)/lib/libcurl.a $(KLOCAL)/lib/libssl.a \ - $(KLOCAL)/lib/libcrypto.a $(KLOCAL)/lib/libncurses.a \ - $(KLOCAL)/lib/libuv.a -ldl + $(KLOCAL)/lib/libcrypto.a $(KLOCAL)/lib/libncurses.a -ldl all: K @@ -70,7 +68,6 @@ help: # make pvs - download pvs src files # # make zlib - download zlib src files # # make curl - download curl src files # - # make libuv - download libuv src files # # make ncurses - download ncurses src files # # make sqlite - download sqlite src files # # make openssl - download openssl src files # @@ -98,7 +95,7 @@ ifdef KALL unset KALL && echo -n $(CARCH) | xargs -I % -d ' ' $(MAKE) CHOST=% $@ else mkdir -p build-$(CHOST) - CHOST=$(CHOST) $(MAKE) zlib openssl curl sqlite ncurses libuv json uws quickfix + CHOST=$(CHOST) $(MAKE) zlib openssl curl sqlite ncurses json uws quickfix test -f /sbin/ldconfig && sudo ldconfig || : endif @@ -150,12 +147,6 @@ ncurses: build-$(CHOST) --prefix=$(PWD)/$(KLOCAL) --with-fallbacks=linux,screen,vt100,xterm,xterm-256color,putty-256color \ && make && make install ) -libuv: build-$(CHOST) - test -d build-$(CHOST)/libuv-$(V_UV) || ( \ - curl -L https://github.com/libuv/libuv/archive/v$(V_UV).tar.gz | tar xz -C build-$(CHOST) \ - && cd build-$(CHOST)/libuv-$(V_UV) && sh autogen.sh && CC=$(CC) ./configure --host=$(CHOST) \ - --prefix=$(PWD)/$(KLOCAL) && make && make install ) - json: build-$(CHOST) test -f $(KLOCAL)/include/json.h || (mkdir -p $(KLOCAL)/include \ && curl -L https://github.com/nlohmann/json/releases/download/$(V_JSON)/json.hpp \ @@ -195,7 +186,7 @@ cleandb: /data/db/K* packages: test -n "`command -v apt-get`" && sudo apt-get -y install g++ build-essential automake autoconf libtool libxml2 libxml2-dev zlib1g-dev openssl stunnel python curl gzip imagemagick screen \ || (test -n "`command -v yum`" && sudo yum -y install gcc-c++ automake autoconf libtool libxml2 libxml2-devel openssl stunnel python curl gzip ImageMagick screen) \ - || (test -n "`command -v brew`" && (xcode-select --install || :) && (brew install automake autoconf libxml2 sqlite openssl zlib libuv stunnel python curl gzip imagemagick || brew upgrade || :)) \ + || (test -n "`command -v brew`" && (xcode-select --install || :) && (brew install automake autoconf libxml2 sqlite openssl zlib stunnel python curl gzip imagemagick || brew upgrade || :)) \ || (test -n "`command -v pacman`" && sudo pacman --noconfirm -S --needed base-devel libxml2 zlib sqlite curl libcurl-compat openssl stunnel python gzip imagemagick screen) sudo mkdir -p /data/db/ sudo chown $(shell id -u) /data/db @@ -362,4 +353,4 @@ md5: src asandwich: @test `whoami` = 'root' && echo OK || echo make it yourself! -.PHONY: K dist link Linux Darwin build zlib openssl curl ncurses libuv quickfix uws json pvs clean cleandb list screen start stop restart startall stopall restartall gdax packages install docker travis reinstall client www bundle diff latest changelog test test-cov send-cov png png-check release md5 asandwich +.PHONY: K dist link Linux Darwin build zlib openssl curl ncurses quickfix uws json pvs clean cleandb list screen start stop restart startall stopall restartall gdax packages install docker travis reinstall client www bundle diff latest changelog test test-cov send-cov png png-check release md5 asandwich diff --git a/README.md b/README.md index ce78e5d8d..d856f0338 100644 --- a/README.md +++ b/README.md @@ -375,8 +375,6 @@ or donate your time with programming or financial suggestions in the topical IRC - https://github.com/michaelgrosner/tribeca (https://github.com/michaelgrosner) - https://www.sqlite.org - https://github.com/michaelgrosner/tribeca (https://github.com/michaelgrosner) -- http://libuv.org -- https://github.com/michaelgrosner/tribeca (https://github.com/michaelgrosner) ### Help diff --git a/src/server/K.cxx b/src/server/K.cxx index ca4b09f0c..7713b477a 100644 --- a/src/server/K.cxx +++ b/src/server/K.cxx @@ -21,7 +21,6 @@ using namespace std; -#include "uv.h" #include "json.h" #include "sqlite3.h" #include "uWS/uWS.h" diff --git a/src/server/ev.h b/src/server/ev.h index fdc7e5bc8..ba14245cf 100644 --- a/src/server/ev.h +++ b/src/server/ev.h @@ -7,13 +7,12 @@ namespace K { uWS::Hub *hub = nullptr; int eCode = EXIT_FAILURE; public: - mutex hubMutex; uWS::Group *uiGroup = nullptr; - uv_timer_t *tCalcs = nullptr, - *tStart = nullptr, - *tDelay = nullptr, - *tWallet = nullptr, - *tCancel = nullptr; + Timer *tCalcs = nullptr, + *tStart = nullptr, + *tDelay = nullptr, + *tWallet = nullptr, + *tCancel = nullptr; function ogOrder; function ogTrade; function mgLevels, @@ -32,14 +31,13 @@ namespace K { gw->hub = hub = new uWS::Hub(0, true); }; void waitTime() { - uv_timer_init(hub->getLoop(), tCalcs = new uv_timer_t()); - uv_timer_init(hub->getLoop(), tStart = new uv_timer_t()); - uv_timer_init(hub->getLoop(), tDelay = new uv_timer_t()); - uv_timer_init(hub->getLoop(), tWallet = new uv_timer_t()); - uv_timer_init(hub->getLoop(), tCancel = new uv_timer_t()); + tCalcs = new Timer(hub->getLoop()); + tStart = new Timer(hub->getLoop()); + tDelay = new Timer(hub->getLoop()); + tWallet = new Timer(hub->getLoop()); + tCancel = new Timer(hub->getLoop()); }; void waitData() { - gw->hubMutex = &hubMutex; gw->gwGroup = hub->createGroup(); }; void waitUser() { @@ -61,19 +59,15 @@ namespace K { }; void stop(int code, function gwCancelAll) { eCode = code; - if (uv_loop_alive(hub->getLoop())) { - uv_timer_stop(tCancel); - uv_timer_stop(tWallet); - uv_timer_stop(tCalcs); - uv_timer_stop(tStart); - uv_timer_stop(tDelay); - gw->close(); - gw->gwGroup->close(); - gwCancelAll(); - uiGroup->close(); - FN::close(hub->getLoop()); - hub->getLoop()->destroy(); - } + tCancel->stop(); + tWallet->stop(); + tCalcs->stop(); + tStart->stop(); + tDelay->stop(); + gw->close(); + gw->gwGroup->close(); + gwCancelAll(); + uiGroup->close(); halt(code); }; void listen(int port) { diff --git a/src/server/fn.h b/src/server/fn.h index da628187f..07222f83f 100644 --- a/src/server/fn.h +++ b/src/server/fn.h @@ -768,14 +768,6 @@ namespace K { redrawwin(wLog); wrefresh(wLog); }; - static void close(uv_loop_t* loop) { - uv_walk(loop, close_walk_cb, NULL); - uv_run(loop, UV_RUN_DEFAULT); - }; - static void close_walk_cb(uv_handle_t* handle, void* arg) { - if (!uv_is_closing(handle)) - uv_close(handle, NULL); - }; }; class B64 { public: diff --git a/src/server/gw.h b/src/server/gw.h index 1fcf4c750..701ca7a46 100644 --- a/src/server/gw.h +++ b/src/server/gw.h @@ -16,14 +16,14 @@ namespace K { handshake(gw->exchange); }; void waitTime() { - ((EV*)events)->tWallet->data = (void*)this; - uv_timer_start(((EV*)events)->tWallet, [](uv_timer_t *handle) { + ((EV*)events)->tWallet->setData(this); + ((EV*)events)->tWallet->start([](Timer *handle) { GW *k = (GW*)handle->data; if (((CF*)k->config)->argDebugEvents) FN::log("DEBUG", "EV GW tWallet timer"); k->gw->wallet(); }, 0, 15e+3); - ((EV*)events)->tCancel->data = (void*)this; - uv_timer_start(((EV*)events)->tCancel, [](uv_timer_t *handle) { + ((EV*)events)->tCancel->setData(this); + ((EV*)events)->tCancel->start([](Timer *handle) { GW *k = (GW*)handle->data; if (((CF*)k->config)->argDebugEvents) FN::log("DEBUG", "EV GW tCancel timer"); if (k->qp->cancelOrdersAuto) @@ -135,7 +135,7 @@ namespace K { string _price_ = price_.str(); for (string::iterator it=_price_.begin(); it!=_price_.end();) if (*it == '+' or *it == '-') break; else it = _price_.erase(it); - stringstream os(string("1e").append(to_string(stod(_price_)-4))); + stringstream os(string("1e").append(to_string(fmax(stod(_price_),-4)-4))); os >> gw->minTick; } k = FN::wJet(string(gw->http).append("/symbols_details")); diff --git a/src/server/km.h b/src/server/km.h index fae4be965..c6130cf2a 100644 --- a/src/server/km.h +++ b/src/server/km.h @@ -513,7 +513,6 @@ namespace K { function evDataLevels; function evConnectOrder, evConnectMarket; - mutex *hubMutex = nullptr; uWS::Hub *hub = nullptr; uWS::Group *gwGroup = nullptr; mExchange exchange = mExchange::Null; diff --git a/src/server/qe.h b/src/server/qe.h index d536ffd94..48c7a5eb6 100644 --- a/src/server/qe.h +++ b/src/server/qe.h @@ -24,9 +24,9 @@ namespace K { quotingMode[mQuotingMode::Depth] = &calcDepthOfMarket; }; void waitTime() { - ((EV*)events)->tStart->data = (void*)this; - ((EV*)events)->tCalcs->data = (void*)this; - uv_timer_start(((EV*)events)->tCalcs, [](uv_timer_t *handle) { + ((EV*)events)->tStart->setData(this); + ((EV*)events)->tCalcs->setData(this); + ((EV*)events)->tCalcs->start([](Timer *handle) { QE *k = (QE*)handle->data; if (((CF*)k->config)->argDebugEvents) FN::log("DEBUG", "EV GW tCalcs timer"); if (((MG*)k->market)->fairValue) { @@ -544,10 +544,10 @@ namespace K { nextStart[side] = q; nextIsPong = isPong; if (tStarted) { - uv_timer_stop(((EV*)events)->tStart); + ((EV*)events)->tStart->stop(); tStarted = 0; } - uv_timer_start(((EV*)events)->tStart, [](uv_timer_t *handle) { + ((EV*)events)->tStart->start([](Timer *handle) { QE *k = (QE*)handle->data; if (((CF*)k->config)->argDebugEvents) FN::log("DEBUG", "EV GW tStart timer"); k->start(k->nextStart.begin()->first, k->nextStart.begin()->second, k->nextIsPong); diff --git a/src/server/ui.h b/src/server/ui.h index c576e180d..5a886e227 100644 --- a/src/server/ui.h +++ b/src/server/ui.h @@ -11,6 +11,7 @@ namespace K { map queue; map*> hello; map*> kiss; + bool realtimeClient = false; public: unsigned int orders60sec = 0; protected: @@ -26,8 +27,8 @@ namespace K { }; void waitTime() { if (((CF*)config)->argHeadless) return; - ((EV*)events)->tDelay->data = (void*)this; - uv_timer_start(((EV*)events)->tDelay, sendState, 0, 0); + ((EV*)events)->tDelay->setData(this); + ((EV*)events)->tDelay->start(sendState, 0, 0); }; void waitData() { if (((CF*)config)->argHeadless) return; @@ -43,7 +44,6 @@ namespace K { string auth = req.getHeader("authorization").toString(); string addr = res->getHttpSocket()->getAddress().address; if (addr.length() > 7 and addr.substr(0, 7) == "::ffff:") addr = addr.substr(7); - lock_guard lock(((EV*)events)->hubMutex); if (((CF*)config)->argWhitelist != "" and ((CF*)config)->argWhitelist.find(addr) == string::npos) { FN::log("UI", "dropping gzip bomb on", addr); content << ifstream("etc/K-bomb.gzip").rdbuf(); @@ -109,10 +109,7 @@ namespace K { } if (uiBIT::Hello == (uiBIT)message[0] and hello.find(message[1]) != hello.end()) { json reply = (*hello[message[1]])(); - if (!reply.is_null()) { - lock_guard lock(((EV*)events)->hubMutex); - webSocket->send(string(message, 2).append(reply.dump()).data(), uWS::OpCode::TEXT); - } + if (!reply.is_null()) webSocket->send(string(message, 2).append(reply.dump()).data(), uWS::OpCode::TEXT); } else if (uiBIT::Kiss == (uiBIT)message[0] and kiss.find(message[1]) != kiss.end()) (*kiss[message[1]])(json::parse((length > 2 and (message[2] == '[' or message[2] == '{')) ? string(message, length).substr(2, length-2) : "{}" @@ -145,12 +142,13 @@ namespace K { }; void delayme(double delayUI) { if (((CF*)config)->argHeadless) return; - uv_timer_set_repeat(((EV*)events)->tDelay, delayUI > 0 ? (int)(delayUI*1e+3) : 6e+4 + 1); - uv_timer_again(((EV*)events)->tDelay); + realtimeClient = !delayUI; + ((EV*)events)->tDelay->stop(); + ((EV*)events)->tDelay->start(sendState, 0, realtimeClient ? 6e+4 : (int)(delayUI*1e+3)); }; void send(uiTXT k, json o, bool delayed = false) { if (((CF*)config)->argHeadless or connections == 0) return; - if (realtimeClient() or !delayed) send(k, o.dump()); + if (realtimeClient or !delayed) send(k, o.dump()); else queue[k] = o.dump(); }; private: @@ -174,7 +172,6 @@ namespace K { void send(uiTXT k, string j) { string m(1, (char)uiBIT::Kiss); m += string(1, (char)k) + j; - lock_guard lock(((EV*)events)->hubMutex); ((EV*)events)->uiGroup->broadcast(m.data(), m.length(), uWS::OpCode::TEXT); }; void sendQueue() { @@ -182,10 +179,10 @@ namespace K { send(it->first, it->second); queue.clear(); }; - void (*sendState)(uv_timer_t*) = [](uv_timer_t *handle) { + void (*sendState)(Timer*) = [](Timer *handle) { UI *k = (UI*)handle->data; if (((CF*)k->config)->argDebugEvents) FN::log("DEBUG", "EV UI tDelay timer"); - if (!k->realtimeClient()) { + if (!k->realtimeClient) { k->sendQueue(); static unsigned long uiT_1m = 0; if (uiT_1m+6e+4 > FN::T()) return; @@ -205,9 +202,6 @@ namespace K { {"a", gw->A()} }; }; - bool realtimeClient() { - return uv_timer_get_repeat(((EV*)events)->tDelay) == 6e+4 + 1; - }; }; } From e906124b3f3e0dd09bc2cae5a23615d26e04e507 Mon Sep 17 00:00:00 2001 From: Carles Tubio Date: Mon, 20 Nov 2017 02:01:08 +0000 Subject: [PATCH 6/8] Updated missing timers to epoll. Free Software Free Society To support commits by ctubio, you can buy-me-a-drink with a small git tip at: 1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u I promise to drink chocolate milk in the development of the next commit. To request new features or in case this commit breaks something for you, please create a new github issue with all possible details, but never share your API Keys! Signed-off-by: Carles Tubio --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7357c3ae4..7d173bc00 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ V_UWS := 0.14.4 V_SQL := 3200100 V_QF := v.1.14.4 V_PVS := 6.19.23789.1731 -KZIP = a2abda031cbdd155fca04184d463efcd03da691e +KZIP = 4533e7558b8aedc1adff770eea91158f376159e2 KARGS = -Wextra -std=c++11 -O3 -I$(KLOCAL)/include \ src/server/K.cxx -pthread -rdynamic -DUWS_THREADSAFE \ -DK_STAMP='"$(shell date --rfc-3339=seconds | cut -f1 -d+)"' \ From fea332e8d4b65e1d07f9856d2cd69f05a6536164 Mon Sep 17 00:00:00 2001 From: Carles Tubio Date: Tue, 21 Nov 2017 01:06:43 +0000 Subject: [PATCH 7/8] Updated exit event without useless var. Free Software Free Society To support commits by ctubio, you can buy-me-a-drink with a small git tip at: 1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u I promise to drink chocolate milk in the development of the next commit. To request new features or in case this commit breaks something for you, please create a new github issue with all possible details, but never share your API Keys! Signed-off-by: Carles Tubio --- Makefile | 2 +- src/server/ev.h | 3 --- src/server/ui.h | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 7d173bc00..c2e6ea7dc 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ V_UWS := 0.14.4 V_SQL := 3200100 V_QF := v.1.14.4 V_PVS := 6.19.23789.1731 -KZIP = 4533e7558b8aedc1adff770eea91158f376159e2 +KZIP = 3387f80fdf03799072cd973561449506507cfd6d KARGS = -Wextra -std=c++11 -O3 -I$(KLOCAL)/include \ src/server/K.cxx -pthread -rdynamic -DUWS_THREADSAFE \ -DK_STAMP='"$(shell date --rfc-3339=seconds | cut -f1 -d+)"' \ diff --git a/src/server/ev.h b/src/server/ev.h index ba14245cf..58cbe933b 100644 --- a/src/server/ev.h +++ b/src/server/ev.h @@ -5,7 +5,6 @@ namespace K { class EV: public Klass { private: uWS::Hub *hub = nullptr; - int eCode = EXIT_FAILURE; public: uWS::Group *uiGroup = nullptr; Timer *tCalcs = nullptr, @@ -55,10 +54,8 @@ namespace K { public: void start() { hub->run(); - halt(eCode); }; void stop(int code, function gwCancelAll) { - eCode = code; tCancel->stop(); tWallet->stop(); tCalcs->stop(); diff --git a/src/server/ui.h b/src/server/ui.h index 5a886e227..173edef51 100644 --- a/src/server/ui.h +++ b/src/server/ui.h @@ -8,10 +8,10 @@ namespace K { string B64auth = "", notepad = ""; bool toggleSettings = true; + bool realtimeClient = false; map queue; map*> hello; map*> kiss; - bool realtimeClient = false; public: unsigned int orders60sec = 0; protected: From acf1c0dd27aa3d4f2505329c75ed39e4cf358503 Mon Sep 17 00:00:00 2001 From: Carles Tubio Date: Tue, 21 Nov 2017 01:43:40 +0000 Subject: [PATCH 8/8] Added Q hotkey like q to exit ncurses. Free Software Free Society To support commits by ctubio, you can buy-me-a-drink with a small git tip at: 1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u I promise to drink chocolate milk in the development of the next commit. To request new features or in case this commit breaks something for you, please create a new github issue with all possible details, but never share your API Keys! Signed-off-by: Carles Tubio --- Makefile | 2 +- src/server/ev.h | 4 ++-- src/server/fn.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c2e6ea7dc..30c3e52a0 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ V_UWS := 0.14.4 V_SQL := 3200100 V_QF := v.1.14.4 V_PVS := 6.19.23789.1731 -KZIP = 3387f80fdf03799072cd973561449506507cfd6d +KZIP = 0b57ac8dc50c7fe025e6a8418e6e300d2677e668 KARGS = -Wextra -std=c++11 -O3 -I$(KLOCAL)/include \ src/server/K.cxx -pthread -rdynamic -DUWS_THREADSAFE \ -DK_STAMP='"$(shell date --rfc-3339=seconds | cut -f1 -d+)"' \ diff --git a/src/server/ev.h b/src/server/ev.h index 58cbe933b..b29fdbc3c 100644 --- a/src/server/ev.h +++ b/src/server/ev.h @@ -88,7 +88,7 @@ namespace K { cout << FN::uiT(); for(unsigned int i = 0; i < 21; ++i) cout << "THE END IS NEVER "; - cout << "THE END" << '\n'; + cout << "THE END." << '\n'; halt(code); }; static void quit(int sig) { @@ -96,7 +96,7 @@ namespace K { cout << '\n'; json k = FN::wJet("https://api.icndb.com/jokes/random?escape=javascript&limitTo=[nerdy]"); cout << FN::uiT() << "Excellent decision! " - << ((k.is_null() || !k["/value/joke"_json_pointer].is_string()) + << ((k.is_null() or !k["/value/joke"_json_pointer].is_string()) ? "let's plant a tree instead.." : k["/value/joke"_json_pointer].get() ) << '\n'; (*evExit)(EXIT_SUCCESS); diff --git a/src/server/fn.h b/src/server/fn.h index 07222f83f..48cd32be7 100644 --- a/src/server/fn.h +++ b/src/server/fn.h @@ -652,7 +652,7 @@ namespace K { signal(SIGWINCH, screen_resize); thread([&]() { int ch; - while ((ch = wgetch(wBorder)) != 'q') { + while ((ch = wgetch(wBorder)) != 'q' and ch != 'Q') { switch (ch) { case ERR: continue; // case KEY_PPAGE: wscrl(wLog, -3); wrefresh(wLog); break;