Developing broker plugin, "BrokerCommand" causes wrong nTicks

Posted By: maccam912

Developing broker plugin, "BrokerCommand" causes wrong nTicks - 07/29/21 20:58

I wasn't sure where to post this. I know there is free support for developers writing C++ plugins. My plugin is in Rust, and is just a POC.

When I don't have "BrokerCommand" defined "BrokerHistory2" is called with "nTicks" = 300, as expected. Dates for start and end are parsed just fine etc.

When I define a "BrokerCommand" function that simply is returning 0 no matter what the arguments are everything falls apart for my "BrokerHistory2". nTicks is int::min (-2147483648), tStart is -89434288.33333333 and tEnd is -89434078.4252956. Needless to say, my broker doesn't have history from that far back laugh

Does anyone here have any ideas as to why just defining "BrokerCommand" here is causing this problem? The Rust FFI has been working fine until now.
Posted By: AndrewAMD

Re: Developing broker plugin, "BrokerCommand" causes wrong nTicks - 07/29/21 21:09

I have never seen this happen in C++. Maybe force GET_MAXTICKS to output 300?

Otherwise, check to see if there's any problems with your build process/options. Check your struct alignment (1 byte).
Posted By: maccam912

Re: Developing broker plugin, "BrokerCommand" causes wrong nTicks - 07/30/21 00:55

What is most baffling to me is that having BrokerCommand defined, and called, is what causes the weird arguments. Here is an example with what all the arguments to BrokerHistory2 are:

[Linked Image]

And here is when it works, when BrokerCommand is not defined:

[Linked Image]

Structs seem to be aligned. The only one I'm using is T6, and from the docs I have it aligned to 4 bytes.
Posted By: jcl

Re: Developing broker plugin, "BrokerCommand" causes wrong nTicks - 07/30/21 11:42

I'm not very familiar with Rust, but BrokerCommand returns double, not int. Maybe your implementation returns strange values because of a wrong return type.
Posted By: maccam912

Re: Developing broker plugin, "BrokerCommand" causes wrong nTicks - 07/30/21 20:12

Well turns out jcl isn't a chief engineer for nuthin'. That was exactly my problem. After fixing the return type everything worked exactly as expected. Thanks for the help!
Posted By: Ferris

Re: Developing broker plugin, "BrokerCommand" causes wrong nTicks - 12/15/22 20:12

Hey everyone,
I'm replying to this post because I'm very much interested in using Rust with Zorro, as Rust is my favorite programming language that I'm using for almost everything.
(And this is the only forum thread that comes up when I search for Rust.)

@maccam912:
How is it going with Rust & Zorro? Would you be interested in collaborating?
I've been using Rust since 2014 and I'm working as a Rust fullstack developer, I've written quite a bit of FFI code in Rust over the years to interact with C/C++ libs.
It would be nice if we could pool our efforts instead of duplicating efforts in writing FFI. What do you think? smile

I'm also curious if there are other Rustaceans on this forum who would be interested in collaborating on writing Rust FFI.
© 2024 lite-C Forums