Skip to content

Commit

Permalink
Markets updates, including stop and market orders.
Browse files Browse the repository at this point in the history
Signed-off-by: FellowTraveler <F3llowTraveler@gmail.com>
  • Loading branch information
FellowTraveler committed Nov 24, 2013
1 parent 09003be commit 019e871
Show file tree
Hide file tree
Showing 81 changed files with 8,396 additions and 1,504 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.90.a
0.90.b
26 changes: 12 additions & 14 deletions include/otapi/OTAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -3518,20 +3518,18 @@ public :
// ...and in fact the requestNum IS the return value!
// ===> In 99% of cases, this LAST option is what actually happens!!
*/
EXPORT static int32_t issueMarketOffer(
const std::string & SERVER_ID,
const std::string & USER_ID,
// -------------------------------------------
const std::string & ASSET_ACCT_ID, // Perhaps this is the wheat market.
const std::string & CURRENCY_ACCT_ID, // Perhaps I'm buying the wheat with rubles.
// -------------------------------------------
const int64_t & MARKET_SCALE, // Defaults to minimum of 1. Market granularity.
const int64_t & MINIMUM_INCREMENT, // This will be multiplied by the Scale. Min 1.
const int64_t & TOTAL_ASSETS_ON_OFFER, // Total assets available for sale or purchase. Will be multiplied by minimum increment.
const int64_t & PRICE_LIMIT, // Per Minimum Increment...
const bool & bBuyingOrSelling, // Actually OT_BOOL. SELLING == OT_TRUE, BUYING == OT_FALSE.
const time_t & LIFESPAN_IN_SECONDS // Pass 0 for the default behavior: 86400 seconds aka 1 day.
);
EXPORT static int32_t issueMarketOffer(const std::string & ASSET_ACCT_ID, // Perhaps this is the wheat market.
const std::string & CURRENCY_ACCT_ID, // Perhaps I'm buying the wheat with rubles.
// -------------------------------------------
const int64_t & MARKET_SCALE, // Defaults to minimum of 1. Market granularity.
const int64_t & MINIMUM_INCREMENT, // This will be multiplied by the Scale. Min 1.
const int64_t & TOTAL_ASSETS_ON_OFFER, // Total assets available for sale or purchase. Will be multiplied by minimum increment.
const int64_t & PRICE_LIMIT, // Per Minimum Increment...
const bool & bBuyingOrSelling, // SELLING == true, BUYING == false.
const time_t & LIFESPAN_IN_SECONDS, // Pass 0 for the default behavior: 86400 seconds aka 1 day.
// -------------------------------------------
const std::string & STOP_SIGN, // Must be "" (for market/limit orders) or "<" or ">" (for stop orders.)
const int64_t & ACTIVATION_PRICE); // Must be provided if STOP_SIGN is also set. Determines the price threshold for stop orders.


// --------------------------------------------------
Expand Down
21 changes: 10 additions & 11 deletions include/otapi/OTAPI_Basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -3405,19 +3405,18 @@ class OTAPI_Basic
// ===> In 99% of cases, this LAST option is what actually happens!!
//
EXPORT static long issueMarketOffer(
const std::string & SERVER_ID,
const std::string & USER_ID,
// -------------------------------------------
const std::string & ASSET_ACCT_ID, // Perhaps this is the wheat market.
// -------------------------------------------
const std::string & CURRENCY_ACCT_ID, // Perhaps I'm buying the wheat with rubles.
const std::string & ASSET_ACCT_ID, // Perhaps this is the wheat market.
const std::string & CURRENCY_ACCT_ID, // Perhaps I'm buying the wheat with rubles.
// -------------------------------------------
const std::string & MARKET_SCALE, // Defaults to minimum of 1. Market granularity.
const std::string & MINIMUM_INCREMENT, // This will be multiplied by the Scale. Min 1.
const std::string & MARKET_SCALE, // Defaults to minimum of 1. Market granularity.
const std::string & MINIMUM_INCREMENT, // This will be multiplied by the Scale. Min 1.
const std::string & TOTAL_ASSETS_ON_OFFER, // Total assets available for sale or purchase. Will be multiplied by minimum increment.
const std::string & PRICE_LIMIT, // Per Minimum Increment...
const bool & bBuyingOrSelling, // SELLING == true, BUYING == false.
const std::string & LIFESPAN_IN_SECONDS // if string is empty "", or "0", default is 86400 seconds == 1 day.
const std::string & PRICE_LIMIT, // Per Minimum Increment...
const bool & bBuyingOrSelling, // SELLING == true, BUYING == false.
const std::string & LIFESPAN_IN_SECONDS, // if string is empty "", or "0", default is 86400 seconds == 1 day.
// -------------------------------------------
const std::string & STOP_SIGN, // Must be "" (for market/limit orders) or "<" or ">" (for stop orders.)
const std::string & ACTIVATION_PRICE // Must be provided if STOP_SIGN is also set. Determines the price threshold for stop orders.
);


