# QUERY ORDERS & TRADES

**QUERY TRADE**

**SAMPLE REQUEST TRADE**

```
{“type”:”querytrade”, “fromtime”:”1555522543000”}
```

This is to query the trades for a user.&#x20;

Only administrator can specify “userid” field.

* `“fromtime”` field is optional, if set, it is to specify cutofftime to query
* `“security”` field is optional, if set, it is to return trades for that security only

**SAMPLE RESPONSE ON SUCCESS OR FAILURE**

* `“total_rec”` tells you how many records there are available.

For each record, there is “rec\_no”, this is just for counting. Total number of records received should match value in “total\_rec” field. It should be sort by “time”.

If there are more than 100 records, system can send you multiple response, each will have100 records.

```
{“result”:”OK”,”userid”:”0003”,”type”:”querytrade”,”total_rec”:0}
{“result”:”OK”,”data”:[{“refno”:”5GQBE9BCZOO0A3”,”category”:”CROX”,”ex
ecqty”:”10”,”execprice”:”30”,”traderefno”:”5GQBE9BCZOO0A32_5GQBE9BCZOO2”,”side”:
“B”,”trdtime”:”1557323619303”,”rec_no”:1,”security”:”MSFT”,”type”:”sale”},{“refn
o”:”5GQBE9BCZN4GA7”,”category”:”CROX”,”execqty”:”10”,”execprice”:”100.5”,”trader
efno”:”5GQBE9BCZN4GA72_5GQBE9BCZN4I”,”side”:”B”,”trdtime”:”1557323603427”,”rec_n
o”:2,”security”:”ZVZZT”,”type”:”sale”}],”type”:”querytrade”,”total_rec”:2}
```

**QUERY ORDER**

**SAMPLE REQUEST TRADE**

```
{“refno”:”5GS08WTIE8CWA0”,”security”:”BTCUSD”,”type”:”queryorder”}
```

&#x20;Must provide “security” and “refno” field (that is FI’s order refno)**.**

```
{“result”:”OK”,”refno”:”5GS08WTIE8CWA0”,”data”:{“updtime”:”15575052350
85”,”tif”:”GTC”,”execamount”:”10000”,”qty”:”1000”,”security”:”BTCUSD”,”type”:”or
der”,”clientorderid”:”ID1”,”liveqty”:”900”,”category”:”BRUT”,”refno”:”5GS08WTIE8
CWA0”,”price”:”100”,”execqty”:”100”,”side”:”S”},”security”:”BTCUSD”,”type”:”quer
yorder”}
{“result”:”order not found”,”refno”:”5GS08WTIE8CWA0”,”security”:”BTCUS
D”,”type”:”queryorder”} 
```

**TRADE HISTORY**

* Symbol- type=getsymbols Close- type=highlow. Get data per symbol if exists&#x20;
* Open- type=subscribeonopen
* % Change - calculating is (openingprice - prevcloseprice)/prevcloseprice \* 100&#x20;
  * openingprice from type=highlow&#x20;
  * prevcloseprice from type=highlow
* High- type=highlow. Get data per symbol if exists&#x20;
* Low- type=highlow. Get data per symbol if exists • Best Bid - type=subscribe . Max price from bids&#x20;
* Best Ask - type=subscribe. Min price from asks&#x20;
* Quantity in Trade - type=subscribe. Sum of qty from books

Must set “security” field for the symbol that you query.&#x20;

Optional field “extradays”, by default, system return last 24-hour trade info back to you. If you need extra history, set “extradays”, for example to “3” for 3 extra previous day history info.&#x20;

The query returns the trade history in 1-minute block. If that minute has trade, a corresponding block will be return with summary of that minute high/low/first/last trade price as well as volume and num of trades info.&#x20;

There can be multiple responses to one query if there are more than 100 entries in response. Each response will carry maximum of 100 entries. “total\_rec” tells how many records there should be, and “rec\_no” tell you current number of record.

