Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTOffer.hpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTOffer.hpp
4  *
5  */
6 
7 /************************************************************
8  -----BEGIN PGP SIGNED MESSAGE-----
9  Hash: SHA1
10 
11  * OPEN TRANSACTIONS
12  *
13  * Financial Cryptography and Digital Cash
14  * Library, Protocol, API, Server, CLI, GUI
15  *
16  * -- Anonymous Numbered Accounts.
17  * -- Untraceable Digital Cash.
18  * -- Triple-Signed Receipts.
19  * -- Cheques, Vouchers, Transfers, Inboxes.
20  * -- Basket Currencies, Markets, Payment Plans.
21  * -- Signed, XML, Ricardian-style Contracts.
22  * -- Scripted smart contracts.
23  *
24  * Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
25  *
26  * EMAIL:
28  *
29  * BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
30  *
31  * KEY FINGERPRINT (PGP Key in license file):
32  * 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
33  *
34  * OFFICIAL PROJECT WIKI(s):
35  * https://github.com/FellowTraveler/Moneychanger
36  * https://github.com/FellowTraveler/Open-Transactions/wiki
37  *
38  * WEBSITE:
39  * http://www.OpenTransactions.org/
40  *
41  * Components and licensing:
42  * -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
43  * -- otlib.........A class library.......LICENSE:...LAGPLv3
44  * -- otapi.........A client API..........LICENSE:...LAGPLv3
45  * -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
46  * -- otserver......Server Application....LICENSE:....AGPLv3
47  * Github.com/FellowTraveler/Open-Transactions/wiki/Components
48  *
49  * All of the above OT components were designed and written by
50  * Fellow Traveler, with the exception of Moneychanger, which
51  * was contracted out to Vicky C ([email protected]).
52  * The open-source community has since actively contributed.
53  *
54  * -----------------------------------------------------
55  *
56  * LICENSE:
57  * This program is free software: you can redistribute it
58  * and/or modify it under the terms of the GNU Affero
59  * General Public License as published by the Free Software
60  * Foundation, either version 3 of the License, or (at your
61  * option) any later version.
62  *
63  * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
64  * section 7: (This paragraph applies only to the LAGPLv3
65  * components listed above.) If you modify this Program, or
66  * any covered work, by linking or combining it with other
67  * code, such other code is not for that reason alone subject
68  * to any of the requirements of the GNU Affero GPL version 3.
69  * (==> This means if you are only using the OT API, then you
70  * don't have to open-source your code--only your changes to
71  * Open-Transactions itself must be open source. Similar to
72  * LGPLv3, except it applies to software-as-a-service, not
73  * just to distributing binaries.)
74  *
75  * Extra WAIVER for OpenSSL, Lucre, and all other libraries
76  * used by Open Transactions: This program is released under
77  * the AGPL with the additional exemption that compiling,
78  * linking, and/or using OpenSSL is allowed. The same is true
79  * for any other open source libraries included in this
80  * project: complete waiver from the AGPL is hereby granted to
81  * compile, link, and/or use them with Open-Transactions,
82  * according to their own terms, as long as the rest of the
83  * Open-Transactions terms remain respected, with regard to
84  * the Open-Transactions code itself.
85  *
86  * Lucre License:
87  * This code is also "dual-license", meaning that Ben Lau-
88  * rie's license must also be included and respected, since
89  * the code for Lucre is also included with Open Transactions.
90  * See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
91  * The Laurie requirements are light, but if there is any
92  * problem with his license, simply remove the Lucre code.
93  * Although there are no other blind token algorithms in Open
94  * Transactions (yet. credlib is coming), the other functions
95  * will continue to operate.
96  * See Lucre on Github: https://github.com/benlaurie/lucre
97  * -----------------------------------------------------
98  * You should have received a copy of the GNU Affero General
99  * Public License along with this program. If not, see:
100  * http://www.gnu.org/licenses/
101  *
102  * If you would like to use this software outside of the free
103  * software license, please contact FellowTraveler.
104  * (Unfortunately many will run anonymously and untraceably,
105  * so who could really stop them?)
106  *
107  * DISCLAIMER:
108  * This program is distributed in the hope that it will be
109  * useful, but WITHOUT ANY WARRANTY; without even the implied
110  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
111  * PURPOSE. See the GNU Affero General Public License for
112  * more details.
113 
114  -----BEGIN PGP SIGNATURE-----
115  Version: GnuPG v1.4.9 (Darwin)
116 
117  iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
118  vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
119  KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
120  aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
121  LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
122  sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
123  oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
124  TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
125  x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
126  nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
127  M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
128  kamH0Y/n11lCvo1oQxM+
129  =uSzz
130  -----END PGP SIGNATURE-----
131  **************************************************************/
132 
133 // Each instance of OTOffer represents a Bid or Ask. (A Market has a list of bid
134 // offers and a list of ask offers.)
135 
136 #ifndef OPENTXS_CORE_TRADE_OTOFFER_HPP
137 #define OPENTXS_CORE_TRADE_OTOFFER_HPP
138 
139 #include "../OTInstrument.hpp"
140 
141 namespace opentxs
142 {
143 
144 class OTTrade;
145 
146 /*
147  OTOffer
148 
149  Offer MUST STORE:
150 
151  X 1) Transaction ID (MUST be linked to a trade, so it can expire, and so it can
152  be paid for.)
153  X 2) ASSET TYPE ID of whatever I’m trying to BUY or SELL. (Is this the Gold
154  market?)
155  X 7) CURRENCY TYPE ID of whatever I’m trying to buy or sell it WITH. (Is it
156  dollars? Euro? Yen?)
157  X 8) BUY OR SELL? (BOOL)
158  X 9) Bid/Ask price (limit / per minimum increment.)
159 
160  X 4) Total number of assets available for sale or purchase. (4 ounces of gold?
161  12 ounces of gold?)
162  X 5) Number of assets already traded, against the above total.
163  X 6) Minimum increment for sale or purchase (if matches “total number of assets
164  for sale”, effectively becomes a FILL OR KILL order. MUST be 1 or greater.
165  CANNOT be zero.)
166 */
167 class OTOffer : public OTInstrument
168 {
169 private: // Private prevents erroneous use by other classes.
170  typedef OTInstrument ot_super;
171 
172  // From OTInstrument (parent class of this)
173  /*
174 public:
175  inline time64_t GetValidFrom() const { return m_VALID_FROM; }
176  inline time64_t GetValidTo() const { return m_VALID_TO; }
177 
178  inline void SetValidFrom(time64_t TIME_FROM) { m_VALID_FROM =
179 TIME_FROM; }
180  inline void SetValidTo(time64_t TIME_TO) { m_VALID_TO = TIME_TO;
181 }
182 
183 
184  inline const OTIdentifier& GetAssetID() const { return m_AssetTypeID; }
185  inline const OTIdentifier& GetServerID() const { return m_ServerID; }
186 
187  inline void SetAssetID(const OTIdentifier& ASSET_ID) { m_AssetTypeID =
188 ASSET_ID; }
189  inline void SetServerID(const OTIdentifier& SERVER_ID) { m_ServerID =
190 SERVER_ID; }
191 
192  bool VerifyCurrentDate(); // Verify the current date against the VALID FROM
193 / TO dates.
194  */
195  time64_t m_tDateAddedToMarket;
196 
197 protected:
198  OTTrade* m_pTrade; // If this offer is actually connected to a trade, it
199  // will have a pointer.
200 
201  OTIdentifier m_CURRENCY_TYPE_ID; // GOLD (Asset) is trading for DOLLARS
202  // (Currency).
203  bool m_bSelling; // true = ask. false = bid.
204  // If a bid, this is the most I will pay. If an ask, this is the least I
205  // will sell for. My limit.
206  // (Normally the price I get is whatever is the best one on the market right
207  // now.)
208  int64_t m_lPriceLimit; // Denominated in CURRENCY TYPE, and priced per
209  // SCALE.
210  // 1oz market price limit might be 1,300
211  // 100oz market price limit might be 130,000 (or 127,987 or whatever)
212 
213  int64_t m_lTransactionNum; // Matches to an OTTrade stored in OTCron.
214  int64_t m_lTotalAssetsOffer; // Total amount of ASSET TYPE trying to BUY or
215  // SELL, this trade.
216  int64_t m_lFinishedSoFar; // Number of ASSETs bought or sold already against
217  // the above total.
218 
219  int64_t m_lScale; // 1oz market? 100oz market? 10,000oz market? This
220  // determines size and granularity.
221  int64_t m_lMinimumIncrement; // Each sale or purchase against the above
222  // total must be in minimum increments.
223  // Minimum Increment must be evenly divisible by m_lScale.
224  // (This effectively becomes a "FILL OR KILL" order if set to the same value
225  // as m_lTotalAssetsOffer. Also, MUST be 1
226  // or great. CANNOT be zero. Enforce this at class level. You cannot sell
227  // something in minimum increments of 0.)
228  inline void SetTransactionNum(const int64_t& lTransactionNum)
229  {
230  m_lTransactionNum = lTransactionNum;
231  }
232  inline void SetPriceLimit(const int64_t& lPriceLimit)
233  {
234  m_lPriceLimit = lPriceLimit;
235  }
236  inline void SetTotalAssetsOnOffer(const int64_t& lTotalAssets)
237  {
238  m_lTotalAssetsOffer = lTotalAssets;
239  }
240  inline void SetFinishedSoFar(const int64_t& lFinishedSoFar)
241  {
242  m_lFinishedSoFar = lFinishedSoFar;
243  }
244  inline void SetMinimumIncrement(const int64_t& lMinIncrement)
245  {
246  m_lMinimumIncrement = lMinIncrement;
248  }
249  inline void SetScale(const int64_t& lScale)
250  {
251  m_lScale = lScale;
252  if (m_lScale < 1) m_lScale = 1;
253  }
254 
255 public:
256  EXPORT bool MakeOffer(
257  bool bBuyingOrSelling, // True == SELLING, False == BUYING
258  const int64_t& lPriceLimit, // Per Scale...
259  const int64_t& lTotalAssetsOffer, // Total assets available for sale or
260  // purchase.
261  const int64_t& lMinimumIncrement, // The minimum increment that must be
262  // bought or sold for each transaction
263  const int64_t& lTransactionNum, // The transaction number authorizing
264  // this trade.
265  const time64_t& VALID_FROM = OT_TIME_ZERO, // defaults to RIGHT NOW
266  const time64_t& VALID_TO = OT_TIME_ZERO); // defaults to 24 hours (a
267  // "Day Order")
268  inline void IncrementFinishedSoFar(const int64_t& lFinishedSoFar)
269  {
270  m_lFinishedSoFar += lFinishedSoFar;
271  }
272 
273  inline int64_t GetAmountAvailable() const
274  {
276  }
277  inline const int64_t& GetTransactionNum() const
278  {
279  return m_lTransactionNum;
280  }
281 
282  inline const int64_t& GetPriceLimit() const
283  {
284  return m_lPriceLimit;
285  }
286  inline const int64_t& GetTotalAssetsOnOffer() const
287  {
288  return m_lTotalAssetsOffer;
289  }
290  inline const int64_t& GetFinishedSoFar() const
291  {
292  return m_lFinishedSoFar;
293  }
294  inline const int64_t& GetMinimumIncrement()
295  {
297  return m_lMinimumIncrement;
298  }
299  inline const int64_t& GetScale() const
300  {
301  return m_lScale;
302  }
303 
304  inline const OTIdentifier& GetCurrencyID() const
305  {
306  return m_CURRENCY_TYPE_ID;
307  }
308  inline void SetCurrencyID(const OTIdentifier& CURRENCY_ID)
309  {
310  m_CURRENCY_TYPE_ID = CURRENCY_ID;
311  }
312 
313  // Buying or selling?
314  inline bool IsBid()
315  {
316  return !m_bSelling;
317  }
318  inline bool IsAsk()
319  {
320  return m_bSelling;
321  }
322 
323  bool IsMarketOrder() const;
324  bool IsLimitOrder() const;
325 
326  // Stores a pointer to theTrade for later use. (Not responsible to clean up,
327  // just convenient.)
328  inline OTTrade* GetTrade()
329  {
330  return m_pTrade;
331  }
332  inline void SetTrade(const OTTrade& theTrade)
333  {
334  m_pTrade = &((OTTrade&)theTrade);
335  }
336  // Note: m_tDateAddedToMarket is not saved in the Offer Contract, but
337  // OTMarket sets/saves/loads it.
338  //
339  EXPORT time64_t GetDateAddedToMarket() const; // Used in
340  // OTMarket::GetOfferList and
341  // GetNymOfferList.
342  EXPORT void SetDateAddedToMarket(time64_t tDate); // Used in OTCron when
343  // adding/loading offers.
344  EXPORT OTOffer(); // The constructor contains the 3 variables needed to
345  // identify any market.
346  EXPORT OTOffer(const OTIdentifier& SERVER_ID, const OTIdentifier& ASSET_ID,
347  const OTIdentifier& CURRENCY_ID,
348  const int64_t& MARKET_SCALE);
349  EXPORT virtual ~OTOffer();
350 
351  // Overridden from OTContract.
352  virtual void GetIdentifier(OTIdentifier& theIdentifier) const;
353 
354  void InitOffer();
355 
356  virtual void Release();
357  void Release_Offer();
358 
359  // return -1 if error, 0 if nothing, and 1 if the node was processed.
360  virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader*& xml);
361 
362  virtual void UpdateContents(); // Before transmission or serialization, this
363  // is where the ledger saves its contents
364 
365  virtual bool SaveContractWallet(std::ofstream& ofs) const;
366 };
367 
368 } // namespace opentxs
369 
370 #endif // OPENTXS_CORE_TRADE_OTOFFER_HPP
int64_t m_lFinishedSoFar
Definition: OTOffer.hpp:216
void SetFinishedSoFar(const int64_t &lFinishedSoFar)
Definition: OTOffer.hpp:240
const int64_t & GetMinimumIncrement()
Definition: OTOffer.hpp:294
virtual int32_t ProcessXMLNode(irr::io::IrrXMLReader *&xml)
Definition: OTOffer.cpp:231
EXPORT time64_t GetDateAddedToMarket() const
Definition: OTOffer.cpp:498
int64_t GetAmountAvailable() const
Definition: OTOffer.hpp:273
int64_t m_lTransactionNum
Definition: OTOffer.hpp:213
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)
Definition: OTOffer.cpp:434
bool IsMarketOrder() const
Definition: OTOffer.cpp:220
const int64_t & GetScale() const
Definition: OTOffer.hpp:299
void InitOffer()
Definition: OTOffer.cpp:574
bool IsLimitOrder() const
Definition: OTOffer.cpp:225
OTTrade * m_pTrade
Definition: OTOffer.hpp:198
const OTIdentifier & GetCurrencyID() const
Definition: OTOffer.hpp:304
virtual void UpdateContents()
Definition: OTOffer.cpp:391
void SetTransactionNum(const int64_t &lTransactionNum)
Definition: OTOffer.hpp:228
virtual void Release()
Definition: OTOffer.cpp:562
void SetCurrencyID(const OTIdentifier &CURRENCY_ID)
Definition: OTOffer.hpp:308
void SetTrade(const OTTrade &theTrade)
Definition: OTOffer.hpp:332
OTTrade * GetTrade()
Definition: OTOffer.hpp:328
int64_t time64_t
Definition: Common.hpp:209
virtual void GetIdentifier(OTIdentifier &theIdentifier) const
Definition: OTOffer.cpp:206
const int64_t & GetTotalAssetsOnOffer() const
Definition: OTOffer.hpp:286
const int64_t & GetFinishedSoFar() const
Definition: OTOffer.hpp:290
void Release_Offer()
Definition: OTOffer.cpp:556
EXPORT void SetDateAddedToMarket(time64_t tDate)
Definition: OTOffer.cpp:504
const int64_t & GetTransactionNum() const
Definition: OTOffer.hpp:277
virtual bool SaveContractWallet(std::ofstream &ofs) const
Definition: OTOffer.cpp:600
void SetScale(const int64_t &lScale)
Definition: OTOffer.hpp:249
int64_t m_lTotalAssetsOffer
Definition: OTOffer.hpp:214
int64_t m_lScale
Definition: OTOffer.hpp:219
void SetTotalAssetsOnOffer(const int64_t &lTotalAssets)
Definition: OTOffer.hpp:236
void SetMinimumIncrement(const int64_t &lMinIncrement)
Definition: OTOffer.hpp:244
void SetPriceLimit(const int64_t &lPriceLimit)
Definition: OTOffer.hpp:232
OTIdentifier m_CURRENCY_TYPE_ID
Definition: OTOffer.hpp:201
int64_t m_lPriceLimit
Definition: OTOffer.hpp:208
virtual EXPORT ~OTOffer()
Definition: OTOffer.cpp:551
#define OT_TIME_ZERO
Definition: Common.hpp:180
EXPORT OTOffer()
Definition: OTOffer.cpp:510
void IncrementFinishedSoFar(const int64_t &lFinishedSoFar)
Definition: OTOffer.hpp:268
int64_t m_lMinimumIncrement
Definition: OTOffer.hpp:221
const int64_t & GetPriceLimit() const
Definition: OTOffer.hpp:282