Expand Down
8 changes: 4 additions & 4 deletions include/otapi/OTMadeEasy.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,16 @@ class OTMadeEasy
EXPORT std::string query_asset_types(const std::string & SERVER_ID,
const std::string & NYM_ID,
const std::string & ENCODED_MAP);
EXPORT std::string create_market_offer(const std::string & SERVER_ID,
const std::string & NYM_ID,
const std::string & ASSET_ACCT_ID,
EXPORT std::string create_market_offer(const std::string & ASSET_ACCT_ID,
const std::string & CURRENCY_ACCT_ID,
const std::string & scale,
const std::string & minIncrement,
const std::string & quantity,
const std::string & price,
const bool bSelling,
const std::string & LIFESPAN_IN_SECONDS);
const std::string & LIFESPAN_IN_SECONDS,
const std::string & STOP_SIGN,
const std::string & ACTIVATION_PRICE);
EXPORT std::string kill_market_offer(const std::string & SERVER_ID,
const std::string & NYM_ID,
const std::string & ASSET_ACCT_ID,
Expand Down
8 changes: 4 additions & 4 deletions include/otapi/OT_ME.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,16 @@ class OT_ME
EXPORT std::string query_asset_types(const std::string & SERVER_ID,
const std::string & NYM_ID,
const std::string & ENCODED_MAP);
EXPORT std::string create_market_offer(const std::string & SERVER_ID,
const std::string & NYM_ID,
const std::string & ASSET_ACCT_ID,
EXPORT std::string create_market_offer(const std::string & ASSET_ACCT_ID,
const std::string & CURRENCY_ACCT_ID,
const int64_t scale,
const int64_t minIncrement,
const int64_t quantity,
const int64_t price,
const bool bSelling,
const int64_t lLifespanInSeconds); // 0 does default of 86400 == 1 day.
const int64_t lLifespanInSeconds, // 0 does default of 86400 == 1 day.
const std::string STOP_SIGN, // If a stop order, must be "<" or ">"
const int64_t ACTIVATION_PRICE); // If a stop order, must be non-zero.
EXPORT std::string kill_market_offer(const std::string & SERVER_ID,
const std::string & NYM_ID,
const std::string & ASSET_ACCT_ID,
Expand Down
9 changes: 6 additions & 3 deletions include/otapi/OpenTransactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,6 @@ EXPORT OTServerContract * LoadServerContract(const OTIdentifier & SERVER_ID);
const OTString & THE_PAYMENT_PLAN);

// ------------------------------------------------------------------------

EXPORT int issueMarketOffer(const OTIdentifier & SERVER_ID,
const OTIdentifier & USER_ID,
// -------------------------------------------
Expand All @@ -1226,8 +1225,12 @@ EXPORT OTServerContract * LoadServerContract(const OTIdentifier & SERVER_ID);
const long & PRICE_LIMIT, // Per Minimum Increment...
const bool bBuyingOrSelling, // BUYING == false, SELLING == true.
// -------------------------------------------
const time_t tLifespanInSeconds=86400); // 86400 seconds == 1 day.

const time_t tLifespanInSeconds=86400, // 86400 seconds == 1 day.
// -------------------------------------------
const char STOP_SIGN=0, // For stop orders, set to '<' or '>'
const long ACTIVATION_PRICE=0); // For stop orders, set the threshold price here.
// ------------------------------------------------------------------------

EXPORT int getMarketList(const OTIdentifier & SERVER_ID, const OTIdentifier & USER_ID);
EXPORT int getMarketOffers(const OTIdentifier & SERVER_ID, const OTIdentifier & USER_ID,
const OTIdentifier & MARKET_ID, const long & lDepth);
Expand Down
6 changes: 3 additions & 3 deletions include/otlib/OTBylaw.h
Original file line number Diff line number Diff line change
Expand Up @@ -1000,11 +1000,11 @@ class OTBylaw
// ---------------------
EXPORT bool AddVariable(OTVariable& theVariable);
EXPORT bool AddVariable(const std::string str_Name, const std::string str_Value,
const OTVariable::OTVariable_Access theAccess=OTVariable::Var_Persistent);
const OTVariable::OTVariable_Access theAccess=OTVariable::Var_Persistent);
EXPORT bool AddVariable(const std::string str_Name, const int nValue,
const OTVariable::OTVariable_Access theAccess=OTVariable::Var_Persistent);
const OTVariable::OTVariable_Access theAccess=OTVariable::Var_Persistent);
EXPORT bool AddVariable(const std::string str_Name, const bool bValue,
const OTVariable::OTVariable_Access theAccess=OTVariable::Var_Persistent);
const OTVariable::OTVariable_Access theAccess=OTVariable::Var_Persistent);
// ---------------------
EXPORT bool AddClause(OTClause& theClause);
EXPORT bool AddClause(const char * szName, const char * szCode);
Expand Down
86 changes: 50 additions & 36 deletions include/otlib/OTCron.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
#endif
#include <ExportWrapper.h>

