Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 945 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Broker API - Options Questions #466972
07/11/17 02:11
07/11/17 02:11
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Hello,

I'm writing options features into the Ally Invest plugin, and I have three questions:

#1 - What is the correct procedure for writing the BrokerCommand GET_OPTIONS function? Am I supposed to build up an array of CONTRACT's and then copy it to the DWORD like so...

Code:
BrokerCommand (int nCommand, DWORD dwParameter)
{
// the below code is for nCommand=="GET_OPTIONS"

std::vector <CONTRACT> contracts;
// send request to server, 
// get response from server
// parse data into contracts vector

// here's the part I'm not sure about:
dwParameter = (DWORD)contracts.data();
return contracts.size();
}

If not, please point me in the right direction.


#2 - I see that I have two symbol definitions... One is in SET_SYMBOL, and one is char* Asset. If a user wants to buy/sell an option, would the option symbol be defined in SET_SYMBOL or in char* Asset? Will there be cases where I would have to use one and override the other? Is SET_SYMBOL strictly for usage with BrokerCommand?

#3 - Will a user need the options symbols all individually in the AssetFix.csv file?

I appreciate any clarifications. Thanks.

Andrew


EDIT - I did eventually fix the above snippet. I'll document it here.
Code:
BrokerCommand (int nCommand, DWORD dwParameter)
{
// the below code is for nCommand=="GET_OPTIONS"

//this next line is a pointer to an array of 10,000 elements.
CONTRACT* contracts_ptr = (CONTRACT*)dwParameter;

std::vector <CONTRACT> contracts;
// send request to server, 
// get response from server
// parse data into contracts vector

// I copied vector elements to the pointer, not to exceed 10,000 elements.
int i;
for (i = 0; i < Contracts.size() && i < 10000; i++)
{
	contracts_ptr[i] = Contracts[i];
}
return i;
}


Last edited by AndrewAMD; 07/15/17 12:51.
Re: Broker API - Options Questions [Re: AndrewAMD] #466976
07/11/17 09:05
07/11/17 09:05
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I only know #3 - you need the underlying only in the asset list. About 1 and 2 I'll inquire and post later.

Re: Broker API - Options Questions [Re: jcl] #466978
07/11/17 11:04
07/11/17 11:04
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Ok, for getting the contract chain first SET_SYMBOL, SET_MULTIPLIER, SET_CLASS is called, then GET_OPTIONS with an array of 10000 CONTRACT structs.

For buying and selling an option, the symbol is passed in char* Asset, coded in the way as described on the "IB" page of the manual.

Re: Broker API - Options Questions [Re: jcl] #466993
07/11/17 18:08
07/11/17 18:08
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Okay, it looks like I can get the CONTRACT array through, but I'm not sure why char* Asset is still coming through as "SPY", even after I selected an available contract. I might need to troubleshoot this a bit. Attached is a screenshot.



EDIT: char* Asset is only "SPY" the second time around. The real problem I need to solve is that Error 10.




EDIT 2: I got it! I moved the Multiplier = 100 line further down in the script.

Attached Files 002.PNG003.PNG004.PNG
Last edited by AndrewAMD; 07/12/17 03:21.
Re: Broker API - Options Questions [Re: AndrewAMD] #467006
07/12/17 03:17
07/12/17 03:17
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Question #4: Below is the CONTRACT definition:
Code:
typedef struct CONTRACT
{
	DATE	time;			// or trading class
	float fAsk, fBid; // premium without multiplicator
	float fVal;			// open interest or multiplier
	float fVol; 
	float fUnl;			// underlying price
	float fStrike;
	long	Expiry;		// YYYYMMDD
	long	Type;			// PUT, CALL, FUTURE, EUROPEAN, BINARY - functions.h
} CONTRACT; // for options, futures, FOPs



4.a) DATE time: Is this supposed to be the expiration date? Also, what does "or trading class" mean, and how would it apply to options contracts? Is this just an IB thing?
4.b) float fVal: Am I supposed to use the SET_MULTIPLIER value or the actual multiplier for the asset?

Last edited by AndrewAMD; 07/12/17 23:30.
Re: Broker API - Options Questions [Re: AndrewAMD] #467051
07/13/17 16:56
07/13/17 16:56
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
The multiplier is asset specific, so you must set it after selecting the asset, like the other asset parameters.

The time is a union. In historical data it's the quote time, in option chains it's the first 8 bytes of the trading class.

Here's a section of the IB plugin code that loads the option chain into the CONTRACT structs:

