Skip to content

Commit

Permalink
fix(examples) - Removing fonst
Browse files Browse the repository at this point in the history
  • Loading branch information
lilla28 committed Sep 6, 2024
1 parent ec3f951 commit 6f3a5d2
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,185 +212,187 @@ export class MarketWatchComponent implements OnInit, OnDestroy{
}

async ngOnInit() {
this.subject.next(
{
Symbol: undefined,
DataSource: [...ELEMENT_DATA]
});

try {
this.channel = await window.fdc3.getOrCreateChannel('tradeIdeasChannel');
const listener = await this.channel.addContextListener("fdc3.trade", async(context, metadata) => {
const data = context['data'];
let symbols = ELEMENT_DATA.filter(x => x.Symbol == data.symbol && x.Children?.length && x.Children?.length > 0);
const topic: string = "fdc3." + data.symbol + "." + data.trader;

if (!symbols || symbols.length == 0) {
await this.channel!.broadcast(
{
type: topic,
result: {
success: false,
action: "BUY",
error: "No symbol found."
}
});

return;
}

if (data.action === 'BUY') {
const sumQuantity = symbols.reduce((sum, current) => {
if (current.Children && current.Children.length > 0) {
let s: number = current.Children.reduce((t, currentSymbol) => {
if(currentSymbol.AskSize) {
return t + currentSymbol.AskSize;
}
return t + 0;
}, 0);

return sum + s;
}
return sum + 0;
}, 0);

window.addEventListener('fdc3Ready', async() => {
this.subject.next(
{
Symbol: undefined,
DataSource: [...ELEMENT_DATA]
});

if (sumQuantity < data.quantity) {
try {
this.channel = await window.fdc3.getOrCreateChannel('tradeIdeasChannel');
const listener = await this.channel.addContextListener("fdc3.trade", async(context, metadata) => {
const data = context['data'];
let symbols = ELEMENT_DATA.filter(x => x.Symbol == data.symbol && x.Children?.length && x.Children?.length > 0);
const topic: string = "fdc3." + data.symbol + "." + data.trader;

if (!symbols || symbols.length == 0) {
await this.channel!.broadcast(
{
type: topic,
result: {
success: false,
action: "BUY",
error: "Too much ticks were requested; not enough symbols are available on the target."
error: "No symbol found."
}
});

return;
}

let price: number = 0;
let size = data.quantity;
for (let element of ELEMENT_DATA) {
if (size == 0) {
break;
}

if (element.Symbol != data.symbol || !element.Children || element.Children.length <= 0) {
continue;
}

if (element.Children.at(0) && element.Children.at(0)?.AskSize && element.Children.at(0)!.AskSize! >= data.quantity) {
element.Children.at(0)!.AskSize! = element.Children.at(0)!.AskSize! - data.quantity;
element.Children.at(0)!.LastTrade = data.timestamp;
price = element.Children.at(0)!.AskPrice != undefined ? element.Children.at(0)!.AskPrice! * data.quantity : 0;
size = 0;

await this.channel!.broadcast({
type: topic,
result: {
success: true,
action: "BUY",
tradePrice: price
}
});

break;
if (data.action === 'BUY') {
const sumQuantity = symbols.reduce((sum, current) => {
if (current.Children && current.Children.length > 0) {
let s: number = current.Children.reduce((t, currentSymbol) => {
if(currentSymbol.AskSize) {
return t + currentSymbol.AskSize;
}
return t + 0;
}, 0);

return sum + s;
}
return sum + 0;
}, 0);


if (sumQuantity < data.quantity) {
await this.channel!.broadcast(
{
type: topic,
result: {
success: false,
action: "BUY",
error: "Too much ticks were requested; not enough symbols are available on the target."
}
});

return;
}

for (let innerElement of element.Children) {
if (innerElement.Symbol != data.symbol) {

let price: number = 0;
let size = data.quantity;
for (let element of ELEMENT_DATA) {
if (size == 0) {
break;
}

if (element.Symbol != data.symbol || !element.Children || element.Children.length <= 0) {
continue;
}

if (innerElement.AskSize && innerElement.AskSize >= size) {
price = price + size * (innerElement.AskPrice == undefined ? 0 : innerElement.AskPrice);
innerElement.AskSize = innerElement.AskSize - size;
innerElement.LastTrade = data.timestamp;
if (element.Children.at(0) && element.Children.at(0)?.AskSize && element.Children.at(0)!.AskSize! >= data.quantity) {
element.Children.at(0)!.AskSize! = element.Children.at(0)!.AskSize! - data.quantity;
element.Children.at(0)!.LastTrade = data.timestamp;
price = element.Children.at(0)!.AskPrice != undefined ? element.Children.at(0)!.AskPrice! * data.quantity : 0;
size = 0;

await this.channel!.broadcast({
type: topic,
result: {
success: true,
action: "BUY",
tradePrice: price
}
});

break;
} else if (innerElement.AskSize && innerElement.AskSize < size && innerElement.AskSize != 0) {
price = price + innerElement.AskSize * (innerElement.AskPrice == undefined ? 0 : innerElement.AskPrice);
size = size - innerElement.AskSize;
innerElement.AskSize = 0;
innerElement.LastTrade = data.timestamp;
}

for (let innerElement of element.Children) {
if (innerElement.Symbol != data.symbol) {
continue;
}

if (innerElement.AskSize && innerElement.AskSize >= size) {
price = price + size * (innerElement.AskPrice == undefined ? 0 : innerElement.AskPrice);
innerElement.AskSize = innerElement.AskSize - size;
innerElement.LastTrade = data.timestamp;
size = 0;
break;
} else if (innerElement.AskSize && innerElement.AskSize < size && innerElement.AskSize != 0) {
price = price + innerElement.AskSize * (innerElement.AskPrice == undefined ? 0 : innerElement.AskPrice);
size = size - innerElement.AskSize;
innerElement.AskSize = 0;
innerElement.LastTrade = data.timestamp;
}
}
}

await this.channel!.broadcast({
type: topic,
result: {
success: true,
action: "BUY",
tradePrice: price
}
});

this.subject.next(
{
Symbol: data.symbol,
DataSource: ELEMENT_DATA
});

return;
}

await this.channel!.broadcast({
type: topic,
result: {
success: true,
action: "BUY",
tradePrice: price
//It's selling the symbols - probably on the highest seller value (as it's not defined in this poc)
let symbolElement: SymbolElement | undefined;

ELEMENT_DATA.forEach((symbol) => {
if (symbol.Symbol != data.symbol) {
return;
}
if (symbol.Children && symbol.Children.length > 0) {
symbolElement = symbol.Children.reduce((prev, current) => {
if (prev.BidPrice && current.BidPrice
&& prev.BidPrice > current.BidPrice) {
return prev;
}

return current;
});
}
});

this.subject.next(

if(symbolElement) {
symbolElement.BidSize = symbolElement.BidSize + data.quantity;
symbolElement.LastTrade = data.timestamp;
await this.channel!.broadcast(
{
type: topic,
result: {
success: true,
action: "SELL",
}
});
this.subject.next(
{
Symbol: data.symbol,
DataSource: ELEMENT_DATA
DataSource: [...ELEMENT_DATA]
});

return;
}

//It's selling the symbols - probably on the highest seller value (as it's not defined in this poc)
let symbolElement: SymbolElement | undefined;

ELEMENT_DATA.forEach((symbol) => {
if (symbol.Symbol != data.symbol) {
return;
}
if (symbol.Children && symbol.Children.length > 0) {
symbolElement = symbol.Children.reduce((prev, current) => {
if (prev.BidPrice && current.BidPrice
&& prev.BidPrice > current.BidPrice) {
return prev;
} else {
await this.channel!.broadcast(
{
type: topic,
result: {
success: false,
action: "SELL",
error: "Trader is not able to place its symbol for selling."
}

return current;
});
});
}

return;
});

if(symbolElement) {
symbolElement.BidSize = symbolElement.BidSize + data.quantity;
symbolElement.LastTrade = data.timestamp;
await this.channel!.broadcast(
{
type: topic,
result: {
success: true,
action: "SELL",
}
});
this.subject.next(
{
Symbol: data.symbol,
DataSource: [...ELEMENT_DATA]
});
} else {
await this.channel!.broadcast(
{
type: topic,
result: {
success: false,
action: "SELL",
error: "Trader is not able to place its symbol for selling."
}
});
}

return;
});

this.listeners.push(listener);

} catch (err) {
console.error(err);
}

this.listeners.push(listener);

} catch (err) {
console.error(err);
}
});
}

public displayedColumns: string[] = ['Symbol', 'Description', 'AskPrice', 'AskSize', 'BidPrice', 'BidSize', 'LastTrade'];
Expand Down
1 change: 0 additions & 1 deletion examples/fdc3-trade-simulator/js-order-book/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
Expand Down
1 change: 0 additions & 1 deletion examples/fdc3-trade-simulator/js-trader-app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body class="mat-typography">
Expand Down
1 change: 0 additions & 1 deletion src/fdc3/js/composeui-fdc3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ async function initialize(): Promise<void> {
if (channelId) {
await fdc3.joinUserChannel(channelId)
.then(() => {
console.log("Hello");
window.fdc3 = fdc3;
window.dispatchEvent(new Event("fdc3Ready"));
});
Expand Down

0 comments on commit 6f3a5d2

Please sign in to comment.