---
# System prepended metadata

title: l2a exchange itch/ouch trading API

---

# l2a exchange itch/ouch trading API

## Идеальное апи на взгляд маркетмейкера
https://hackernoon.com/the-ideal-crypto-trading-api-b1bbb2675875
Нужно описать сервисное апи, ответственное за авторизацию и передачу текстовых сообщений. Это апи не чувствительно к задержкам и имеет сложный протокол сериализации тк оперирует типами нефиксировонной длиннны. 

Также нужно придумать груповое добавление/удаление ордеров.

Фид для пользователя без подписей. 

Подписи биржи только по запросу, те никакого бродкаста подписанных сообщений(это есть ресурсы). В будущем может будет фид подписанных сообщений.  

## Мультимаркет

**спот**:
мейкер - ставит лимит и ждет
тейкер - ставит маркет и забирает

**своп**:
спот + открытие/закрытие позиции

**Вейл**:
мейкер - ставит лимит и ждет
тейкер - ставит оффер и ждет
мейкер - апрувит 

для поддержки всех площадок в одном апи надо:

для createOrder значащие  поля:

1. type - open/close; short/long; limit/market; etc.
2. price - price of order
3. qty - quantity of order
4. instrument_id - market/pair ID
5. order_sub_type - FOK/IOC etc

для выставления плеча в случае свопа - используется в паре сметодом SetLeverage, устанавливающим плечо на пару и  сторону 
1. instrument_id	-	market/pair ID
2. leverage	- leverage level from 1-100
3. side	- Side: 1.FIXED-LONG 2.FIXED-SHORT 3.CROSSED

## Транспорт

трейдер постит бирже рестом, получает отчет через WS 

**Endpoints**
--non--



## сообщения 
> **REST+WS MIX**
0. A - Auth User Message
1. S - Get Signature Message
2. O - Create Order Message
3. U - Update Order Message
4. C - Cancel Order Message
5. R - Reject Order Message
6. L - Set leverage Order Message
 
> **WS FEEDS ONLY**
0. E - Exetued Order Message
1. S - Order Book Lvl2 Message Feed
2. T - Order Book Lvl3 Message Feed 
## Auth User Message
**POST REQUEST** 
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “A” |  “A” = Auth Session Message ID. |
| Timestamp | 8 | int | Timestamp in nanoseconds |
| Signature | 65 | int | Signature of message | 
**POST RESPONSE**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “a” |  “a” = Auth Session Message ID. |
| Timestamp_end | 8 | int | Timestamp in nanoseconds of expiration of session |
| Account_Id | 4 | int |  Assigned by Auth service User ID |
| Signature | 65 | int | Signature of message | 

## Get Signature Message
**POST REQUEST** 
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “S” |  “S” = Get Signature Message Id. |
| Instrument_id | 2 | int | market/pair ID |
| Order Reference Number | 8 | int | unique order reference number. |
| Account_Id | 4 | int |  Assigned by Auth service User ID |
| Signature | 65 | int | Signature of message | 

> Instrument_id = market ID, for close signature = 65535 

**POST RESPONSE**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “s” |  “s” = Get Signature Message id. |
| Timestamp | 8 | int | Timestamp of order in nanoseconds |
| Instrument_id | 2 | int | market/pair ID |
| blockchain_id | 1 | int | blockchain ID |
| SignatureL2 | 65 | int | Signature of L2 oracle  | 
| SignatureTaker | 65 | int | Signature of Taker order, if exist | 
| SignatureMaker | 65 | int | Signature of Maker order, if exist | 

## Create Order Message
**POST REQUEST** 
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “O” |  “O” = Create Order Message ID. |
| Instrument_id | 2 | int | market/pair ID |
| Order_ID | 4 | int | unique user generated order id. must be uniq per user trading sesion. |
| Order_type | 1 | int | 0-buy limit/1- buy market/ 2- sell limit / 3-sell market |
| Price | 4 | int |  price for limit order, for market = 0x7FFFFFFF |  
| Quantity | 8 | int | quantity of order |
| Order_Sub_Type | 1 | int | order sub type FOC/IOC etc |
| Account_Id | 4 | int |  Assigned by Auth service User ID |
| Signature | 65 | int | Signature of message | 
**WS RESPONSE**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “o” |  “o” = Create Order Message Id. |
| Timestamp | 8 | int | Timestamp of order in nanoseconds |
| Instrument_id | 2 | int | market/pair ID |
| Order_ID | 4 | int | unique user generated order id. must be uniq per user trading sesion. |
| Order Reference Number | 8 | int | unique order reference number |  
| Order_type | 1 | int | 0-limit/1-market |
| Price | 4 | int |  price for limit order, for market = 0x7FFFFFFF |  
| Quantity | 8 | int | quantity of order |
| Order_Sub_Type | 1 | int | order sub type FOC/IOC etc |

**Order types**
> spot

0-buy limit
1-buy market
2-sell limit 
3-sell market 
> swap

4-open long 
5-open short 
6-close long 
7-close short
> whale

8 - set offer
9 - set bid
10 - swap

## Update Order Message

