Mida icon indicating copy to clipboard operation
Mida copied to clipboard

Adding a custom id to a MidaTradingAccount

Open thijserven opened this issue 3 years ago • 3 comments

Is there a way to add a custom id to a MidaTradingAccount when using Mida.login()?

The MidaTradingAccount class does have an id property but it's set as read only so I can't assign any value to it. Is this intentional?

thijserven avatar Sep 22 '22 21:09 thijserven

Hello, the id field of MidaTradingAccount is supposed to contain the trading account id in the trading platform. So it's intentional to be a read only property. If you want to assign an id to your trading account you have plenty of ways to do this with different data structures, for example:

const ids = new WeakMap();
const myAccount = ...

ids.set(myAccount, "id");

What do you think?

Vasile-Peste avatar Sep 26 '22 12:09 Vasile-Peste

Thanks! Never heard of WeakMaps before but it provided the solution for me.

thijserven avatar Oct 01 '22 08:10 thijserven

Also one side note I noticed that the MidaTradingAccount id of a Binance/Spot account is empty. Is this because Binance doesn't give back a trading account id?

thijserven avatar Oct 01 '22 10:10 thijserven

Also one side note I noticed that the MidaTradingAccount id of a Binance/Spot account is empty. Is this because Binance doesn't give back a trading account id?

Yes, in Binance unfortunately the API will not report the user id so in this specific case it's going to be empty.

Vasile-Peste avatar Oct 08 '22 14:10 Vasile-Peste