#include <ctime>

#include <map>
#include <list>

Expand All @@ -154,18 +156,22 @@ class OTPseudonym;
class OTMarket;


// ------------------------------------------------------------------
// mapOfCronItems: Mapped (uniquely) to transaction number.
// multimapOfCronItems: Mapped to date the item was added to Cron.
//
// (Any given CronItem will be found on BOTH lists.)

// Mapped (uniquely) to transaction number.
typedef std::map <long, OTCronItem *> mapOfCronItems;

typedef std::map <long, OTCronItem *> mapOfCronItems;
typedef std::multimap <time_t, OTCronItem *> multimapOfCronItems;
// ------------------------------------------------------------------
// Mapped (uniquely) to market ID.
typedef std::map <std::string, OTMarket *> mapOfMarkets;


// Cron stores a bunch of these on this list,
// ------------------------------------------------------------------
// Cron stores a bunch of these on this list,
// which the server refreshes from time to time.
typedef std::list<long> listOfLongNumbers;

// ------------------------------------------------------------------


class OTCron : public OTContract
Expand All @@ -175,50 +181,58 @@ class OTCron : public OTContract

private:
mapOfMarkets m_mapMarkets; // A list of all valid markets.
mapOfCronItems m_mapCronItems;
// ---------------------------------------
mapOfCronItems m_mapCronItems; // Cron Items are found on both lists.
multimapOfCronItems m_multimapCronItems;
// ---------------------------------------
OTIdentifier m_SERVER_ID; // Always store this in any object that's associated with a specific server.

OTPseudonym * m_pServerNym; // I'll need this for later.

listOfLongNumbers m_listTransactionNumbers; // I can't put receipts in people's inboxes without a supply of these.

bool m_bIsActivated; // I don't want to start Cron processing until everything else is all loaded up and ready to go.

// ---------------------------------------
static int __trans_refill_amount; // The number of transaction numbers Cron will grab for itself, when it gets low, before each round.
static int __cron_ms_between_process; // The number of milliseconds (ideally) between each "Cron Process" event.
static int __trans_refill_amount; // Number of transaction numbers Cron will grab for itself, when it gets low, before each round.
static int __cron_ms_between_process; // Number of milliseconds (ideally) between each "Cron Process" event.

static int __cron_max_items_per_nym; // Int. The maximum number of cron items any given Nym can have active at the same time.
static int __cron_max_items_per_nym; // Int. The maximum number of cron items any given Nym can have active at the same time.

public:
static int GetCronMsBetweenProcess() { return __cron_ms_between_process; }
static void SetCronMsBetweenProcess(long lMS) { __cron_ms_between_process = lMS; }

static int GetCronRefillAmount() { return __trans_refill_amount; }
static void SetCronRefillAmount(int nAmount) { __trans_refill_amount = nAmount; }
// ---------------------------------------
static int GetCronMaxItemsPerNym() { return __cron_max_items_per_nym; }
static void SetCronMaxItemsPerNym(int nMax) { __cron_max_items_per_nym = nMax; }
// ---------------------------------------

inline bool IsActivated() const { return m_bIsActivated; }
inline bool ActivateCron() { if (!m_bIsActivated) return m_bIsActivated = true; else return false; }

static int GetCronMsBetweenProcess() { return __cron_ms_between_process; }
static void SetCronMsBetweenProcess(long lMS) { __cron_ms_between_process = lMS; }