**POST REQUEST** 
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “U” |  “U” = Update Order Message Id. |
| Instrument_id | 2 | int | market/pair ID |
| Order Reference Number | 8 | int | unique order reference number. |
| Price | 4 | int |  price for limit order, for market = 0x7FFFFFFF |  
| Quantity | 8 | int | quantity of order |
| Account_Id | 4 | int |  Assigned by Auth service User ID |
| Signature | 65 | int | Signature of message | 
**WS RESPONSE**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “u” |  “u” = Update Message Id. |
| Timestamp | 8 | int | Timestamp of order in nanoseconds |
| Order Reference Number | 8 | int | unique order reference number |  
| Order_type | 1 | int | 0-limit/1-market |
| Price | 4 | int |  price for limit order, for market = 0x7FFFFFFF |  
| Quantity | 8 | int | quantity of order |
| Instrument_id | 2 | int | market/pair ID |
| Order_Sub_Type | 1 | int | order sub type FOC/IOC etc |

## Cancel Order Message
**POST REQUEST** 
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “C” |  “C” = Cancel Order Message Id. |
| Instrument_id | 2 | int | market/pair ID |
| Order Reference Number | 8 | int | unique order reference number. |
| Account_Id | 4 | int |  Assigned by Auth service User ID |
| Signature | 65 | int | Signature of message | 
**WS RESPONSE**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “c” |  “c” = Canceled Order Message Id. |
| Timestamp | 8 | int | Timestamp of order in nanoseconds |
| Instrument_id | 2 | int | market/pair ID |
| Order Reference Number | 8 | int | unique order reference number |  
| Quantity | 8 | int | quantity of order |

## Set leverage Order Message

**POST REQUEST** 
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “L” |  “L” = Set leverage Order Message Id. |
| Instrument_id | 2 | int | market/pair ID |
| leverage | 1 | int |  leverage level from 1-100 |
| side | 1 | int | Side: 1.FIXED-LONG 2.FIXED-SHORT 3.CROSSED |
| Account_Id | 4 | int |  Assigned by Auth service User ID |
| Signature | 65 | int | Signature of message | 

**WS RESPONSE**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “l” |  “l” = Set leverage Order Message Id. |
| Instrument_id | 2 | int | market/pair ID |
| leverage | 1 | int |  leverage level from 1-100 |
| side | 1 | int | Side: 1.FIXED-LONG 2.FIXED-SHORT 3.CROSSED |
| Account_Id | 4 | int |  Assigned by Auth service User ID |






# WEBSOCKET FEED REQUEST

| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “E/H/S/T” | Feed msg type |
| Instrument_id | 2 | int | market/pair ID |
| Account_id | 4 | int |  Assigned by Auth service User ID |
| Signature | 65 | int | Signature of message | 

“E” = Executed Message feed. 
“H” = Auth user report messages feed - broadcast last signed msgs for every channel, after live feed forCreate/Delete/Update/Reject response messages.   
“S” =  Order Book Lvl2 Message feed. 
"T" = Order Book Lvl3 Message feed.

## Reject Order Message
**WS RESPONSE**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “R” |  “R” = Reject Order Message Id. |
| Timestamp | 8 | int | Timestamp of order in nanoseconds |
| Order_ID | 4 | int | unique user generated order id. must be uniq per user trading sesion. |
| Instrument_id | 2 | int | market/pair ID |
| Reason | 1 | int | Reason the order was rejected | 

0 - The secboard, instrument, board or market is not tradeable.
1 - Invalid quantity or quantity exceeds maximum limit.
2 - Invalid orderbook identifier.
3 - The order is not allowed at this time.
4 - Invalid price.
5 - Invalid minimum quantity.
6 - Invalid Order Type. For example, the Time In Force value is not supported in current trading session.
7 - Unknown. Contact support for further information.


## Execute Order Message Feed
**WS FEED**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “E” |  “E” = Executed Message Id. |
| Timestamp | 8 | int | Timestamp of order in nanoseconds |
| Instrument_id | 2 | int | market/pair ID |
| Order Reference Number | 8 | int | unique taker order reference number |
| Maker Reference Number | 8 | int | unique maker order reference number |
| Executed Price | 4 | int |  price for limit order |  
| Executed Quantity | 8 | int | quantity of order |

## Order Book Lvl2 Message Feed
**WS FEED**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “S” |  “S” = Order Book Lvl2 Message Id. |
| Price | 4 | int |  price for limit order |  
| Quantity | 8 | int | quantity of order |
| Side | 1 | int | 0-buy/1-sell |
| num-orders | 2 | int | number of orders |  

> after complite in feed will broadcast E/C/U/O messages
## Order Book Lvl3 Message Feed
**WS FEED**
| descrption | length, bytes | value/type | notes | 
| -------- | -------- | -------- | -------- |
| Message_type |  1 | “T” |  “T” = Order Book Lvl3 Message Id. |
| Price | 4 | int |  price for limit order |  
| Quantity | 8 | int | quantity of order |
| Side | 1 | int | 0-buy/1-sell |
| Order Reference Number | 8 | int | unique order reference number |  
> after complite in feed will broadcast E/C/U/O messages

