API Support Forum
OEC API > FIX Support > Margin request
Author Topic: Margin request
(10 messages, Page 1 of 1)
Moderators: VPfau
ARomano8351
Posts: 5
Joined: Jun 04, 2024


Posted: Jun 23, 2024 @ 01:43 PM             Msg. 1 of 10
Hi,

If found that the fix example https://bitbucket.org/GainFuturesDev/oecfixsample/src/master/ has a MARGINCALC Command in foxscript.
1)How is this script language used?
How to run commands, from the console? I installed in LINUX but nothing seems to work,
I am already using fix for trading from python in linux, with quickfix, but I it is not clear how to use foxscript.

I want to write a function to compute the margins of a given portfolio, and run it from python, if possible.

2)Is there any working example of margin calculation for a portfolio of 3 different futures in foxscript? In case this will not work, anybody has an example of calling com object from python to compute the margins of multiple legs portfolios ?

Thanks
BW
Edited by ARomano8351 on Jun 23, 2024 01:47 PM
Edited by ARomano8351 on Jun 23, 2024 06:21 PM
VPfau
Moderator
Posts: 164
Joined:


Posted: Jun 24, 2024 @ 12:56 PM             Msg. 2 of 10
>1)How is this script language used?
This is a console application that could execute your commands in interactive mode or you can provide foxscript as a parameter.
Examples of foxscript located here https://bitbucket.org/GainFuturesDev/oecfixsample/src/master/Tests/

>How to run commands, from the console? I installed in LINUX but nothing seems to work,
This is Windows console application based on .NETFramework 4.6.2; Dependencies located at ThirdParty/ are also Win based.

>I want to write a function to compute the margins of a given portfolio, and run it from python, if possible.
We do not support python.

>2)Is there any working example of margin calculation for a portfolio of 3 different futures in foxscript?
I did not find any but based on atg file the MarginCalc command defined as this:

https://bitbucket.org/GainFuturesDev/oecfixsample/src/master/FoxScript/FoxScript.atg#lines-400

Code example skipped due Forum restrictions.


which leads to syntax like
MarginCalc Account# Contract MinQty MaxQty, Custom Fields Assignment in form Tag=Value
Vitaliy Pfau
CMicciche902
Posts: 354
Joined:


Posted: Jun 24, 2024 @ 01:55 PM             Msg. 3 of 10
You wouldn't need to use the FIX Sample. You already have a FIX application. Just support these messages:

    *MarginCalcRequest - UR- See https://futures-media.stonex.com/gfapi/?topic=html/6835735a-11da-42bd-ad01-3d4ccfbbc033.htm
    *MarginCalcReport - UM - See https://futures-media.stonex.com/gfapi/?topic=html/8f93af8f-9598-49f6-ae19-4c1950db9345.htm
Chris M
ARomano8351
Posts: 5
Joined: Jun 04, 2024


Posted: Jun 24, 2024 @ 04:07 PM             Msg. 4 of 10
Thanks. I found that indeed, but that message type seems to be a custom one, i.e. is not included in the standard fix implementation. Do I need to create a custom message type https://quickfixn.org/tutorial/custom-fields-groups-and-messages.html? You have an example?

I tried this , but I get "Unknown request message type"
Edited by ARomano8351 on Jun 24, 2024 06:24 PM
ARomano8351
Posts: 5
Joined: Jun 04, 2024


Posted: Jun 25, 2024 @ 10:55 AM             Msg. 5 of 10
When I submit the sample message I get : Unknown request message type:
2024-06-25 15:51:31,626 - INFO - MainThread - FixClient is sending: 949533789=UR
2024-06-25 15:51:31,628 - INFO - MainThread - Sending Application message to server. Session: FIX.4.4:xxxxxx->OEC. Message: 8=FIX.4.49=25235=UR34=8649=xxxxxx52=20240625-15:51:31.62856=OEC1=xxxxxx55=ES55=ES55=OES110=4110=1110=-5200=201403200=201403200=201403202=1600461=FXXXXS461=FXXXXS461=OCXFXS702=312064=63530616069275902512066=-412066=512066=110=089


2024-06-25 15:51:31,629 - ERROR - MainThread - Unknown request message type 8=FIX.4.49=25235=UR34=8649=xxxxxx52=20240625-15:51:31.62856=OEC1=xxxxxx55=ES55=ES55=OES110=4110=1110=-5200=201403200=201403200=201403202=1600461=FXXXXS461=FXXXXS461=OCXFXS702=312064=63530616069275902512066=-412066=512066=110=089
2024-06-25 15:51:31,634 - INFO - Dummy-5 - Received Admin message from server. Session: FIX.4.4:xxxxxx->OEC. Message: 8=FIX.4.49=12435=334=8549=OEC52=20240625-15:51:3156=xxxxxx45=8658=Tag appears more than once371=55372=UR373=1310=125
VPfau
Moderator
Posts: 164
Joined:


