# SIMPLIFIED ORDERS

**1. Limit orders**

* **HTTP Request Type:** POST
* **Route:** `/firestapi/orders/limit`
* **URL / Body Parameters:**
  * **Required:**
    * `security`: "TESTJ"
    * `side`: "B" (Buy) or "S" (Sell)
    * `qty`: The quantity to buy or sell.
    * `price`: The unit price.
    * `ordertype`: "LMT" (Limit), "POST" (Post Only), "ICEBERG", "STOP"
    * If `ordertype:"ICEBERG", displayqty` is required.
    * If `ordertype:"STOP", stopprice` is required.
    * `tif`: "GTC" (Good Till Cancelled), "IOC" (Immediate Or Cancel), "GTT" (Good Till Time), "FOK" (Fill Or Kill), "DAY" (Day)
    * `tif: "GTT"`  If set to GTT we also need input `exptime`
* **Info:** Adds a new order.
* **HTTPS Body Example:**

json

```json
{
  "security": "TESTJ",
  "side": "B",
  "qty": 100,
  "price": 50,
  "ordertype": "LMT",
  "tif": "GTC"
}

```

WS Example:

json

```json
{
  "type": "addorder",
  "security": "TESTJ",
  "side": "B",
  "qty": 100,
  "price": 50,
  "ordertype": "LMT",
  "tif": "GTC",
}

```

#### Example Implementation in Express.js

Here's an example of how you might implement these endpoints in an Express.js application:

javascript

```javascript
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');

const app = express();

app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({
  secret: 'your_secret_key',
  resave: false,
  saveUninitialized: true,
  cookie: { secure: true } // Use secure cookies in production
}));

// Dummy order data for demonstration purposes
const orders = [
  { refno: '1', userid: 'runzhuo.li@fundamentalinteractions.com', security: 'TESTN', side: 'B', qty: 100, price: 50, ordertype: 'LMT', tif: 'GTC', timestamp: 1671195975792 },
  // Add more orders as needed
];


// Add New Order
app.post('/firestapi/orders/limit', (req, res) => {
  const { security, side, qty, price, ordertype, tif } = req.body;

  // Perform necessary validations here
  const newOrder = {
    userid: req.session.userid, 
    // When connected to the websocket we do not use userid but token
    security,
    side,
    qty,
    price,
    ordertype,
    tif,
  };

  orders.push(newOrder);
  res.status(201).json(newOrder);
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

```

This example sets up the specified routes using Express.js and handles retrieving user orders, retrieving an order by reference number, and adding new orders. It includes necessary validations and error handling for the endpoints.

**2. Market orders**

* **HTTP Request Type:** POST
* **Route:** `/firestapi/orders/market`
* **URL / Body Parameters:**
  * **Required:**
    * `security`: "TESTJ"
    * `side`: "B" (Buy) or "S" (Sell)
    * `qty`: The quantity to buy or sell.
    * `price`: The unit price.
* **Info:** Adds a new order.
* **HTTPS Body Example:**

json

```json
{
  "security": "TESTJ",
  "side": "B",
  "qty": 100,
  "price": 50,
}

```

WS Example:

json

```json
{
  "type": "addorder",
  "security": "TESTJ",
  "side": "B",
  "qty": 100,
  "price": 50,
  "ordertype": "MKT",
  "tif": "GTC"
}

```

#### Example Implementation in Express.js

Here's an example of how you might implement these endpoints in an Express.js application:

javascript

```javascript
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');

const app = express();

app.use(bodyParser.json());
app.use(cookieParser());
app.use(session({
  secret: 'your_secret_key',
  resave: false,
  saveUninitialized: true,
  cookie: { secure: true } // Use secure cookies in production
}));

// Dummy order data for demonstration purposes
const orders = [
  { refno: '1', userid: 'runzhuo.li@fundamentalinteractions.com', security: 'TESTN', side: 'B', qty: 100, price: 50, ordertype: 'LMT', tif: 'GTC', timestamp: 1671195975792 },
  // Add more orders as needed
];


// Add New Order
app.post('/firestapi/orders/market', (req, res) => {
  const { security, side, qty, price } = req.body;

  // Perform necessary validations here
  const newOrder = {
    userid: req.session.userid, 
    // When connected to the websocket we do not use userid but token
    security,
    side,
    qty,
    price,
    ordertype: "MKT",
    tif: "GTC",
  };

  orders.push(newOrder);
  res.status(201).json(newOrder);
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

```

This example sets up the specified routes using Express.js and handles retrieving user orders, retrieving an order by reference number, and adding new orders. It includes necessary validations and error handling for the endpoints.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fundamental-interactions-inc.gitbook.io/finteractions.com-restapi/simplified-orders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
