fix-client
Version:
A minimalist FIX API client
35 lines (30 loc) • 939 B
JavaScript
const directions = {
'BUY': '1',
'SELL': '2',
}
const fixSides = {
'1': 'BUY',
'2': 'SELL',
}
const getDirectionfromFixId = (fixSideID, type) =>
fixSideID === 'BUY' || fixSideID === 'SELL' ? `${fixSideID}-${type}` : `${fixSides[fixSideID]}-${type}`
const getFixIdFromDirection = (direction) =>
direction === '1' || direction === '2' ? direction : directions[direction]
const getDirectionAndOrderQty = ({ longQty, shortQty }) => {
const longQtyInt = parseInt(longQty)
const shortQtyInt = parseInt(shortQty)
const directionAndOrderQty =
longQtyInt > 0
&& shortQtyInt === 0
&& { side: '1', direction: 'BUY', orderQty: longQtyInt }
||
shortQtyInt > 0
&& longQtyInt === 0
&& { side: '2', direction: 'SELL', orderQty: shortQtyInt }
return directionAndOrderQty
}
module.exports = {
getDirectionAndOrderQty,
getDirectionfromFixId,
getFixIdFromDirection
}