1. 首页
  2. 易语言 - EasyLanguage
  3. 根据客户编号限定分析技术 Restricting access to a Customer Number

根据客户编号限定分析技术 Restricting access to a Customer Number

本文描述如何实现让您的分析技术只针对某一客户编号运行。 This page describes how to restrict your studies so that they can only be run by someone with a particular Customer Number. To restrict your code fully you need to add this functionality and then see the Protecting EasyLanguage Code page.

In most cases a Customer Number is specific to a person. However, it is also possible for companies to have multiple people (with different user names) accessing one account (Customer Number). In these situations you should see the Restricting access to a person page.

The first thing to do is get the Customer Number from the person you will be sending the strategy/indicator to. The Customer Number is found from the main ‘Help’ menu, under ‘About TradeStation x.x’…

Next you need to restrict your code. In your indicator/function code you place the following code around all of your other code:

Vars:	CustomerNumber(123456); 
 
If CustomerID = CustomerNumber then Begin
           {all your code here} 
end;

Note that you put the Customers Number in a variable (not an input) and you put the begin…end loop around your entire code (except the Inputs: and Variables: declarations).


This is a second, more comprehensive example, that combines Customer Number, an expiry date, and an ‘x days before expiry’ warning (see Restricting access by date).

The Customer Number is checked first, and if it isn’t valid a message is sent to the Print Log and a message displayed on screen. At that point, no more code is run.
If the Customer Number is valid, then the date is checked for expiry. If the product is expired then a message is sent to the Print Log and a message displayed on screen. And no more code is run.
If both the Customer Number and date are valid then a final check is made to see if we are within ‘WarningDays’ of the expiry. If this is the case then a message is send to the Print Log and a messaage displayed on screen. After this the main indicator/strategy code is run.

If the CustomerNumber variable is left at 0 then the customer number criteria is not checked (good for testing). It is OK to have a list of customer numbers because when you ‘protect’ the ELD (see Protecting EasyLanguage Code) all comments are stripped out.

Vars:	CustomerNumber(0),
	//CustomerNumber(562732),		// TradeStation Testing Number
	//CustomerNumber(123456),		// Joe Jacobs, 10 April 2006
	//CustomerNumber(987654),		// Steve Smith, 17 June 2006
	//CustomerNumber(456321),		// Terry Thomas, 1 January 2007
	ExpiryDate(1100619),
	WarningDays(5),

	TXID_InvalidCust(-1),
	TXID_NearExpiry(-1),
	TXID_Expired(-1),
	
	LBOC(False);



LBOC = LastBarOnChart;

//Check here to make sure we have a valid CustomerID
If ( CustomerID = CustomerNumber or CustomerNumber = 0 ) then Begin

	//Check to make sure the data hasn't expired
	If Date <= ExpiryDate then Begin

		If CurrentBar = 1 then Begin
			TXID_NearExpiry = Text_New(date, time, 0, " ");
		end;

		//If we are within WarningDays of the expiry then display a message
		If LBOC and DateToJulian(ExpiryDate) - DateToJulian(date) <= WarningDays then Begin

			value1 = Text_Float(TXID_NearExpiry, 30, 50);

			Text_SetString(TXID_NearExpiry, "This product expires in " + 
					NumToStr(DateToJulian(ExpiryDate) - DateToJulian(Date), 0) + " Days");

			Text_SetStyle(TXID_NearExpiry, 2, 0);

			Once Begin
				print ("This product expires in ", DateToJulian(ExpiryDate) - DateToJulian(date):0:0, " Days");
			end;
		end;

		{}
		{your complete indicator or strategy code here}
		{}

	end
	//past expiry date
	else Begin
		If CurrentBar = 1 then Begin
			TXID_Expired = Text_New(date, time, 0, "This product has now expired.");
		end;

		If LBOC then Begin
			Once Begin
				Print ("This product has now expired");
			end;

			value2 = Text_Float(TXID_Expired, 1, 50);

			Text_SetStyle(TXID_Expired, 1, 0);
		end;	
	end;
end
//wrong customer number
else Begin
	If CurrentBar = 1 then Begin
		TXID_InvalidCust = Text_New(date, time, 0, "Invalid Customer Number");
	end;

	If LBOC then Begin
		Once Begin
			Print ("Invalid Customer Number");
		end;

		value2 = Text_Float(TXID_InvalidCust, 1, 50);

		Text_SetStyle(TXID_InvalidCust, 1, 0);
	end;
end;


The following code is not necessary for EasyLanguage. It is an example of using the SDK to access the Customer Number, and is for people who wish to protect their code in a DLL. It is written in C++.

#import "C:\Program Files\TradeStation 8.1 (Build 3159)\Program\tskit.dll" no_namespace 
 
#define CUSTOMERNUMBER		123456 
#define ERROR			-1 
 
double __stdcall myDLLcalc(IEasyLanguageObject *pELObj, int value1) 
{ 
	ITradeStationPlatform * pELTSP = pELObj->Platform; 
	int myCustNum = pELTSP->CustomerID; 
 
	if ( myCustNum == CUSTOMERNUMBER )  
	{ 
		//do your calculations on value1 
		//return result; 
	} 
	else 
	{ 
		return ERROR; 
	} 
}


And this is the equivalent in VB.net

Private Function TS_GetCustomerId(ByVal pELObj As TSKITLib.IEasyLanguageObject) As Integer 
	Dim pELTSP As TSKITLib.ITradeStationPlatform = pELObj.Platform 
	Dim CustomerId As Integer = pELTSP.CustomerID 
	Return CustomerId 
End Function
更新于 2020年5月15日

这篇文章对您有帮助吗?

相关的话题

留言评论