Posted: Jun 25, 2024 @ 01:10 PM             Msg. 6 of 10
You cannot send 3 sequential 55 tags. NoInstrument is a group. From the documentation:
Request:
8=FIX.4.4|9=230|35=UR|34=276|49=username|52=20140317-01:21:09|56=OEC_TEST|1=YRACCNT|702=3|55=ES|461=FXXXXS|200=201403|110=4|12066=5|55=ES|461=FXXXXS|200=201403|110=-5|12066=-4|55=OES|461=OCXFXS|200=201403|202=1600|110=1|12066=1|12064=635306160692759025|10=020|
Response:
8=FIX.4.4|9=155|35=UM|34=276|49=OEC_TEST|52=20140317-01:21:08.119|56=username|1=YRACCNT|12064=635306160692759025|12065=0|12067=9522.70|12068=8657.00|12069=12015.00|12070=5265.20|10=073|
Vitaliy Pfau
ARomano8351
Posts: 5
Joined: Jun 04, 2024


Posted: Jun 25, 2024 @ 04:41 PM             Msg. 7 of 10
Are you referring to NoPositions, 702?
I do not see any of NoPositions fields (703,704, .. see below) in the sample message and I cannot set other fields such as 55 in the group, I get an error, because 55 for example is not a filed of NoPositions group (see below).
Can you post an example of how to construct the UR message with quickfix , (c++ is fine) ? You have a custom xml for UR/UM messages? They are not included in the standard xml dictionary for fix44, so I suppose they are custom.
Thanks

Below is the quick fix code for NoPositions
class NoPositions(fix.Group):
def __init__(self):
order = fix.IntArray(6)
order[0] = 703
order[1] = 704
order[2] = 705
order[3] = 706
order[4] = 539
order[5] = 0
fix.Group.__init__(self, 702, 703, order
Edited by ARomano8351 on Jun 26, 2024 12:25 AM
VPfau
Moderator
Posts: 164
Joined:


Posted: Jun 26, 2024 @ 07:58 AM             Msg. 8 of 10
For FIX connection we support only protocol messages. You are free to choose any implementation of the protocol and languages.
I googled that for you: https://ref.onixs.biz/cpp-fix-engine-guide/group__fix-protocol-repeating-group.html
This article describes groups and have examples in c++
Vitaliy Pfau
ARomano8351
Posts: 5
Joined: Jun 04, 2024


Posted: Jun 26, 2024 @ 09:57 PM             Msg. 9 of 10
Hi,

Hi,

Hi,
thanks, but setgroup works differently in quickfix.
1)in quickfix (which is the fix implementation suggested in the gain fix docuementation), setgroup is not available with 2 arguments, but requires 6 arguments(https://github.com/quickfix/quickfix/blob/master/src/C%2B%2B/Message.h#L246)
void setGroup( const std::string& msg, const FieldBase& field,
const std::string& string, std::string::size_type& pos,
FieldMap& map, const DataDictionary& dataDictionary );
, which I cannot figure out what they are and if it is the same method.

2)This codes give an error:
group= fix.NoPositions()
group.setField(fix.Symbol("ES"))
as documente here as well https://stackoverflow.com/questions/77494204/im-trying-to-set-the-partyid-field-in-quickfix-python-api-and-i-face-an-argumen.

but it works for groups defined in the xml dictionary.

3)Can you provide a xml of the fix dialect used by gain? That would make it easy to create UR messages.
4)Alternatively, can you show to create the message without the xml, with the quickfix python implementation?
I also tried to create the fix message from a string, but the order is lost, and the repeating group is not recognized.

5)In any case when I send a message with the 35=UR field gives an erro. not recognized message type, which is to related to the group ordering.
Edited by ARomano8351 on Jun 26, 2024 10:08 PM
VPfau
Moderator
Posts: 164
Joined:


Posted: Jun 27, 2024 @ 09:01 AM             Msg. 10 of 10
FIX dictionary publicly available by this link https://api.gainfutures.com/WebAPI/api/Files/DownloadClientUpdateLast?brandId=0&clientTypeId=5010&branchId=2

We don't support client side applications for FIX protocol.
We don't support c++ and python.

Thank you
Vitaliy Pfau