jl777
Legendary
Offline
Activity: 1176
Merit: 1134
|
 |
July 29, 2014, 08:05:11 AM |
|
Well, that took longer than I expected, but had to essentially recreate most of MT4!
The reason is that after spending all that time making sure bots can use other bot's outputs as inputs and making arbitrary topology, the front line bots need input from, well, from other exchanges and InstantDEX orderbook. So, after not going crazy from all the possible price inversions due to the ability of InstantDEX to show any orderbook base/rel or rel/base. Meaning BTCD/BTC or BTC/BTCD. So at the lowest level, an orderbook needs to pick assetA and assetB and I just require assetA < assetB in its ID. For most contracts there is only one order, but toss in the NXT AE and it is NXT based, so it has BTC/NXT, but all the exchanges have NXT/BTC.
Add to this confusion, the user (tradebot) can request the orderbook in either orientation.
Anyway, I think I got it right, but too late to debug this sort of thing today, so it will have to be tomorow, when I should also be able to add the "action" function calls, eg. makeoffer, issue trades, etc.
All the tradebots are called whenever the top of the orderbook of any exchange changes. Also, once per minute timer.
The first thing a tradebot needs to do is call the initialization function: int init_PTL(int *eventp,int *changedp,char *exchange,char *base,char *rel);
if exchange is not specified, all exchanges will be accepted, including a special one called "ALL", which is all exchanges including InstantDEX combined. base is the first currency and rel is the second, so BTC/BTCD would be base = "BTCD" and rel = "BTC"
if init_PTL returns 0, it means it was not a match. If non-zero it was and all the globals are set. event will currently be: #define TRADEBOT_PRICECHANGE 1 #define TRADEBOT_NEWMINUTE 2 changed would be 1 if there was a pricechange, this is probably almost always going to be set, but I think there are some timer cases that could have no changes, needs some debugging
Here are the available global data: Bid(n) nth bid in the orderbook Bidvol(n) nth bid volume in the orderbook Bidid(n) id of the nth buyer Ask(n) nth ask in the orderbook Ask(n) nth ask volume in the orderbook Askid(n) id of the nth seller
I also calculate the bars for various timeframes: M1, M2, M3, M4, M5, M10, M15, M30 and H1 Maxbars tells the most bars possible, but it is quite possible that even though the bar is there it is empty especially if you dont have much data. Just check the BARI_FIRSTBID or BARI_FIRSTASK field, if it is zero, then no data for that bar
There are 16 fields in each bar, to access one, just go: M1(pasti,bari) or M2(pasti,bari) or ... H1(pasti,bari)
pasti of 0 is the latest bar, pasti 1 is one bar in the past, etc. Now I recalculate all the bars to the second, so the bars are relative to the current second. Jdatetime has the time index in GMT from 1/1/2000
bari is the index into the 16 element bar and has the following fields: #define BARI_FIRSTBID 0 #define BARI_FIRSTASK 1 #define BARI_LOWBID 2 #define BARI_HIGHASK 3 #define BARI_HIGHBID 4 #define BARI_LOWASK 5 #define BARI_LASTBID 6 #define BARI_LASTASK 7
#define BARI_ARBBID 8 #define BARI_ARBASK 9 #define BARI_MINBID 10 #define BARI_MAXASK 11 #define BARI_VIRTBID 10 #define BARI_VIRTASK 11 #define BARI_AVEBID 12 #define BARI_AVEASK 13 #define BARI_MEDIAN 14 #define BARI_AVEPRICE 15
Currently, the ARB and VIRT fields are not calculated.
So as you can see, PTL now is getting close to MT4 functionality, actually in many ways it has a lot more. Now I just need to debug all the new code and add the action functions.
James
|