Skip to content

Commit

Permalink
strategy parameters on order blotter
Browse files Browse the repository at this point in the history
ettec committed Oct 22, 2020
1 parent d7d8dbf commit 38d333d
Showing 7 changed files with 126 additions and 18 deletions.
60 changes: 55 additions & 5 deletions react/opentp-client/src/common/grpcUtilities.tsx
Original file line number Diff line number Diff line change
@@ -6,11 +6,61 @@ export function getGrpcErrorMessage( error : Error, prepend?: string) : string {
prepend = prepend + ": "
}

let grpErrorCodeAsStr = error.message
switch (error.code) {
case StatusCode.PERMISSION_DENIED:
return prepend + "Permission Denied"

default:
return prepend + error.message
case StatusCode.ABORTED:
grpErrorCodeAsStr = "Aborted"
break
case StatusCode.ALREADY_EXISTS:
grpErrorCodeAsStr = "Already Exists"
break
case StatusCode.CANCELLED:
grpErrorCodeAsStr = "Cancelled"
break
case StatusCode.DATA_LOSS:
grpErrorCodeAsStr = "Data Loss"
break
case StatusCode.DEADLINE_EXCEEDED:
grpErrorCodeAsStr = "Deadline Exceeded"
break
case StatusCode.FAILED_PRECONDITION:
grpErrorCodeAsStr = "Failed Precondition"
break
case StatusCode.INTERNAL:
grpErrorCodeAsStr = "Internal"
break
case StatusCode.INVALID_ARGUMENT:
grpErrorCodeAsStr = "Invalid Argument"
break
case StatusCode.NOT_FOUND:
grpErrorCodeAsStr = "Not Found"
break
case StatusCode.OK:
grpErrorCodeAsStr = "OK"
break
case StatusCode.OUT_OF_RANGE:
grpErrorCodeAsStr = "Out Of Range"
break
case StatusCode.PERMISSION_DENIED:
grpErrorCodeAsStr = "Permission Denied"
break
case StatusCode.RESOURCE_EXHAUSTED:
grpErrorCodeAsStr = "Resource Exhausted"
break
case StatusCode.UNAUTHENTICATED:
grpErrorCodeAsStr = "Unauthenticated"
break
case StatusCode.UNAVAILABLE:
grpErrorCodeAsStr = "Unavailable"
break
case StatusCode.UNIMPLEMENTED:
grpErrorCodeAsStr = "Unimplemented"
break
case StatusCode.UNKNOWN:
grpErrorCodeAsStr = "Unknown Host"
break

}

return prepend + grpErrorCodeAsStr
}
4 changes: 3 additions & 1 deletion react/opentp-client/src/common/strategydescriptions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Destinations } from "./destinations"

export function getStrategyDisplayName(mic: string) : string | undefined {
switch(mic) {
case "XVWAP":
case Destinations.VWAP:
return "VWAP STRATEGY"
}

2 changes: 1 addition & 1 deletion react/opentp-client/src/components/Container/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Alignment, Button, Icon, Menu, MenuItem, Navbar, Popover, Position } from "@blueprintjs/core";
import FlexLayout, { Layout, Model, TabNode } from "flexlayout-react";
import "flexlayout-react/style/dark.css";
import { Error, StatusCode } from "grpc-web";
import { Error } from "grpc-web";
import React, { ReactNode } from 'react';
import log from 'loglevel';
import { ClientConfigServiceClient } from "../../serverapi/ClientconfigserviceServiceClientPb";
2 changes: 1 addition & 1 deletion react/opentp-client/src/components/Login/Login.tsx
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ export default class Login extends React.Component<Props, State> {
}

if (this.serverUrl.endsWith("localhost:3000")) {
this.serverUrl = "http://127.0.0.1:32054" // for local dev, change this to point at your otp services cluster
this.serverUrl = "http://127.0.0.1:32509" // for local dev, change this to point at your otp services cluster
}

log.info("Connecting to services at:" + this.serverUrl)
Original file line number Diff line number Diff line change
@@ -79,7 +79,8 @@ export default abstract class OrderBlotter<P extends OrderBlotterProps , S exten
<Column key="owner" id="owner" name="Owner" cellRenderer={this.renderOwner} />,
<Column key="errorMsg" id="errorMsg" name="Error" cellRenderer={this.renderErrorMsg} />,
<Column key="version" id="version" name="Version" cellRenderer={this.renderVersion} />,
<Column key="createdby" id="createdby" name="Created By" cellRenderer={this.renderCreatedBy}/>
<Column key="createdby" id="createdby" name="Created By" cellRenderer={this.renderCreatedBy}/>,
<Column key="parameters" id="parameters" name="Parameters" cellRenderer={this.renderParameters}/>
];
}

