Пример #1
0
// This is called by the client side. First you call MakeOffer() to set up the Offer,
// then you call IssueTrade() and pass the Offer into it here.
bool OTTrade::IssueTrade(OTOffer & theOffer, char cStopSign/*=0*/, long lStopPrice/*=0*/)
{
	// Make sure the Stop Sign is within parameters (0, '<', or '>')
	if ((cStopSign ==  0 )	||
		(cStopSign == '<')	||
		(cStopSign == '>'))
		m_cStopSign = cStopSign;
	else
	{
		OTLog::vError("Bad data in Stop Sign while issuing trade: %c\n", cStopSign);
		return false;
	}
	
	// Make sure, if this IS a Stop order, that the price is within parameters and set.
	if ((m_cStopSign == '<')	||
		(m_cStopSign == '>'))
	{
		if (0 >= lStopPrice)
		{
			OTLog::Error("Expected Stop Price for trade.\n");
			return false;
		}
		
		m_lStopPrice = lStopPrice;
	}

	m_nTradesAlreadyDone	= 0;
	
	SetCreationDate(time(NULL)); // This time is set to TODAY NOW  (OTCronItem)
	
	// ------------------------------------------------------------------------
	
	// Validate the Server ID, Asset Type ID, Currency Type ID, and Date Range.
	if ((GetServerID()			!= theOffer.GetServerID())		||
		(GetCurrencyID()		!= theOffer.GetCurrencyID())	||
		(GetAssetID()			!= theOffer.GetAssetID())		||
		
		(theOffer.GetValidFrom() <	0)							||
		(theOffer.GetValidTo()	 < theOffer.GetValidFrom())	)
	{
		return false;
	}
	
//	m_CURRENCY_TYPE_ID // This is already set in the constructors of this and the offer. (And compared.)
//	m_CURRENCY_ACCT_ID // This is already set in the constructor of this.
	
	// Set the (now validated) date range as per the Offer.
	SetValidFrom(theOffer.GetValidFrom());
	SetValidTo(theOffer.GetValidTo());
	
	// Get the transaction number from the Offer.
	SetTransactionNum(theOffer.GetTransactionNum());
	
	// Save a copy of the offer, in XML form, here on this Trade.
	OTString strOffer(theOffer);
	m_strOffer.Set(strOffer);
	
	return true;
}
Пример #2
0
// This is called by the client side. First you call MakeOffer() to set up the
// Offer,
// then you call IssueTrade() and pass the Offer into it here.
bool OTTrade::IssueTrade(OTOffer& offer, char stopSign, int64_t stopPrice)
{
    // Make sure the Stop Sign is within parameters (0, '<', or '>')
    if ((stopSign == 0) || (stopSign == '<') || (stopSign == '>'))
        stopSign_ = stopSign;
    else {
        otErr << "Bad data in Stop Sign while issuing trade: " << stopSign
              << "\n";
        return false;
    }

    // Make sure, if this IS a Stop order, that the price is within parameters
    // and set.
    if ((stopSign_ == '<') || (stopSign_ == '>')) {
        if (0 >= stopPrice) {
            otErr << "Expected Stop Price for trade.\n";
            return false;
        }

        stopPrice_ = stopPrice;
    }

    tradesAlreadyDone_ = 0;

    SetCreationDate(
        OTTimeGetCurrentTime()); // This time is set to TODAY NOW  (OTCronItem)

    // Validate the Notary ID, Instrument Definition ID, Currency Type ID, and
    // Date Range.
    if ((GetNotaryID() != offer.GetNotaryID()) ||
        (GetCurrencyID() != offer.GetCurrencyID()) ||
        (GetInstrumentDefinitionID() != offer.GetInstrumentDefinitionID()) ||
        (offer.GetValidFrom() < OT_TIME_ZERO) ||
        (offer.GetValidTo() < offer.GetValidFrom())) {
        return false;
    }

    //    currencyTypeID_ // This is already set in the constructors of this
    // and the offer. (And compared.)
    //    currencyAcctID_ // This is already set in the constructor of this.

    // Set the (now validated) date range as per the Offer.
    SetValidFrom(offer.GetValidFrom());
    SetValidTo(offer.GetValidTo());

    // Get the transaction number from the Offer.
    SetTransactionNum(offer.GetTransactionNum());

    // Save a copy of the offer, in XML form, here on this Trade.
    String strOffer(offer);
    marketOffer_.Set(strOffer);

    return true;
}