Skip to content

Commit

Permalink
fix url in datasource, last dir in leveraged strategy can report alert
Browse files Browse the repository at this point in the history
  • Loading branch information
ondra-novak committed Jan 6, 2021
1 parent d1cec19 commit fdc5bad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/brokers/datasrc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Value readPrices(const StrViewA &asset, const StrViewA &currency, std::uint64_t
url << "https://devel.novacisko.cz/prices/minute.php?asset="
<< simpleServer::urlEncode(asset)
<< "&currency=" << simpleServer::urlEncode(currency)
<< "&from =" << fromTime;
<< "&from=" << fromTime;

return httpc.GET(url.str()).map([&](Value v){return v[1];});

Expand Down
9 changes: 7 additions & 2 deletions src/main/strategy_leveraged_base.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ std::pair<typename Strategy_Leveraged<Calc>::OnTradeResult, PStrategy> Strategy_
nwst.position = cpos;
//store last price
nwst.last_price = tradePrice;
nwst.last_dir = sgn(st.last_price-tradePrice);
nwst.last_dir = sgn(tradeSize);

recalcNeutral(calc, cfg, nwst);

Expand Down Expand Up @@ -317,6 +317,7 @@ template<typename Calc>
IStrategy::OrderData Strategy_Leveraged<Calc>::getNewOrder(
const IStockApi::MarketInfo &minfo,
double curPrice, double price, double dir, double assets, double currency, bool rej) const {
bool fast_closed = false;
auto apos = assets - st.neutral_pos;
double asym = calcAsym(cfg,st);
if (cfg->max_loss && (curPrice < calcRoots().min || curPrice > calcRoots().max)) {
Expand Down Expand Up @@ -351,7 +352,11 @@ IStrategy::OrderData Strategy_Leveraged<Calc>::getNewOrder(
newlev = std::abs(cps)*close_price / bal;
cnt --;
}
logDebug("Fast close on levr: newlev = $1, lev = $4, price = $2, cnt = $3",
newlev, close_price, cnt, lev);

if (cnt) {
fast_closed = true;
price = close_price;
}

Expand Down Expand Up @@ -382,7 +387,7 @@ IStrategy::OrderData Strategy_Leveraged<Calc>::getNewOrder(
double df = calcOrderSize(st.position,apos,cps);
/* double min_size = std::max(minfo.min_size, minfo.min_volume/price);
return {price, df, std::abs(cps) < min_size && std::abs(df) < min_size?Alert::forced:Alert::enabled};*/
return {price, df, cps == 0 ?Alert::forced:Alert::enabled};
return {price, df, cps == 0 || fast_closed?Alert::forced:Alert::enabled};
}
}

Expand Down

0 comments on commit fdc5bad

Please sign in to comment.