142 #include <irrxml/irrXML.hpp>
184 int32_t returnVal = 0;
197 if (!strcmp(
"trade", xml->getNodeName())) {
199 tradesAlreadyDone_ = atoi(xml->getAttributeValue(
"completedNoTrades"));
203 const OTString creationStr = xml->getAttributeValue(
"creationDate");
204 const OTString validFromStr = xml->getAttributeValue(
"validFrom");
205 const OTString validToStr = xml->getAttributeValue(
"validTo");
207 int64_t creation = creationStr.
ToLong();
208 int64_t validFrom = validFromStr.
ToLong();
209 int64_t validTo = validToStr.
ToLong();
215 OTString activated(xml->getAttributeValue(
"hasActivated"));
217 if (activated.Compare(
"true"))
218 hasTradeActivated_ =
true;
220 hasTradeActivated_ =
false;
222 const OTString serverID(xml->getAttributeValue(
"serverID")),
223 userID(xml->getAttributeValue(
"userID")),
224 assetTypeID(xml->getAttributeValue(
"assetTypeID")),
225 assetAcctID(xml->getAttributeValue(
"assetAcctID")),
226 currencyTypeID(xml->getAttributeValue(
"currencyTypeID")),
227 currencyAcctID(xml->getAttributeValue(
"currencyAcctID"));
229 const OTIdentifier SERVER_ID(serverID), USER_ID(userID),
230 ASSET_TYPE_ID(assetTypeID), ASSET_ACCT_ID(assetAcctID),
231 CURRENCY_TYPE_ID(currencyTypeID), CURRENCY_ACCT_ID(currencyAcctID);
241 <<
" Completed # of Trades: " << tradesAlreadyDone_ <<
"\n";
243 otWarn <<
" Creation Date: " << creation
244 <<
" Valid From: " << validFrom <<
"\n Valid To: " << validTo
246 " assetTypeID: " << assetTypeID
247 <<
"\n assetAcctID: " << assetAcctID <<
"\n"
248 " ServerID: " << serverID
249 <<
"\n UserID: " << userID
251 " currencyTypeID: " << currencyTypeID
252 <<
"\n currencyAcctID: " << currencyAcctID <<
"\n ";
257 if (!strcmp(
"stopOrder", xml->getNodeName())) {
258 OTString sign(xml->getAttributeValue(
"sign"));
260 if (sign.Compare(
"0")) {
263 otErr <<
"Strange: Stop order tag found in trade, but sign "
264 "character set to 0.\n"
265 "(Zero means: NOT a stop order.)\n";
268 else if (sign.Compare(
"<"))
270 else if (sign.Compare(
">"))
274 otErr <<
"Unexpected or nonexistent value in stop order sign: "
281 stopPrice_ = atol(xml->getAttributeValue(
"price"));
283 OTString activated(xml->getAttributeValue(
"hasActivated"));
285 if (activated.Compare(
"true"))
286 stopActivated_ =
true;
288 stopActivated_ =
false;
290 otLog3 <<
"\n\nStop order -- "
291 << (stopActivated_ ?
"Already activated" :
"Will activate")
292 <<
" when price " << (stopActivated_ ?
"was" :
"reaches") <<
" "
293 << ((
'<' == stopSign_) ?
"LESS THAN" :
"GREATER THAN") <<
": "
294 << stopPrice_ <<
".\n";
298 else if (!strcmp(
"offer", xml->getNodeName())) {
300 otErr <<
"Error in OTTrade::ProcessXMLNode: offer field without "
324 "<trade\n version=\"%s\"\n"
325 " hasActivated=\"%s\"\n"
327 " assetTypeID=\"%s\"\n"
328 " assetAcctID=\"%s\"\n"
329 " currencyTypeID=\"%s\"\n"
330 " currencyAcctID=\"%s\"\n"
332 " completedNoTrades=\"%d\"\n"
333 " transactionNum=\"%lld\"\n"
334 " creationDate=\"%" PRId64
"\"\n"
335 " validFrom=\"%" PRId64
"\"\n"
336 " validTo=\"%" PRId64
"\""
339 SERVER_ID.Get(), ASSET_TYPE_ID.Get(), ASSET_ACCT_ID.Get(),
340 CURRENCY_TYPE_ID.Get(), CURRENCY_ACCT_ID.
Get(), USER_ID.Get(),
357 "<closingTransactionNumber value=\"%lld\"/>\n\n", closingNumber);
360 if ((
'<' == stopSign_) || (
'>' == stopSign_)) {
362 " hasActivated=\"%s\"\n"
366 (stopActivated_ ?
"true" :
"false"),
367 stopSign_, stopPrice_);
370 if (marketOffer_.
Exists()) {
395 otErr <<
"While verifying offer, failed matching transaction number.\n";
399 otErr <<
"While verifying offer, failed matching Server ID.\n";
403 otErr <<
"While verifying offer, failed matching asset type ID.\n";
407 otErr <<
"While verifying offer, failed matching currency type ID.\n";
426 if (offer_ !=
nullptr) {
438 if (market !=
nullptr) {
446 if (pMarket !=
nullptr)
449 otErr <<
"OTTrade::" << __FUNCTION__
450 <<
": offer_ already exists, yet unable to find the "
451 "market it's supposed to be on.\n";
454 if (offerMarketId !=
nullptr) {
457 offerMarketId->
Assign(OFFER_MARKET_ID);
465 if (!marketOffer_.
Exists()) {
466 otErr <<
"OTTrade::GetOffer called with empty marketOffer_.\n";
477 otErr <<
"Error loading offer from string in OTTrade::GetOffer\n";
493 if (offerMarketId !=
nullptr) {
496 offerMarketId->
Assign(OFFER_MARKET_ID);
514 if (pMarket !=
nullptr) {
516 <<
"OTTrade::" << __FUNCTION__
517 <<
": Unable to find or create market within requested parameters.";
524 if (market !=
nullptr) {
557 if (marketOffer !=
nullptr) {
558 offer_ = marketOffer;
577 if (hasTradeActivated_) {
580 otErr <<
"How has the trade already activated, yet not on the "
581 "market and null in my pointer?\n";
583 else if (!pMarket->
AddOffer(
this, *offer,
true))
590 otErr <<
"Error adding the offer to the market! (Even though "
591 "supposedly the right market.)\n";
597 hasTradeActivated_ =
true;
637 int64_t relevantPrice = 0;
651 if (!pMarket->
AddOffer(
this, *offer,
true))
656 otErr <<
"Error adding the stop order to the market! (Even "
657 "though supposedly the right market.)\n";
663 stopActivated_ =
true;
664 hasTradeActivated_ =
true;
730 int64_t transactionNum = 0;
732 if (offer_ !=
nullptr) {
733 if (!marketOffer_.
Exists()) {
735 <<
"OTTrade::onRemovalFromCron called with nullptr offer_ and "
736 "empty marketOffer_.\n";
740 std::unique_ptr<OTOffer> offer(
new OTOffer());
746 if (!offer->LoadContractFromString(marketOffer_)) {
747 otErr <<
"Error loading offer from string in "
748 "OTTrade::onRemovalFromCron\n";
752 scale = offer->GetScale();
753 transactionNum = offer->GetTransactionNum();
765 if (market ==
nullptr) {
766 otErr <<
"Unable to find market within requested parameters in "
767 "OTTrade::onRemovalFromCron.\n";
778 if (marketOffer !=
nullptr) {
779 offer_ = marketOffer;
826 otLog5 <<
"OTTrade::CanRemoveItem: nym is not the originator of "
828 "(He could be a recipient though, so this is normal.)\n";
835 <<
"OTTrade::CanRemoveItem Weird: Sender tried to remove a market "
836 "trade; expected at "
837 "least 2 closing numbers to be available--that weren't. (Found "
845 otOut <<
"OTTrade::CanRemoveItemFromCron: Closing number didn't verify "
846 "for asset account.\n";
851 otOut <<
"OTTrade::CanRemoveItemFromCron: Closing number didn't verify "
852 "for currency account.\n";
893 const int64_t& newTransactionNumber,
896 const char* szFunc =
"OTTrade::onFinalReceipt";
915 const int64_t closingAssetNumber =
919 const int64_t closingCurrencyNumber =
965 OTString* attachment = &updatedCronItem;
971 note = &updatedOffer;
974 const OTString strOrigCronItem(origCronItem);
986 if ((openingNumber > 0) &&
994 idSet.erase(openingNumber);
1005 if ((serverNym !=
nullptr) && serverNym->
CompareID(actualNymId))
1006 actualNym = serverNym;
1007 else if (originator.
CompareID(actualNymId))
1008 actualNym = &originator;
1009 else if ((remover !=
nullptr) && remover->
CompareID(actualNymId))
1010 actualNym = remover;
1024 <<
": Failure loading public key for Nym : " << strNymID
1026 "(To update his NymboxHash.) \n";
1037 <<
": Loading actual Nym, since he wasn't already loaded. "
1038 "(To update his NymboxHash.)\n";
1039 actualNym = &theActualNym;
1045 <<
": Failure loading or verifying Actual Nym public key: "
1047 "(To update his NymboxHash.)\n";
1052 strOrigCronItem, note, attachment,
1054 otErr << szFunc <<
": Failure dropping receipt into nymbox.\n";
1058 otErr << szFunc <<
": Problem verifying Opening Number when calling "
1059 "VerifyIssuedNum(openingNumber)\n";
1064 if ((closingAssetNumber > 0) &&
1070 strOrigCronItem, note, attachment);
1074 <<
": Failed verifying "
1075 "closingAssetNumber=origCronItem."
1076 "GetClosingTransactionNoAt(0)>0 && "
1077 "originator.VerifyTransactionNum(closingAssetNumber)\n";
1082 if ((closingCurrencyNumber > 0) &&
1086 closingCurrencyNumber,
1088 strOrigCronItem, note, attachment);
1092 <<
": Failed verifying "
1093 "closingCurrencyNumber=origCronItem."
1094 "GetClosingTransactionNoAt(1)>0 "
1096 "originator.VerifyTransactionNum(closingCurrencyNumber)\n";
1181 bool bStayOnMarket =
1195 &OFFER_MARKET_ID, &market);
1199 if (offer ==
nullptr) {
1213 else if (market ==
nullptr) {
1224 bStayOnMarket =
false;
1239 return bStayOnMarket;
1265 if ((stopSign == 0) || (stopSign ==
'<') || (stopSign ==
'>'))
1266 stopSign_ = stopSign;
1268 otErr <<
"Bad data in Stop Sign while issuing trade: " << stopSign
1275 if ((stopSign_ ==
'<') || (stopSign_ ==
'>')) {
1276 if (0 >= stopPrice) {
1277 otErr <<
"Expected Stop Price for trade.\n";
1281 stopPrice_ = stopPrice;
1284 tradesAlreadyDone_ = 0;
1311 marketOffer_.
Set(strOffer);
1319 , hasTradeActivated_(false)
1322 , stopActivated_(false)
1323 , tradesAlreadyDone_(0)
1339 :
ot_super(serverId, assetId, assetAcctId, userId)
1341 , hasTradeActivated_(false)
1344 , stopActivated_(false)
1345 , tradesAlreadyDone_(0)
1398 tradesAlreadyDone_ = 0;
1402 stopActivated_ =
false;
1405 hasTradeActivated_ =
false;
OTMarket * GetOrCreateMarket(const OTIdentifier &ASSET_ID, const OTIdentifier &CURRENCY_ID, const int64_t &lScale)
bool AddOffer(OTTrade *pTrade, OTOffer &theOffer, bool bSaveFile=true, time64_t tDateAddedToMarket=OT_TIME_ZERO)
virtual bool SaveContractWallet(std::ofstream &ofs) const
OTOffer * GetOffer(const int64_t &lTransactionNum)
virtual bool VerifyNymAsAgent(OTPseudonym &nym, OTPseudonym &signerNym, mapOfNyms *preloadedMap=nullptr) const
const OTIdentifier & GetSenderUserID() const
time64_t GetValidTo() const
void SetValidFrom(time64_t TIME_FROM)
bool IsGreaterThan() const
virtual int64_t GetClosingNumber(const OTIdentifier &acctId) const
int64_t GetTransactionNum() const
const int64_t & GetScale() const
int64_t OTTimeGetTimeInterval(time64_t lhs, time64_t rhs)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
EXPORT bool SaveContract()
int64_t m_lTransactionNum
EXPORT bool VerifyIssuedNum(const OTString &strServerID, const int64_t &lTransNum) const
EXPORT int64_t ToLong() const
const OTIdentifier & GetAssetID() const
const OTIdentifier & GetCurrencyID() const
bool IsFlaggedForRemoval() const
OTLOG_IMPORT OTLogStream otOut
std::map< std::string, OTPseudonym * > mapOfNyms
OTLOG_IMPORT OTLogStream otLog3
int64_t GetLowestAskPrice()
const OTIdentifier & GetCurrencyAcctID() const
EXPORT bool SaveContractRaw(OTString &strOutput) const
const int64_t & GetStopPrice() const
void SetTrade(const OTTrade &theTrade)
void SetValidTo(time64_t TIME_TO)
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
void SetAssetID(const OTIdentifier &ASSET_ID)
EXPORT bool LoadSignedNymfile(OTPseudonym &SIGNER_NYM)
EXPORT bool IssueTrade(OTOffer &offer, char stopSign=0, int64_t stopPrice=0)
EXPORT void Concatenate(const char *arg,...)
EXPORT bool VerifyCurrentDate()
void SetCreationDate(const time64_t &CREATION_DATE)
virtual EXPORT ~OTTrade()
EXPORT int64_t GetClosingTransactionNoAt(uint32_t nIndex) const
EXPORT bool VerifyPseudonym() const
EXPORT void ReleaseSignatures()
EXPORT bool Exists() const
EXPORT void SetIdentifier(const OTIdentifier &theIdentifier)
EXPORT bool VerifyOffer(OTOffer &offer) const
const OTIdentifier & GetServerID() const
time64_t GetValidFrom() const
EXPORT bool LoadPublicKey()
bool DropFinalReceiptToInbox(const OTIdentifier &USER_ID, const OTIdentifier &ACCOUNT_ID, const int64_t &lNewTransactionNumber, const int64_t &lClosingNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTAccount *pActualAcct=nullptr)
virtual void onRemovalFromCron()
EXPORT int32_t GetCountClosingNumbers() const
virtual void onFinalReceipt(OTCronItem &origCronItem, const int64_t &newTransactionNumber, OTPseudonym &originator, OTPseudonym *remover)
EXPORT bool VerifyOwner(const OTPseudonym &candidate) const
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
time64_t OTTimeGetCurrentTime()
EXPORT void Assign(const OTData &source)
virtual bool ProcessCron()
virtual bool ProcessCron()
static EXPORT bool LoadEncodedTextField(irr::io::IrrXMLReader *&xml, OTASCIIArmor &ascOutput)
EXPORT bool RemoveIssuedNum(OTPseudonym &SIGNER_NYM, const OTString &strServerID, const int64_t &lTransNum, bool bSave)
void SetTransactionNum(int64_t lTransactionNum)
OTString m_strContractType
const int64_t & GetTransactionNum() const
OTLOG_IMPORT OTLogStream otInfo
void SetCurrencyAcctID(const OTIdentifier ¤cyAcctID)
EXPORT bool CompareID(const OTIdentifier &theIdentifier) const
const int64_t & GetProcessInterval() const
void SetSenderAcctID(const OTIdentifier &ACCT_ID)
const OTIdentifier & GetCurrencyID() const
OTStringXML m_xmlUnsigned
EXPORT int64_t GetOpeningNum() const
void SetCurrencyID(const OTIdentifier ¤cyId)
OTLOG_IMPORT OTLogStream otWarn
EXPORT const char * Get() const
virtual EXPORT bool SignContract(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr)
void SetServerID(const OTIdentifier &SERVER_ID)
OTLOG_IMPORT OTLogStream otErr
virtual bool CanRemoveItemFromCron(OTPseudonym &nym)
EXPORT int64_t GetCurrencyAcctClosingNum() const
void ProcessTrade(OTTrade &theTrade, OTOffer &theOffer, OTOffer &theOtherOffer)
EXPORT int64_t GetAssetAcctClosingNum() const
OTPseudonym * GetServerNym() const
int64_t GetHighestBidPrice()
virtual EXPORT bool VerifySignature(const OTPseudonym &theNym, const OTPasswordData *pPWData=nullptr) const
const OTIdentifier & GetSenderAcctID() const
const time64_t & GetLastProcessDate() const
std::set< int64_t > & GetSetOpenCronItems()
bool DropFinalReceiptToNymbox(const OTIdentifier &USER_ID, const int64_t &lNewTransactionNumber, const OTString &strOrigCronItem, OTString *pstrNote=nullptr, OTString *pstrAttachment=nullptr, OTPseudonym *pActualNym=nullptr)
void SetSenderUserID(const OTIdentifier &USER_ID)
int64_t OTTimeGetSecondsFromTime(time64_t time)
EXPORT bool LoadContractFromString(const OTString &theStr)
virtual bool VerifyNymAsAgentForAccount(OTPseudonym &nym, OTAccount &account) const
virtual EXPORT void Release()
EXPORT OTMarket * GetMarket(const OTIdentifier &MARKET_ID)
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
OTOffer * GetOffer(OTIdentifier *offerMarketId=nullptr, OTMarket **market=nullptr)
bool RemoveOffer(const int64_t &lTransactionNum)
virtual void UpdateContents()
virtual EXPORT void Release()
void SetProcessInterval(const int64_t &THE_DATE)
EXPORT bool SaveSignedNymfile(OTPseudonym &SIGNER_NYM)
const time64_t & GetCreationDate() const
OTLOG_IMPORT OTLogStream otLog5
void SetLastProcessDate(const time64_t &THE_DATE)