Skip to content

Commit

Permalink
Updated quote2orders() without useless lambdas ina for_each.
Browse files Browse the repository at this point in the history
████ ███  To request new features or in case this commit breaks something for you,
████ ███  please, create a new github issue with all possible information for me,
▓███▀█▄   but never share your API Keys!
▒▓██ ███
░▒▓█ ███  Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>
 _______________________________
/ Hello, WORLD!                 \
|                               |
\ pssst.. 1 BTC = 42057.83 EUR. /
 -------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
  • Loading branch information
ctubio committed Feb 23, 2021
1 parent 36bdbab commit 8614acc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ K ?= K.sh
MAJOR = 0
MINOR = 6
PATCH = 1
BUILD = 1
BUILD = 2

OBLIGATORY = DISCLAIMER: This is strict non-violent software: \
\nif you hurt other living creatures, please stop; \
Expand Down
34 changes: 13 additions & 21 deletions src/bin/scaling-bot/scaling-bot.data.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace analpaper {
};
bool ready() const {
const bool err = base.currency.empty() or quote.currency.empty();
if (err and Tspent > 7e+3)
if (err and Tspent > 21e+3)
K.logWar("QE", "Unable to calculate quote, missing wallet data", 3e+3);
return !err;
};
Expand Down Expand Up @@ -47,14 +47,13 @@ namespace analpaper {
Order *const order = upsert(raw);
if (!order) return;
if (raw.filled >= K.gateway->minSize) {
if (!order->isPong) {
if (!order->isPong)
last = {order->price, raw.filled, order->side};
K.gateway->askForFees = true;
K.log("GW " + K.gateway->exchange, "SCALING IN " + to_string(raw.filled) + " " + K.gateway->base + " at " + to_string(order->price) + " " + K.gateway->quote);
} else {
last.filled = 0;
K.log("GW " + K.gateway->exchange, "SCALING OUT " + to_string(raw.filled) + " " + K.gateway->base + " at " + to_string(order->price) + " " + K.gateway->quote);
}
K.gateway->askForFees = true;
K.log("GW " + K.gateway->exchange, string(order->isPong?"PONG":"PING") + " TRADE "
+ (order->side == Side::Bid ? "BUY " : "SELL ")
+ K.gateway->decimal.amount.str(raw.filled) + " " + K.gateway->base + " at "
+ K.gateway->decimal.price.str(order->price) + " " + K.gateway->quote);
}
if (order->isPong or order->status == Status::Terminated)
purge(order);
Expand Down Expand Up @@ -149,7 +148,7 @@ namespace analpaper {
};
bool ready() const {
const bool err = bids.empty() or asks.empty();
if (err and Tspent > 7e+3)
if (err and Tspent > 21e+3)
K.logWar("QE", "Unable to calculate quote, missing market data", 3e+3);
return !err;
};
Expand Down Expand Up @@ -444,10 +443,7 @@ namespace analpaper {
calculon.states(QuoteState::Disconnected);
};
bool ready() const {
const bool err = !(bool)greenGateway;
if (err and Tspent > 7e+3)
K.logWar("QE", "Unable to calculate quote, missing connection", 3e+3);
return !err;
return (bool)greenGateway;
};
void purge() {
for (const Order *const it : calculon.purge())
Expand All @@ -459,7 +455,7 @@ namespace analpaper {
quote2orders(calculon.quotes.bid);
};
void scale(const LastOrder &last) {
K.gateway->place(orders.upsert({
placeOrder({
last.side == Side::Bid
? Side::Ask
: Side::Bid,
Expand All @@ -472,7 +468,7 @@ namespace analpaper {
Tstamp,
true,
K.gateway->randId()
}));
});
};
private:
vector<Order*> abandon(Quote &quote) {
Expand All @@ -488,12 +484,8 @@ namespace analpaper {
const unsigned int replace = K.gateway->askForReplace and !(
quote.empty() or abandoned.empty()
);
for_each(
abandoned.begin(), abandoned.end() - replace,
[&](Order *const it) {
cancelOrder(it);
}
);
for (auto it = abandoned.begin(); it != abandoned.end() - replace;)
cancelOrder(*it++);
if (quote.empty()) return;
if (replace) replaceOrder(quote.price, quote.isPong, abandoned.back());
else placeOrder({
Expand Down
23 changes: 14 additions & 9 deletions src/bin/scaling-bot/scaling-bot.main.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ class ScalingBot: public KryptoNinja {
{"debug-quotes", "1", nullptr, "print detailed output about quoting engine"},
},
[&](MutableUserArguments &args) {
if (!arg<double>("order-size"))
error("CF", "Invalid empty --order-size value");
if (!arg<double>("ping-width"))
error("CF", "Invalid empty --ping-width value");
if (!arg<double>("pong-width"))
error("CF", "Invalid empty --pong-width value");
if (arg<int>("debug"))
args["debug-orders"] =
args["debug-quotes"] = 1;
if (!arg<int>("scale-asks") and !arg<int>("scale-bids"))
log("CF", "pings enabled on", "both sides");
else if (arg<int>("scale-asks") and arg<int>("scale-bids"))
Expand All @@ -37,9 +34,17 @@ class ScalingBot: public KryptoNinja {
log("CF", "pings enabled on", "ask side");
else if (arg<int>("scale-bids"))
log("CF", "pings enabled on", "bid side");
if (arg<int>("debug"))
args["debug-orders"] =
args["debug-quotes"] = 1;
Decimal opt;
opt.precision(1e-8);
if (!arg<double>("order-size"))
error("CF", "Invalid empty --order-size value");
else log("CF", "--order-size=", opt.str(arg<double>("order-size")));
if (!arg<double>("ping-width"))
error("CF", "Invalid empty --ping-width value");
else log("CF", "--ping-width=", opt.str(arg<double>("ping-width")));
if (!arg<double>("pong-width"))
error("CF", "Invalid empty --pong-width value");
else log("CF", "--pong-width=", opt.str(arg<double>("pong-width")));
}
};
};
Expand Down
12 changes: 4 additions & 8 deletions src/bin/trading-bot/trading-bot.data.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ namespace tribeca {
{};
bool warn_empty() const {
const bool err = bids.empty() or asks.empty();
if (err and Tspent > 7e+3)
if (err and Tspent > 21e+3)
K.logWar("QE", "Unable to calculate quote, missing market data", 3e+3);
return err;
};
Expand Down Expand Up @@ -1740,7 +1740,7 @@ namespace tribeca {
};
bool warn_empty() const {
const bool err = empty();
if (err and Tspent > 7e+3)
if (err and Tspent > 21e+3)
K.logWar("PG", "Unable to calculate TBP, missing wallet data", 3e+3);
return err;
};
Expand Down Expand Up @@ -2751,12 +2751,8 @@ namespace tribeca {
const unsigned int replace = K.gateway->askForReplace and !(
quote.empty() or abandoned.empty()
);
for_each(
abandoned.begin(), abandoned.end() - replace,
[&](Order *const it) {
cancelOrder(it);
}
);
for (auto it = abandoned.begin(); it != abandoned.end() - replace;)
cancelOrder(*it++);
if (quote.empty()) return;
if (replace)
replaceOrder(quote.price, quote.isPong, abandoned.back());
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Krypto.ninja-apis.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ namespace ₿ {
Future margin = (Future)0;
int debug = 0;
Connectivity adminAgreement = Connectivity::Disconnected;
virtual void disconnect() {};
virtual bool connected() const = 0;
virtual json handshake() const = 0;
virtual void disconnect() = 0;
virtual bool connected() const = 0;
virtual json handshake() const = 0;
json handshake(const bool &nocache) {
json reply;
const string cache = (K_HOME "/cache/handshake")
Expand Down
9 changes: 5 additions & 4 deletions src/lib/Krypto.ninja-bots.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ namespace ₿ {
else clog << Ansi::r(COLOR_WHITE);
clog << ' ' << reason;
if (!highlight.empty())
clog << ' ' << Ansi::b(COLOR_YELLOW) << highlight;
clog << string(reason.back() != '=', ' ') << Ansi::b(COLOR_YELLOW) << highlight;
clog << Ansi::r(COLOR_WHITE) << '.' << endl;
return;
}
Expand All @@ -284,7 +284,8 @@ namespace ₿ {
if (color == 1) wattroff(stdlog, COLOR_PAIR(COLOR_CYAN));
else if (color == -1) wattroff(stdlog, COLOR_PAIR(COLOR_MAGENTA));
if (!highlight.empty()) {
wprintw(stdlog, " ");
if (reason.back() != '=')
wprintw(stdlog, " ");
wattroff(stdlog, COLOR_PAIR(COLOR_WHITE));
wattron(stdlog, COLOR_PAIR(COLOR_YELLOW));
wprintw(stdlog, highlight.data());
Expand Down Expand Up @@ -392,7 +393,7 @@ namespace ₿ {
<< epilogue
<< string(epilogue.empty() ? 0 : 1, '\n');
});
args["autobot"] = headless;
args["autobot"] =
args["headless"] = headless;
args["dustybot"] = dustybot;
args["naked"] = !display.terminal;
Expand Down Expand Up @@ -448,7 +449,7 @@ namespace ₿ {
"\n" "default NUMBER is '321' and the minimum is '10'"}
}) long_options.push_back(it);
if (ev_order) long_options.push_back(
{"lifetime", "NUMBER", "0", "set NUMBER of minimum milliseconds to keep orders open,"
{"lifetime", "NUMBER", "0", "set NUMBER of minimum milliseconds to keep orders open,"
"\n" "otherwise open orders can be replaced anytime required"}
);
for (const Argument &it : arguments.first)
Expand Down

0 comments on commit 8614acc

Please sign in to comment.