138 #include <irrxml/irrXML.hpp>
151 if (1 == x)
return true;
153 const int64_t lBase = 10;
156 for (int32_t i = 1; i < 23; i++) {
157 if (x == lIt)
return true;
214 strTemp.
Format(
"ASSET TYPE:\n%s\nCURRENCY TYPE:\n%s\nMARKET SCALE:\n%lld\n",
215 strAsset.Get(), strCurrency.
Get(), lScale);
233 int32_t nReturnVal = 0;
246 if (!strcmp(
"marketOffer", xml->getNodeName())) {
250 strIsSelling = xml->getAttributeValue(
"isSelling");
251 if (strIsSelling.
Compare(
"true"))
258 const OTString strServerID(xml->getAttributeValue(
"serverID")),
259 strAssetTypeID(xml->getAttributeValue(
"assetTypeID")),
260 strCurrencyTypeID(xml->getAttributeValue(
"currencyTypeID"));
262 const OTIdentifier SERVER_ID(strServerID), ASSET_ID(strAssetTypeID),
263 CURRENCY_TYPE_ID(strCurrencyTypeID);
269 const OTString strScale = xml->getAttributeValue(
"marketScale");
270 const int64_t lScale = strScale.
Exists() ? atol(strScale.
Get())
276 otOut <<
"OTOffer::ProcessXMLNode: Failure: marketScale *must* be "
277 "1, or a power of 10. Instead I got: " << lScale <<
".\n";
283 const OTString strPriceLimit = xml->getAttributeValue(
"priceLimit");
284 const int64_t lPriceLimit = strPriceLimit.
Exists()
285 ? atol(strPriceLimit.
Get())
291 if (!strPriceLimit.
Exists())
294 otOut <<
"OTOffer::ProcessXMLNode: Failure: priceLimit *must* be "
295 "provided(" << lPriceLimit <<
").\n";
301 const OTString strTotal = xml->getAttributeValue(
"totalAssetsOnOffer");
302 const int64_t lTotal = strTotal.
Exists() ? atol(strTotal.
Get())
307 otOut <<
"OTOffer::ProcessXMLNode: Failure: totalAssetsOnOffer "
308 "*must* be larger than 0. Instead I got: " << lTotal
315 const OTString strFinished = xml->getAttributeValue(
"finishedSoFar");
316 const int64_t lFinished = strFinished.
Exists()
317 ? atol(strFinished.
Get())
321 otOut <<
"OTOffer::ProcessXMLNode: Failure: finishedSoFar *must* "
322 "be 0 or larger. Instead I got: " << lFinished <<
".\n";
328 const OTString strMinInc = xml->getAttributeValue(
"minimumIncrement");
329 const int64_t lMinInc = strMinInc.
Exists() ? atol(strMinInc.
Get())
333 if ((lMinInc < 1) || (lMinInc > lTotal))
337 otOut <<
"OTOffer::ProcessXMLNode: Failure: minimumIncrement "
338 "*must* be 1 or larger, \n"
339 "and must also be less than the total assets on offer. "
340 "Instead I got: " << lMinInc <<
".\n";
346 const OTString strTransNum = xml->getAttributeValue(
"transactionNum");
347 const int64_t lTransNum =
348 strTransNum.
Exists() ? atol(strTransNum.
Get()) : 0;
352 const OTString str_valid_from = xml->getAttributeValue(
"validFrom");
353 const OTString str_valid_to = xml->getAttributeValue(
"validTo");
357 int64_t tValidTo = str_valid_to.
Exists() ? str_valid_to.
ToLong() : 0;
359 if ((tValidTo < tValidFrom) && (tValidTo != 0)) {
360 otOut <<
"OTOffer::" << __FUNCTION__ <<
": Failure: validTo date ("
361 << tValidFrom <<
") cannot be earlier than "
362 "validFrom date (" << tValidTo <<
").\n";
370 <<
"\n Valid From: " << tValidFrom <<
"\n Valid To: " << tValidTo
372 " AssetTypeID: " << strAssetTypeID
373 <<
"\n CurrencyTypeID: " << strCurrencyTypeID
374 <<
"\n ServerID: " << strServerID
382 <<
". This offer is a" << (
m_bSelling ?
"n ASK" :
" BID")
411 "<marketOffer\n version=\"%s\"\n"
412 " isSelling=\"%s\"\n"
414 " assetTypeID=\"%s\"\n"
415 " currencyTypeID=\"%s\"\n"
416 " priceLimit=\"%lld\"\n"
417 " totalAssetsOnOffer=\"%lld\"\n"
418 " finishedSoFar=\"%lld\"\n"
419 " marketScale=\"%lld\"\n"
420 " minimumIncrement=\"%lld\"\n"
421 " transactionNum=\"%lld\"\n"
422 " validFrom=\"%" PRId64
"\"\n"
423 " validTo=\"%" PRId64
"\""
426 (
IsBid() ?
"false" :
"true"), SERVER_ID.Get(), ASSET_TYPE_ID.Get(),
427 CURRENCY_TYPE_ID.
Get(), lPriceLimit, lTotalAssetsOnOffer,
428 lFinishedSoFar, lScale, lMinimumIncrement, lTransactionNum, lFrom, lTo);
435 bool bBuyingOrSelling,
436 const int64_t& lPriceLimit,
438 const int64_t& lTotalAssetsOffer,
440 const int64_t& lMinimumIncrement,
442 const int64_t& lTransactionNum,
456 int64_t lRealMinInc = lMinimumIncrement;
457 if (lMinimumIncrement > lTotalAssetsOffer)
460 lRealMinInc = lTotalAssetsOffer;
474 time64_t REAL_VALID_FROM = VALID_FROM;
501 return m_tDateAddedToMarket;
507 m_tDateAddedToMarket = tDate;
517 , m_lTransactionNum(0)
518 , m_lTotalAssetsOffer(0)
519 , m_lFinishedSoFar(0)
536 , m_lTransactionNum(0)
537 , m_lTotalAssetsOffer(0)
538 , m_lFinishedSoFar(0)
void SetFinishedSoFar(const int64_t &lFinishedSoFar)
const int64_t & GetMinimumIncrement()
OTLOG_IMPORT OTLogStream otLog4
virtual EXPORT void Release()
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
EXPORT time64_t GetDateAddedToMarket() const
EXPORT bool CalculateDigest(const OTData &dataInput)
int64_t m_lTransactionNum
EXPORT bool MakeOffer(bool bBuyingOrSelling, const int64_t &lPriceLimit, const int64_t &lTotalAssetsOffer, const int64_t &lMinimumIncrement, const int64_t &lTransactionNum, const time64_t &VALID_FROM=OT_TIME_ZERO, const time64_t &VALID_TO=OT_TIME_ZERO)
time64_t GetValidTo() const
bool IsMarketOrder() const
void SetValidFrom(time64_t TIME_FROM)
const int64_t & GetScale() const
time64_t OTTimeAddTimeInterval(time64_t lhs, int64_t rhs)
EXPORT int64_t ToLong() const
const OTIdentifier & GetAssetID() const
bool IsLimitOrder() const
const OTIdentifier & GetCurrencyID() const
virtual void UpdateContents()
OTLOG_IMPORT OTLogStream otOut
void SetTransactionNum(const int64_t &lTransactionNum)
void SetCurrencyID(const OTIdentifier &CURRENCY_ID)
void SetValidTo(time64_t TIME_TO)
time64_t OTTimeGetTimeFromSeconds(int64_t seconds)
void SetAssetID(const OTIdentifier &ASSET_ID)
EXPORT void Concatenate(const char *arg,...)
EXPORT bool Exists() const
virtual void GetIdentifier(OTIdentifier &theIdentifier) const
const int64_t & GetTotalAssetsOnOffer() const
const OTIdentifier & GetServerID() const
EXPORT void Format(const char *fmt,...)
#define OT_TIME_DAY_IN_SECONDS
time64_t GetValidFrom() const
EXPORT bool Compare(const char *compare) const
const int64_t & GetFinishedSoFar() const
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
time64_t OTTimeGetCurrentTime()
EXPORT void SetDateAddedToMarket(time64_t tDate)
OTString m_strContractType
const int64_t & GetTransactionNum() const
bool isPowerOfTen(const int64_t &x)
virtual bool SaveContractWallet(std::ofstream &ofs) const
void SetScale(const int64_t &lScale)
OTStringXML m_xmlUnsigned
EXPORT const char * Get() const
int64_t m_lTotalAssetsOffer
void SetServerID(const OTIdentifier &SERVER_ID)
void SetTotalAssetsOnOffer(const int64_t &lTotalAssets)
void SetMinimumIncrement(const int64_t &lMinIncrement)
void SetPriceLimit(const int64_t &lPriceLimit)
OTIdentifier m_CURRENCY_TYPE_ID
virtual EXPORT ~OTOffer()
int64_t OTTimeGetSecondsFromTime(time64_t time)
virtual EXPORT void Release()
virtual EXPORT void Release()
int64_t m_lMinimumIncrement
const int64_t & GetPriceLimit() const