Replies

alshdavid
08 Dec 2024, 11:32

I'm trying to get the realized pnl for a closed position, basically this:

Looking to determine realized net, gross and commission.

I can get the order details from ProtoOAOrderListReq but determining realized P&L from this is tricky. It also does not contain commission.

I have looked over the proto messages in the docs a few times over but I didn't spot anything that would provide this information - did I miss it?

Thanks

 


@alshdavid

alshdavid
08 Dec 2024, 11:32 ( Updated at: 08 Dec 2024, 11:37 )

I'm trying to get the realized pnl for a closed position, basically this:

Looking to determine realized net, gross and commission.

I can get the order details from ProtoOAOrderListReq but determining realized P&L from this is tricky. It also does not contain commission.

I have looked over the proto messages in the docs a few times over but I didn't spot anything that would provide this information - did I miss it?

Thanks

EDIT:

I can see ProtoOAClosePositionDetail but I don't see what request that comes back from


@alshdavid

alshdavid
08 Dec 2024, 11:32

I'm trying to get the realized pnl for a closed position, basically this:

Looking to determine realized net, gross and commission.

I can get the order details from ProtoOAOrderListReq but determining realized P&L from this is tricky. It also does not contain commission.

I have looked over the proto messages in the docs a few times over but I didn't spot anything that would provide this information - did I miss it?

Thanks


@alshdavid

alshdavid
08 Dec 2024, 11:32

I'm trying to get the realized pnl for a closed position, basically this:

Looking to determine realized net, gross and commission.

I can get the order details from ProtoOAOrderListReq but determining realized P&L from this is tricky. It also does not contain commission.

I have looked over the proto messages in the docs a few times over but I didn't spot anything that would provide this information - did I miss it?

Thanks


@alshdavid

alshdavid
08 Dec 2024, 11:32

I'm trying to get the realized pnl for a closed position, basically this:

Looking to determine realized net, gross and commission.

I can get the order details from ProtoOAOrderListReq but determining realized P&L from this is tricky. It also does not contain commission.

I have looked over the proto messages in the docs a few times over but I didn't spot anything that would provide this information - did I miss it?

Thanks


@alshdavid

alshdavid
07 Dec 2024, 04:04

RE: FRAME_TOO_LONG"!Frame size exceeds allowed limit.

bolatfx said: 

[..]

Thanks, that worked for me!


@alshdavid

alshdavid
03 Nov 2024, 12:58

This is also the case with Golang


func main() {
	var HOST string = "demo.ctraderapi.com"
	var PORT uint32 = 5035
	var CLIENT_ID string = "<x>"
	var CLIENT_SECRET string = "<x>"

	addr := fmt.Sprintf("%s:%d", HOST, PORT)
	tcpAddr, _ := net.ResolveTCPAddr("tcp", addr)
	iconn, _ := net.DialTCP("tcp", nil, tcpAddr)

	cfg := tls.Config{
		InsecureSkipVerify: true,
	}
	conn := tls.Client(iconn, &cfg)

	req := &openapi.ProtoOAApplicationAuthReq{
		PayloadType:  nil,
		ClientId:     &CLIENT_ID,
		ClientSecret: &CLIENT_SECRET,
	}

	out, _ := proto.Marshal(req)

	length := make([]uint8, 5)
	binary.LittleEndian.PutUint32(length[0:4], uint32(len(out)))
	out = append(length, out...)

	conn.Write(out)

	for {
		buffer := make([]byte, 1024)
		conn.Read(buffer)
		fmt.Print("Response:", string(buffer))
	}

}

Failing with 

FRAME_TOO_LONG"!Frame size exceeds allowed limit.

@alshdavid

alshdavid
02 Nov 2024, 06:34 ( Updated at: 03 Nov 2024, 12:59 )

I am also getting this error. I am trying to simplify this with a Nodejs client (will use Rust for production)

const root = protobuf.loadSync(path.join(__dirname, '..', 'protobuf', 'OpenApiMessages.proto'))
const ProtoOAApplicationAuthReq = root.lookupType("ProtoOAApplicationAuthReq");

const client = new net.Socket();

await new Promise<void>(res => client.connect(5035, "demo.ctraderapi.com", res))
console.log('Connected')

const socket = new tls.TLSSocket(client)

const msg = ProtoOAApplicationAuthReq.create({
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
});

let bytes = ProtoOAApplicationAuthReq.encode(msg).finish()
socket.write(bytes)

socket.on('data', function(data) {
  console.log('Received: ' + data);
});

I also tried sending the bytes individually to see if that was the problem

let bytes = ProtoOAApplicationAuthReq.encode(msg).finish()

for (const byte of bytes) {
  socket.write(Buffer.from([byte]))
}

However both resulted in

FRAME_TOO_LONG"!Frame size exceeds allowed limit.

I tried adding the length header

function len(x: number) {
  return [x,(x<<8),(x<<16),(x<<24)].map(z=> z>>>24).reverse()
}

console.log(bytes.length)      // 110
console.log(len(bytes.length)) // [110, 0, 0, 0]

// +--------------------------+-----------------------------------------+  
// | Message Length (4 bytes) | Serialized ProtoMessage object (byte[]) |  
// +--------------------------+-----------------------------------------+  
//                            |<---------- Message Length ------------->|
const b = Buffer.from([...len(bytes.length),...bytes])

console.log(b)  // [110, 0, 0, 0, ...proto bytes]

socket.write(b)

Same error


@alshdavid

alshdavid
31 Oct 2024, 12:27

Has this been implemented? 


@alshdavid

alshdavid
29 Oct 2024, 08:51 ( Updated at: 29 Oct 2024, 16:20 )

RE: Emails not coming through or coming through too slowly / Webhooks?

PanagiotisCharalampous said: 

Hi there,

Emails come immediately in my case, neither we have any other complaints regarding this. So most probably this is an issue with your email rather than the platform. If we receive more complaints, we will investigate further.

Best regards,

Panagiotis

Thanks! Unfortunately my original plan was to use the emails as a push event and data source for journaling however the emails themselves don't contain the right information for this.

I'm currently exploring using the open api capabilities for pulling historical data. Does the API support webhooks for order actions or is it only available via websocket? 

Webhooks are ideal because I can use serverless handlers to process my trade data and put it into an SQL database to be queried/visualized later.

If it's only websockets, I'd be better off polling the open api endpoints every minute or something - or find some alternative trigger for pulling historical data

 


@alshdavid