I have already made rules fixes. And now rules executing correctly. I'll publish update soon.
You can tell me about your implementation of delay, and why safe-mode delay not works for you?
I have not been able to determine why it didn't work for me. Just that when enabled, everything comes to a halt.
As for how I implemented delay, I am using a double spinbox that keeps updating its value using the following code (which is also used to test if enough time has passed or not... currently hard-coded to 16 seconds in another place, but I plan to make it configurable. I also plan to change it to use milliseconds instead of seconds, but only so I can show tenths of a second)
public:
bool lastTradeElapsedTime(); // elapsed time since last executed trade =squeak=
bool QtBitcoinTrader::lastTradeElapsedTime() // returns pass/fail
{
ui.lastTradeTimestamp->setValue(difftime(time(0),baseValues.oldTradeTimestamp)); // also testing delay =squeak=
if(ui.lastTradeTimestamp->value()<=0) // color for pass/fail
{
ui.lastTradeTimestamp->setStyleSheet("QDoubleSpinBox {background: "+baseValues.appTheme.lightRed.name()+";}");
return false;
} else {
ui.lastTradeTimestamp->setStyleSheet("QDoubleSpinBox {background: "+baseValues.appTheme.lightGreen.name()+";}");
return true;
}
}
I included a lastTradeElapsedTime(); at the beginning of QtBitcoinTrader::checkAllRules() without evaluating it, just to keep the spinbox current.
I included a test for it in RuleHolder::isAchieved(double price), in a way so it would fail if elapsed time was still negative and the rule would execute a trade, but still allow enable/disable/cancel rules to pass even if elapsed time was negative.
and finally, within RuleWidget::checkAndExecuteRule(int ruleType, double price)
near the end, after the priceToExec checks, I have this...
if(ruleBtc>=baseValues.currentPair.tradeVolumeMin&&mainWindow.lastTradeElapsedTime())
{
if(isBuying)mainWindow.apiBuySend(ruleBtc,priceToExec<baseValues.currentPair.tradePriceMin?baseValues.currentPair.tradePriceMin:priceToExec);
else mainWindow.apiSellSend(ruleBtc,priceToExec<baseValues.currentPair.tradePriceMin?baseValues.currentPair.tradePriceMin:priceToExec);
baseValues.oldTradeTimestamp=time(0)+16; // update to current timestamp +16 seconds for lastTradeElapsedTime() delay. =squeak= =*= to-do: delay amount (16) make configurable
rulesModel->setRuleStateByHolder(achievedHolderList.at(n),2);
}
//qDebug()<<"State"<<priceToExec<<2;
//rulesModel->setRuleStateByHolder(achievedHolderList.at(n),2); //trying this above instead, so it doesn't change to 'done' if trade didn't occur. =squeak=
if(ui.ruleBeep->isChecked())mainWindow.beep();
I realize "lastTradeTimestamp" isn't accurate in how it is used, but it was in my earlier versions... this is my dirty code in my rough-draft copy while I work out what I want to do. I'll implement it better later in my other copy eventually.
(I currently have trading by portfolio-ratio running reliably (but not elegantly) and I still have a lot to do yet.)
This was one half of the solution, just to pace the trading... setting the enabled/disabled flags on the BTC/USD balance spinboxes were the other half. in QtBitcoinTrader::apiSellSend(double btc, double price), I "emit accBtcBalanceEnabled(false);" and accUsdBalanceEnabled... and do the same in apiBuySend().
Both have matching signals.
connect(this,SIGNAL(accBtcBalanceEnable(bool)),ui.accountBTC,SLOT(setEnabled(bool)));
where needed, and updated all of the exchange*.cpp files to "emit accBtcBalanceEnabled(true);" when a new balance was received without error.
I also changed a stylesheet (I forget where, but it looked like a generic call) somewhere, which was showing disabled in same color as enabled, and now disabled is grey, and also added a light-yellow option, for when the value hasn't changed.
So now, when it tests if a rule is achieved, it tests for both lastTradeTimestamp() being true, and if the relevant balance amount's box is enabled, for a rule to be achieved.
=squeak=