Skip to content

Commit

Permalink
feat: add tif and default account
Browse files Browse the repository at this point in the history
  • Loading branch information
simoneb committed Mar 4, 2024
1 parent fffdce7 commit becaf75
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/parsers/wsp.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ini from 'ini'
import { Table, TableHead, TableBody, TableRow, TableCell } from '@mui/material'
import { hex2a } from '../util'

const columns = [
{
Expand All @@ -20,6 +21,24 @@ const columns = [
return /true/i.test(value) ? '✅' : '❌'
}
},
{
field: 'tif',
headerName: 'TIF',
valueFormatter({ value }) {
switch (value) {
case 0:
return 'DAY'
case 1:
return 'GTC'
case 2:
return 'IOC'
}
}
},
{
field: 'defaultAccount',
headerName: 'Default Account'
},
{
field: 'contracts',
headerName: 'Contracts',
Expand Down Expand Up @@ -139,10 +158,27 @@ export async function handle(file) {
) === 0
)

const brokerPluginAdditionalInfo =
parsed[
`Wsp\\Window_${windowId}\\ChartManager\\Strategy\\MCBroker\\MCBrokerObject\\PluginsProxies\\MCPluginProxiesCollection\\Item_0\\Proxy\\MCPluginProxy\\AdditionalInfo`
]

const additionalInfo = ini.parse(
hex2a(
Object.keys(brokerPluginAdditionalInfo)
.filter(k => !['PluginData', '{', '}'].includes(k))
.join(' ')
.split(' ')
.join('')
)
)

return {
strategyName: parsed[strategyData].StrategyName,
symbolName: parsed[strategyData].SymbolName,
autoTrading: parsed[strategyData].ATOn,
tif: additionalInfo.AdditionalsParams.TIF,
defaultAccount: additionalInfo.AdditionalsParams.DefaultAccount,
charts,
contracts: parsed[contractsKey]?.Value
}
Expand Down
9 changes: 9 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ export function utf8_to_b64(str) {
export function b64_to_utf8(str) {
return decodeURIComponent(escape(window.atob(str)))
}

export function hex2a(_hex) {
var hex = _hex.toString() //force conversion
var str = ''
for (var i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16))
}
return str
}

0 comments on commit becaf75

Please sign in to comment.