Code:
void contractDetails(int id, const ContractDetails& CD )
{
	if(id != g_Id || !g_Contracts) return;
	Contract C = CD.summary;
	memset(g_Contracts,0,sizeof(CONTRACT));
	int Multiplier = atoi(C.multiplier.c_str());
	if(g_Multiplier > 0 
		&& g_Multiplier != Multiplier) return;
	if(*g_TradingClass 
		&& 0 != strcmpi(g_TradingClass,C.tradingClass.c_str())) return;
	if(C.secType == *SecType::FOP) {
		g_Contracts->Type = FUTURE | ((C.right == "C")? CALL : PUT);
		g_Contracts->fStrike = C.strike;
	} else if(C.secType == *SecType::OPT) {
		g_Contracts->Type = (C.right == "C"? CALL : PUT);
		g_Contracts->fStrike = C.strike;
	} else if(C.secType == *SecType::FUT) {
		g_Contracts->Type = FUTURE;
		g_Contracts->fStrike = 0;
	}
		strcpy_s((char*)g_Contracts,8,C.tradingClass.c_str());
	g_Contracts->Expiry = atoi(C.expiry.c_str());
	g_Contracts->fVal = Multiplier;
	g_Contracts++;
	if(++g_nContracts >= NUM_CONTRACTS) {
		g_End = TRUE;
		g_Contracts = NULL;
	}
}




Re: Broker API - Options Questions [Re: jcl] #467238
07/21/17 15:47
07/21/17 15:47
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Question #5:

What's the difference between GET_MARGININIT and GET_MARGINREQUIRED? Do either apply to options? to stocks?

Also, I understand that the margin required to sell an option to open is higher than to buy an option to open. Is there some way that I can/should differentiate between the two cases using these brokercommand functions? Does Zorro automatically calculate this?

Last edited by AndrewAMD; 07/21/17 15:49.
Re: Broker API - Options Questions [Re: AndrewAMD] #467324
07/26/17 11:23
07/26/17 11:23
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Question #6:

This is more of an engineering question. I'm looking to place "combo" option orders, or "multi-leg" orders. Basically, you pay less commission for up to four simultaneous option orders. Below is an example of a two-leg order:
Code:
<FIXML xmlns="http://www.fixprotocol.org/FIXML-5-0-SP2">
  <NewOrdMleg TmInForce="0" Px="-3.10" OrdTyp="2" Acct="12345678">
    <Ord OrdQty="4" PosEfct="O">
      <Leg Side="1" Strk="190" Mat="2014-01-18T00:00:00.000-05:00" MMY="201401" SecTyp="OPT" CFI="OC" Sym="IBM"/>
    </Ord>
    <Ord OrdQty="4" PosEfct="O">
      <Leg Side="2" Strk="200" Mat="2014-01-18T00:00:00.000-05:00" MMY="201401" SecTyp="OPT" CFI="OC" Sym="IBM"/>
    </Ord>
  </NewOrdMleg>
</FIXML>



Here's an example of how I can currently perform a four-leg order from a zorro script:
Code:
brokerCommand(SET_COMBO_LEGS,4);
// buy leg 1 <-- plugin saves leg, BrokerBuy returns ID from counter
// buy leg 2 <-- plugin saves leg, BrokerBuy returns ID from counter
// buy leg 3 <-- plugin saves leg, BrokerBuy returns ID from counter
// buy leg 4 <-- plugin executes order, BrokerBuy returns ID from counter or 0 if failure



SET_COMBO_LEGS would be a new BrokerCommand that sets the number of legs in a trade. If it's 2, BC will return 1 and execute on the second trade. 3, return 1, third trade, etc.

The problem with this approach is that I have three legs returning a successful trade, with the last one returning the actual status. If the last one returns a trade failure, then Zorro will think the first three trades were fine.

Is there some way that I can delay the return of the first 1-3 legs until I receive all of the legs and get a response from the server?

Last edited by AndrewAMD; 07/26/17 11:33.
Re: Broker API - Options Questions [Re: AndrewAMD] #467326
07/26/17 14:32
07/26/17 14:32
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
GET_MARGINREQUIRED was a relict and no one knows what it's supposed to mean, so it can be disregarded. Zorro uses anyway only the MarginCost parameter, which is the margin for the next trade with the current asset. Complex margin rules, as for options trading, must be calculated by script before opening the position, and MarginCost set to the result.

For the combo, I would send the 4 trades as usual, but store the IDs of the 3 previous legs and cancel them with cancelTrade() when the combo is not filled.

Re: Broker API - Options Questions [Re: jcl] #467360
07/28/17 02:34
07/28/17 02:34
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Then I'm pretty much done developing. laugh I just need to document a couple of things before I submit it for beta testing.

Page 1 of 3 1 2 3

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1