![Trading Statistics for Symbols](https://1549898297-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MOEmO1S_tBPZ8x5Nzu3%2F-MOOjyr-u6ZbEyITR5-r%2F-MOOkFsl6bKJ3IkFrJt2%2Fstat.png?alt=media\&token=16934994-5923-4ca2-b187-44c6e5015920)

**SAMPLE REQUEST EXAMPLES**:

```
{“type”:”tradehistory”,”security”:”BTCUSD”},
{“result”:”OK”,”data”:[{“lastprice”:”11
1”,”starttime”:”1556194354163”,”lastttime”:”1556194368559”,”volume”:”2”,”highpri
ce”:”125”,”blocktime”:”1556194320000”,”rec_no”:1,”numoftrades”:”2”,”startprice”:
“125”,”lowprice”:”111”},{“lastprice”:”135”,”starttime”:”1556194413020”,”lastttim
e”:”1556194413020”,”volume”:”1”,”highprice”:”135”,”blocktime”:”1556194380000”,”r
ec_no”:2,”numoftrades”:”1”,”startprice”:”135”,”lowprice”:”135”},{“lastprice”:”13
5”,”starttime”:”1556194529756”,”lastttime”:”1556194538364”,”volume”:”2”,”highpri
ce”:”160”,”blocktime”:”1556194500000”,”rec_no”:3,”numoftrades”:”2”,”startprice”:
“160”,”lowprice”:”135”},{“lastprice”:”140”,”starttime”:”1556194560524”,”lastttim
e”:”1556194560524”,”volume”:”1”,”highprice”:”140”,”blocktime”:”1556194560000”,”r
ec_no”:4,”numoftrades”:”1”,”startprice”:”140”,”lowprice”:”140”}],”security”:”BTC
USD”,”type”:”tradehistory”,”total_rec”:4}
```

For tradable symbols (such as pairs), there is summary of:

* `"high"`
* `"low"`
* `"open"`
* "`close"`&#x20;

CLOSE `prevcloseprice` &#x20;

```
{"type":"subscribehighlow","security":"LTCUSD"}  {"openingprice":"166.39","security":"LTCUSD","highprice":"45000","lowprice":"1","prevcloseprice":"176","type":"highlow"} 
```

OPEN  `openingprice`&#x20;

```
{"type":"subscribehighlow","security":"LTCUSD"} R {"openingprice":"166.39","security":"LTCUSD","highprice":"45000","lowprice":"1","prevcloseprice":"176","type":"highlow"} 
```

PERCENT `Change calc`&#x20;

```
(openingprice - prevcloseprice)/prevcloseprice *100 4. High - highprice Q {"type":"subscribehighlow","security":"LTCUSD"} R {"openingprice":"166.39","security":"LTCUSD","highprice":"45000","lowprice":"1","prevcloseprice":"176","type":"highlow"} 
```

LOW `lowprice`&#x20;

```
{"type":"subscribehighlow","security":"LTCUSD"} R {"openingprice":"166.39","security":"LTCUSD"
```

The corresponding time (which is in EPOCH milliseconds),"tradeqty" for total qty and "tradeamount" for total amount.

**SUBSCRIBEONOPEN**

```
{"type":"subscribeonopen","security":"AAPL"} 
{"result":"OK","security":"AAPL","type":"subscribeonopen"}
```

&#x20;**SUBSCRIBE**

```
{"type":"subscribe","request":[{"security":"AAPL","msg":"ibook"},
{"security":"AAPL","msg":"itrade"}]}
{"security":"AAPL","books":[{"side":"B","act":"U","src":"CROX","price":"87","qty":"10","id":247697979505377328,"time":
"1610626921561","mpid":"FDML","key":"5XW4NNPLZZKKC0"},{"side":"B","act":"U","src":"CROX","price":
"87","qty":"10","id":247697979505377327,"time":"1610626867059","mpid":"FDML","key":"5XW4NNPLZZKJC0"},{"side":"B","act":
"U","src":"CROX","price":"99","qty":"10","id":247697979505377326,"time":
"1610626859320","mpid":"FDML","key":"5XW4NNPLZZKIC0"},{"side":"S","act":"U","src":"CROX","price":"100","qty":"65","id":
247697979505377325,"time":"1610626845129","mpid":"FINT","key":"5XVXU4B5E67XC0"},{"side":"S","act":"U","src":"CROX","price":
"702","qty":"75","id":247697979505377324,"time":"1610600824281","mpid":"FINT","key":"5XVXU4B5E67VC0"},{"side":"S","ioi":
true,"act":"U","src":"CROX","price":"140","qty":"20","id":247697979505377323,"time":"1610600823886","mpid":"FINT","key":
"5VREII6NO0K4C0"},{"side":"B","ioi":true,"act":"U","src":"CROX","price":"123","qty":"456","id":247697979505377322,"time":
"1610600823886","mpid":"FINT","key":"5VREII6NO0K0C0"}],"type":"book"}
{"security":"AAPL","src":"CROX","price":"100","qty":"10","time":"1610626844292","type":"trade","matchid":"5XW4NNPLZZKH"}
{"request":[{"msg":"ibook","result":"OK","security":"AAPL"},{"msg":"itrade","result":"OK","security":"AAPL"}],"type":"subscribe"}

```

**SUBCRIBEHIGHLOW**

```
{"type":"subscribehighlow","security":"AAPL"}
{"openingprice":"100","security":"AAPL","highprice":"100","lowprice":
"100","prevcloseprice":"100","type":"highlow"}
{"result":"OK","security":"AAPL","type":"subscribehighlow"}
```

**TRADEHISTORY**

```
{"type":"tradehistory","security":"AAPL"}
{"result":"OK","security":"AAPL","data":[{"volume":"34","numoftrades":"2",
"lastttime":"1610578178456","blocktime":"1610578140000","highprice":"702",
"lowprice":"702","rec_no":1,"starttime":"1610578152233","lastprice":"702",
"startprice":"702"},{"volume":"56","numoftrades":"2","lastttime":"1610578259882",
"blocktime":"1610578200000","highprice":"702","lowprice":"702","rec_no":2,
"starttime":"1610578203880","lastprice":"702","startprice":"702"},{"volume":"8",
"numoftrades":"8","lastttime":"1610578270925","blocktime":"1610578260000",
"highprice":"100","lowprice":"100","rec_no":3,"starttime":"1610578270917",
"lastprice":"100","startprice":"100"},{"volume":"10","numoftrades":"1",
"lastttime":"1610626844761","blocktime":"1610626800000","highprice":"100",
"lowprice":"100","rec_no":4,"starttime":"1610626844761","lastprice":"100",
"startprice":"100"}],"total_rec":4,"type":"tradehistory"}
```

Where we use the message subscribeonopen, subscribe (book, trade), subscribehighlow:&#x20;

**MARKET STATISTICS MAIN PAGE OF PORTAL**

* Portal -> Market&#x20;
* Portal -> Market -> Trade&#x20;

**TRADE HISTORY:**&#x20;

* Portal -> Market -> Trade - Only Chart&#x20;
* AZ -> Market -> Daily Trade Summary Testing&#x20;

**ADDITIONAL**&#x20;

for assets (such as BTC, USD), there is summary of:

* `"totaldeposit"`
* `"totalwithdraw"`
* `"commamount"`

For tradable symbols (such as pairs), there is summary of "high","low","open","close" and the corresponding time (which is in EPOCH milliseconds),"`tradeqty`" for total qty and "`tradeamount`" for total amount.

For assets (such as BTC, USD), there is summary of "`totaldeposit`","`totalwithdraw`", in addition to "`commamount`"

**EXAMPLE OF STATISTICAL DATA QUERY**

```
{"totaltrades":9,"totalwithdraws":0,"details":[{"totalwithdraw":"0","commamount":"0.00929954",
"security":"BTC","totaldeposit":"0"},{"totalwithdraw":"0","commamount":"57.33","security":"USD",
"totaldeposit":"0"},{"totalwithdraw":"0","highprice":"9500","openprice":"9250","openpricetime":1594100407327,
"security":"BTCUSD","tradeamount":"28673.63995859","lowprice":"9000","tradeqty":"3.09985704","totaldeposit":"0",
"lowpricetime":1594117449631,"closeprice":"9001","closepricetime":1594117752683,"highpricetime":1594100620114}],
"totaldeposits":0,"totalcommtrades":18}
```

**TRADE SUMMARY QUERY**

“`querytradesummary`” can pass “date” or use “date” as filter.

ce":"45000","lowprice":"1","prevcloseprice":"176","type":"highlow"}

“`totaltrades`” is total number of trades. “`totalcommtrades`” is total number of commission trades. If it is not 0, then “details” field will carry an array of total commission by symbols.

**EXAMPLE OF COMMISSIONS TRADES**

```
{"result":"OK","data":[{"details":[],"totaltrades":0,"totalcommtrades"
:0,"tabletype":"DailySummary","rec_no":1,"date":"20200630"},{"details":[],"total
trades":0,"totalcommtrades":0,"tabletype":"DailySummary","rec_no":2,"date":"2020
0629"}],"type":"querytradesummary","total_rec":2}

```

**QUERY MULTI ORDERS**

**SAMPLE REQUEST MULTI ORDERS**

```
{“type”:”querymultiorders”, “fromtime”:”1555522543000”}
```

This is to query the orders for a user. Only administrator can specify “userid” field.

* `“fromtime”` field is optional, if set, it is to specify "`cutofftime`" to query&#x20;
* `“security”` field is optional, if set, it is to return trades for that security only.

**SAMPLE RESPONSE MULTI ORDERS**

```
{“result”:”OK”,”data”:[{“updtime”:”1562593041099”,”liveqty”:”0”,”refno
“:”5IF6Q7Y8LI8WA0”,”category”:”STAGE”,”execqty”:”0”,”price”:”100.59”,”side”:”B”,
“execamount”:”0”,”qty”:”100”,”rec_no”:1,”security”:”ZVZZT”,”type”:”order”},{“upd
time”:”1562593042339”,”liveqty”:”0”,”refno”:”5IF6Q7Y8LGPKA7”,”category”:”STAGE”,
“execqty”:”0”,”price”:”100.58”,”side”:”B”,”execamount”:”0”,”qty”:”100”,”rec_no”:
2,”security”:”ZVZZT”,”type”:”order”},{“updtime”:”1562593042339”,”liveqty”:”0”,”r
efno”:”5IF6Q7Y8LGPJA7”,”category”:”STAGE”,”execqty”:”0”,”price”:”100.57”,”side”:
“B”,”execamount”:”0”,”qty”:”100”,”rec_no”:3,”security”:”ZVZZT”,”type”:”order”},{
“updtime”:”1562593042339”,”liveqty”:”0”,”refno”:”5IF6Q7Y8LGPIA7”,”category”:”STA
GE”,”execqty”:”0”,”price”:”100.56”,”side”:”B”,”execamount”:”0”,”qty”:”100”,”rec_
no”:4,”security”:”ZVZZT”,”type”:”order”},{“updtime”:”1562593042339”,”liveqty”:”0
“,”refno”:”5IF6Q7Y8LGPHA7”,”category”:”STAGE”,”execqty”:”0”,”price”:”100.55”,”si
de”:”B”,”execamount”:”0”,”qty”:”100”,”rec_no”:5,”security”:”ZVZZT”,”type”:”order
“},{“updtime”:”1562593042339”,”liveqty”:”0”,”refno”:”5IF6Q7Y8LGPGA7”,”category”:
“STAGE”,”execqty”:”0”,”price”:”100.54”,”side”:”B”,”execamount”:”0”,”qty”:”100”,”
rec_no”:6,”security”:”ZVZZT”,”type”:”order”},{“updtime”:”1562593042339”,”liveqty
“:”0”,”refno”:”5IF6Q7Y8LGPFA7”,”category”:”STAGE”,”execqty”:”0”,”price”:”100.53”
,”side”:”B”,”execamount”:”0”,”qty”:”100”,”rec_no”:7,”security”:”ZVZZT”,”type”:”o
rder”},{“updtime”:”1562593042339”,”liveqty”:”0”,”refno”:”5IF6Q7Y8LGPEA7”,”catego
ry”:”STAGE”,”execqty”:”0”,”price”:”100.52”,”side”:”B”,”execamount”:”0”,”qty”:”10
0”,”rec_no”:8,”security”:”ZVZZT”,”type”:”order”},{“updtime”:”1562593042339”,”liv
eqty”:”0”,”refno”:”5IF6Q7Y8LGPDA7”,”category”:”STAGE”,”execqty”:”0”,”price”:”100
.51”,”side”:”B”,”execamount”:”0”,”qty”:”100”,”rec_no”:9,”security”:”ZVZZT”,”type
“:”order”},{“updtime”:”1562593042332”,”liveqty”:”0”,”refno”:”5IF6Q7Y8LGPCA7”,”ca
tegory”:”STAGE”,”execqty”:”0”,”price”:”100.5”,”side”:”B”,”execamount”:”0”,”qty”:
“100”,”rec_no”:10,”security”:”ZVZZT”,”type”:”order”}],”type”:”querymultiorders”,
“total_rec”:10}
```

**QUERY/RETRY DIGITAL ASSET DEPOSIT**

Only super user can use it.&#x20;

* `“blockhash”`, required, this is the blockchain hash from the blockchain deposit transaction `“security”`, required, corresponding crypto currency name.

**SAMPLE REQUEST RETRY CRYPTO DEPOSIT**

```
{“type”:“querymultiorders”}
```

**SAMPLE RESPONSE RETRY CRYPTO DEPOSIT**

```
{“amount”:”0.0001”,”result”:”OK”,”userid”:”BITTEST”,”blockhash”:”1c9a3
c059a17be3c6964e3be75ad05d34d44007c4536e7fa761c0f28dc6ce438”,”security”:”TBTC”,”
type”:”retrycryptodeposit”}

{“result”:”deposit already exist”,”blockhash”:”1c9a3c059a17be3c6964e3b
e75ad05d34d44007c4536e7fa761c0f28dc6ce438”,”security”:”TBTC”,”type”:”retrycrypto

```

**LAST SALE HISTORY**

This is to query the matched trades for a symbol.

**SAMPLE REQUEST GET LAST SALE DATA**

```
{"type":"lshistory","security":"FI","starttime":1697688000000,"endtime":1697728774546}
```

**SAMPLE RESPONSE GET LAST SALE DATA**

```
{"result":"OK","security":"FI",
"data":[
{"security":"FI","rec_no":1,"execprice":"11","time":"1697728761506","execqty":"11","matchid":"6PY00FJN95KI","status":"Open"}
],
"total_rec":1,"starttime":1697688000000,"endtime":1697728774546,"type":"lshistory"}
```

**TRADE REPORTS**

This is to query for trade reports if you have reporting enabled.

**SAMPLE REQUEST TO SEE WHAT REPORTS ARE AVAILIBLE**

```
{type: "getavailablereports"}
```

**SAMPLE RESPONSE TO SEE WHAT REPORTS ARE AVAILIBLE**

```
{"result":"OK","type":"getavailablereports","list":["FI_DAILY.txt.20230718"]}
```

**SAMPLE REQUEST TO DOWNLOAD REPORT**

```
{type: "getreportfile",filename:"FI_DAILY.txt.20230718"}
```

**SAMPLE RESPONSE TO DOWNLOAD REPORT**

```
{"result":"OK","filename":"FI_DAILY.txt.20230718",
"data":"SOME BASE64 ARRAY BUFFER",
"moredata":false,"type":"getreportfile"}
```

If `"moredata"` is true you need to concat the data reponses for the whole file

Javascript code to concat and get file:

```javascript
const { decode } = require("base64-arraybuffer")
...
    let fileData = [];
    ws.on("message", function requestHandler(data) {
      data = JSON.parse(data);
        if (data.result == "OK") {
          if (data.moredata === true) {
            fileData.push(decode(data.data));
          } else {
            // fileData is an Array of ArrayBuffers
            fileData.push(decode(data.data));
            const arrayOfBuffers = []
            for (let index = 0; index < fileData.length; index++) {
              const currentArrayBuffer = fileData[index];
              const currentBuffer = Buffer.from(currentArrayBuffer);
              arrayOfBuffers.push(currentBuffer);
            }
            ws.removeEventListener("message",arguments.callee);
            return (Buffer.concat(arrayOfBuffers));
          }
        }
      }
```
