Quote from Shreddog:
When you generate an order and a Client order ID for it you need to save that ID somewhere for use later. This somewhere is called a variable. Preferably you need to use an array or maybe a hashtable. I store it as part of an object I created. Regardless, it needs to be some sort of data structure that you can access so you can cancel the order later.
Right after they specify the order.clOrderID = ...... you need the following:
MyVariable = order.ClOrderID
Don't forget to declare MyVariable.
Good luck.
Holy moly. Shreddog and Euler, if you guys were here Iâd buy you a beer. That worked perfectly. Why didnât Sterling suggest storing the unique dated id as a variable? Thatâs brilliant. Because they say when you use the api generated id, you canât use it again. So how can you repeatedly use the same id and then cancel it? Use the date stamp and store it in a variable of course. I still had to work with it a little. The manual says to do it wrong.
It says to.
Dim this:
Dim m_STIOrderMaint As STIOrderMaint
Then declare this in the new procedure:
Set m_STIOrderMaint = New STIOrderMaint
ThenCall the id, which they donât tell you how to do.
Then cancel it with this:
m_STIOrderMaint.CancelOrder â<Account>â, 0, â<Client Order Id of Order to cancel>â, â<Client Order Id of new cancel order record>â
So it would look like
" < ACCOUNTNAMEHERE > ", 0, " < MyVariable > ", " < MyVariable2 > "
First off the quotation marks they use are not even recognized by VB. You have to change those. But after that it still didnât work. So I looked at the sterling order example VB and they actually do it differently.
They do it like this:
m_STIOrderMaint.CancelOrder "ACCOUNTNAMEHERE", 0, OldClOrdId, ClOrdId
Notice thereâs no < > and the id is not in ââ. So I just put it like in the example and it came out like this.
Private Sub Command5_Click()
Set m_STIOrderMaint = New STIOrderMaint
m_STIOrderMaint.CancelOrder " ACCOUNTNAME ", 0, MyVariable, MyVariable
End Sub
Now they say the second id has to be a new one because that is the id of the cancel, but it worked fine by naming it the same MyVariable. But in order to do it right I put in a new variable and named it MyVariableCancel. So it looks like this.
Declarations
Dim MyVariable
Dim MyVariableCancel
Private Sub Command5_Click()
Set m_STIOrderMaint = New STIOrderMaint
m_STIOrderMaint.CancelOrder "ACCOUNTNAME", 0, MyVariable, MyVariableCancel
End Sub
At first when I tried it, it didnât work. But then after I kept clicking the cancel, it did. I remember reading somewhere that it doesnât allow an API cancel until after 10 seconds. But the first method, I could cancel immediately. So unless thereâs a big difference, I will not rename the cancel because I donât want to wait 10 seconds.
Boy there is nothing more frustrating than trying to get something to work, and nothing that feels better than finally getting it to work. I know this is all basic stuff to you, but I really appreciate the help. After all this work, I actually have to figure out a way to actually make money now.