how to send several commands in a row

Discussion regarding the spreadsheet functionality of Bet Angel.
Post Reply
flipflop76
Posts: 16
Joined: Sat Nov 07, 2009 9:22 am

hello,
i wrote some VBA code which sends several commands in a row, such as cancel current order, send a new one etc.
the thing is, the VBA code runs too fast, betangel doesn't have time to finish the first command, it already sends the next one, and the first one is not executed.
The code works fine in debugging (step by step) mode, but not in normal mode.

Is there a solution to that issue ? I don't think a call to function "sleep" is a good idea. I don't feel like implementing a state machine if I can avoid it, since my application is quite simple.

thanks
spreadbetting
Posts: 3140
Joined: Sun Jan 31, 2010 8:06 pm

I doubt BA can process two different API requests within the same refresh so sleep probably wouldn't work anyway. Can you not set a flag within your code so separate requests will be sent at each refresh once the first conditions have been met and so on
flipflop76
Posts: 16
Joined: Sat Nov 07, 2009 9:22 am

OK thanks, that's a good idea, here is what I did:
init:
set state = 1

main function:
if state == 1 then
cancel pending order if appropriate
state = 2
else if state == 2 then
send new order to replace cancel order if appropriate
state = 3
else if state == 3 then
...some final processing...
state = 1
end

then, whenever I call my main function, it executes one of the 3 parts...

Another question: what's the best way to call this main function ? with a timer ? inside worksheet_calculate ? from excel cell ?

thanks,
FF
spreadbetting
Posts: 3140
Joined: Sun Jan 31, 2010 8:06 pm

Probably easiest to call from with worksheet_calculate as I imagine most of your code will probably be running from within there anyway. I usually just DIM variables within my coding so I can use them to bypass any unneccessary code or set off various routines when needed, they usually get reset on the next market etc so all run with worksheet calculate
flipflop76
Posts: 16
Joined: Sat Nov 07, 2009 9:22 am

I don't think it's a good idea, as some commands are slow. For example cancel command takes about 5 seconds.
what I did is use an excel timer. All my code is called in the timeout function. Not very clean, but it's the only way I found.
I'd be interested to hear different ways.
Post Reply

Return to “Bet Angel - Spreadsheet / Excel chat”