static int GetCronRefillAmount() { return __trans_refill_amount; }
static void SetCronRefillAmount(int nAmount) { __trans_refill_amount = nAmount; }
// ---------------------------------------
static int GetCronMaxItemsPerNym() { return __cron_max_items_per_nym; }
static void SetCronMaxItemsPerNym(int nMax) { __cron_max_items_per_nym = nMax; }
// ---------------------------------------
inline bool IsActivated() const { return m_bIsActivated; }
inline bool ActivateCron() { if (!m_bIsActivated) return m_bIsActivated = true; else return false; }
// ---------------------------------------
// RECURRING TRANSACTIONS
//
EXPORT bool AddCronItem(OTCronItem & theItem, OTPseudonym * pActivator=NULL, bool bSaveReceipt=true);
EXPORT bool RemoveCronItem(long lTransactionNum, OTPseudonym & theRemover); // if returns false, CronItem wasn't found.
EXPORT bool AddCronItem(OTCronItem & theItem,
OTPseudonym * pActivator,
bool bSaveReceipt,
time_t tDateAdded); // Date it was FIRST added to Cron.
EXPORT bool RemoveCronItem(long lTransactionNum, OTPseudonym & theRemover); // if returns false, item wasn't found.
// ---------------------------------------
EXPORT OTCronItem * GetCronItem(long lTransactionNum);
EXPORT OTCronItem * GetItemByOfficialNum (long lTransactionNum);
EXPORT OTCronItem * GetItemByValidOpeningNum(long lOpeningNum);
// ---------------------------------------
EXPORT mapOfCronItems::iterator FindItemOnMap (long lTransactionNum);
EXPORT multimapOfCronItems::iterator FindItemOnMultimap(long lTransactionNum);
// ---------------------------------------
// MARKETS
//
bool AddMarket(OTMarket & theMarket, bool bSaveMarketFile=true);
bool RemoveMarket(const OTIdentifier & MARKET_ID); // if returns false, market wasn't found.
EXPORT OTMarket * GetMarket(const OTIdentifier & MARKET_ID);
OTMarket * GetOrCreateMarket(const OTIdentifier & ASSET_ID,
const OTIdentifier & CURRENCY_ID, const long & lScale);
bool AddMarket(OTMarket & theMarket, bool bSaveMarketFile=true);
bool RemoveMarket(const OTIdentifier & MARKET_ID); // if returns false, market wasn't found.

EXPORT OTMarket * GetMarket(const OTIdentifier & MARKET_ID);
OTMarket * GetOrCreateMarket(const OTIdentifier & ASSET_ID,
const OTIdentifier & CURRENCY_ID, const long & lScale);
// ---------------------------------------
// This is informational only. It returns OTStorage-type data objects, packed in a string.
//
Expand All @@ -234,7 +248,7 @@ EXPORT bool GetNym_OfferList(OTASCIIArmor & ascOutput, const OTIdentifier & NYM_
// as to call AddTransactionNumber() regularly, in order to keep GetTransactionCount()
// at some minimum threshold.
EXPORT void AddTransactionNumber(const long & lTransactionNum);
long GetNextTransactionNumber();
long GetNextTransactionNumber();
EXPORT int GetTransactionCount() const; // How many numbers do I currently have on the list?
// ---------------------------------------

Expand All @@ -260,8 +274,8 @@ EXPORT bool SaveCron();
// -----------------------------------------------------

EXPORT OTCron();
OTCron(const OTIdentifier & SERVER_ID);
OTCron(const char * szFilename);
OTCron(const OTIdentifier & SERVER_ID);
OTCron(const char * szFilename);

EXPORT virtual ~OTCron();

Expand Down
19 changes: 13 additions & 6 deletions include/otlib/OTData.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,22 @@
#endif
#include <ExportWrapper.h>

extern "C" {
#include <stdint.h>
// ------------------------------------
// Windows (ugh)
extern "C"
{
#ifdef _WIN32
#include <stdint.h>
#else
#include <inttypes.h>
#endif
}
// ------------------------------------


class OTASCIIArmor;



class OTData
{
friend class OTASCIIArmor;
Expand All @@ -164,7 +171,7 @@ class OTData
protected:
// --------------------------------------------
inline void Initialize() { m_pData = NULL; m_lSize = 0; m_lPosition = 0; }
// --------------------------------------------

public:
// --------------------------------------------
EXPORT OTData();
Expand Down Expand Up @@ -195,9 +202,9 @@ class OTData
// --------------------------------------------
EXPORT void Concatenate(const void * pAppendData, uint32_t lAppendSize);
// --------------------------------------------
EXPORT bool Randomize(uint32_t lNewSize);
EXPORT bool Randomize(uint32_t lNewSize);
// --------------------------------------------
EXPORT void zeroMemory();
EXPORT void zeroMemory();
// --------------------------------------------
EXPORT uint32_t OTfread(uint8_t * buf, uint32_t buflen);

Expand Down
Loading

0 comments on commit 019e871

Please sign in to comment.