@@ -96,6 +97,7 @@ export default abstract class OrderBlotter<P extends OrderBlotterProps , S exten
private renderDestination = (row: number) => <Cell>{Array.from(this.state.orders)[row]?.getDestination()}</Cell>;
private renderVersion = (row: number) => <Cell>{Array.from(this.state.orders)[row]?.version}</Cell>;
private renderOwner = (row: number) => <Cell>{Array.from(this.state.orders)[row]?.owner}</Cell>;
private renderParameters = (row: number) => <Cell>{Array.from(this.state.orders)[row]?.parameters}</Cell>;

private renderStatusHeader = (row: number) => {

25 changes: 23 additions & 2 deletions react/opentp-client/src/components/OrderBlotter/OrderView.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import { Order, Side, OrderStatus } from '../../serverapi/order_pb';
import { Listing } from '../../serverapi/listing_pb';
import { ListingService } from '../../services/ListingService';
import { getStrategyDisplayName } from '../../common/strategydescriptions';
import { Destinations } from '../../common/destinations';
import { VwapParameters } from '../OrderTicket/Strategies/VwapParams/VwapParamsPanel';

export interface Filter {
id(): string
@@ -110,6 +112,7 @@ export class OrderView {
owner: string;
createdBy: string;
errorMsg: string;
parameters: string;

constructor(order: Order) {
this.id = ""
@@ -124,6 +127,7 @@ export class OrderView {
this.owner = "";
this.errorMsg = "";
this.createdBy = "";
this.parameters = "";
this.setOrder(order)
}

@@ -163,13 +167,30 @@ export class OrderView {
this.owner = order.getOwnerid()
this.errorMsg = order.getErrormessage()
this.createdBy = order.getRootoriginatorref()
this.parameters = this.getParametersDisplayString(order)

}

getOrder(): Order {
return this.order
}

getParametersDisplayString(order: Order): string {
if (order.getDestination() !== "" && order.getExecparametersjson() !== "") {


switch (order.getDestination()) {
case Destinations.VWAP:
// order.getDestination() + ":" + order.getExecparametersjson()
let p = VwapParameters.fromJsonString(order.getExecparametersjson()) as VwapParameters
return p.toDisplayString()
}
}


return ""
}

getStatusString(status: OrderStatus) {

switch (status) {
@@ -186,8 +207,8 @@ export class OrderView {
}

getDestination(): string | undefined {
if( this.listing?.getMarket()?.getMic() ) {
if( this.destination === this.listing?.getMarket()?.getMic() ) {
if (this.listing?.getMarket()?.getMic()) {
if (this.destination === this.listing?.getMarket()?.getMic()) {
return this.listing?.getMarket()?.getName()
}
}
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ import * as React from "react";
import { Checkbox, Label, NumericInput } from "@blueprintjs/core";
import { TimePicker, TimePrecision } from "@blueprintjs/datetime";
import { StrategyPanel } from "../../OrderTicket";
import { Destinations } from "../../../../common/destinations";


export interface Props {
children?: React.ReactNode
@@ -40,17 +42,19 @@ export default class VwapParamsPanel extends React.Component<Props, State> imple
}

getDestination(): string {
return "XVWAP"
return Destinations.VWAP
}


getParamsString(): string {

var params : VwapParameters;
if (this.state.setBuckets) {
return JSON.stringify(new VwapParameters(Math.floor(this.startTime.getTime() / 1000), Math.floor(this.endTime.getTime() / 1000), this.buckets))
params = new VwapParameters(Math.floor(this.startTime.getTime() / 1000), Math.floor(this.endTime.getTime() / 1000), this.buckets)
} else {
return JSON.stringify(new VwapParameters(Math.floor(this.startTime.getTime() / 1000), Math.floor(this.endTime.getTime() / 1000)))
params = new VwapParameters(Math.floor(this.startTime.getTime() / 1000), Math.floor(this.endTime.getTime() / 1000))
}
return params.toJsonString()
}

render() {
@@ -88,10 +92,7 @@ export default class VwapParamsPanel extends React.Component<Props, State> imple
}





class VwapParameters {
export class VwapParameters {
utcStartTimeSecs: number;
utcEndTimeSecs: number;
buckets?: number;
@@ -103,6 +104,38 @@ class VwapParameters {
this.utcEndTimeSecs = utcEndTimeSecs;
this.buckets = buckets;
}



static fromJsonString(jsonString : string) : VwapParameters {
let p = JSON.parse(jsonString) as VwapParameters

return new VwapParameters(p.utcStartTimeSecs, p.utcEndTimeSecs, p.buckets)
}


toJsonString() : string {
return JSON.stringify(this)
}

toDisplayString() : string {

var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
d.setUTCSeconds(this.utcStartTimeSecs);


let result = "Start:" + d.toLocaleTimeString()
d = new Date(0);
d.setUTCSeconds(this.utcEndTimeSecs);
result += " End:" + d.toLocaleTimeString()

if( this.buckets ) {
result += " Buckets:" + this.buckets
}

return result
}

}


0 comments on commit 38d333d

Please sign in to comment.