Access Deposits and Withdrawals values inside Robot?
Access Deposits and Withdrawals values inside Robot?
11 Jul 2017, 17:21
Hi,
Is it possible to access the Deposit and Withdrawal transactions for an account inside a robot?
Thanks
Replies
ctid320188
12 Jul 2017, 14:55
Hi Thak you for the quick reply.
Is it possible for me to use this Connect API from within the robot code itself?
Just to explain where I'm aiming to get: I am coding up a bot for others to use but it relies on knowing when the owner of the account/bot has mad a deposit or withdrawl so I can maintain a correct "ledger" based on account balance/equity i.e. I know exactly how much the bot has made from closing positions by looking at the starting and current balance which gets a bit screwed if the owner of the account then for example deposits another £1000 into their account.
If the bot can access the deposit/withdrawl details via Connect API inside the bot this would be great as the bot will have access to "their account" details and I don't have access outside.
Cheers
@ctid320188
Spotware
18 Jul 2017, 09:41
Hi ctid320188,
In principle, there is no technical restriction to make calls to Connect API from within a cBot. In your case, you would just need to get the cashflow history with requests like the following one.
https://sandbox-api.spotware.com/connect/tradingaccounts/89214/cashflowhistory?oauth_token=test002_access_token
However, if you plan to distribute your cBot to other users, you should first find a way for them to authenticate using the Connect API since you will need an access token to retrieve each account's information.
In any case, we can consider adding transaction information in a future version of cAlgo.API.
Best Regards,
cTrader Team
@Spotware
PureForm
04 Oct 2019, 01:04
( Updated at: 21 Dec 2023, 09:21 )
You can check the History for gaps in the balance.
In the third row the net profit of that trade was 56€, but the balance changed by 1056€. This hints for a deposit of 1000€.
This example code will print all the deposits and withdrawals to the log. I had to tweak the diff value a bit to filter out noise. Noise can happen by rounding and when several trades are closed in the same millisecond.
// this bot finds deposit and withdrawal transactions in the history and prints them to the log using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class HistoricalTransactions : Robot { protected override void OnStart() { double diff; Print("First Account Deposit of {0} {1} before {2}", History[0].Balance - History[0].NetProfit, Account.Currency, History[0].EntryTime); for (int i = 1; i < History.Count; i++) { diff = History[i].Balance - History[i].NetProfit - History[i-1].Balance; if (diff > 0.01 && (diff+0.01)%10 < 0.02) { Print ("Deposit of {0} {1} between {2} and {3}", diff, Account.Currency, History[i-1].ClosingTime, History[i].ClosingTime); } else if (diff < -0.01 && (diff-0.01)%10 > -0.02) { Print ("Withdrawal of {0} {1} between {2} and {3}", -diff, Account.Currency, History[i-1].ClosingTime, History[i].ClosingTime); } } Stop(); } protected override void OnTick() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
@PureForm
Spotware
12 Jul 2017, 11:47
Hi ctid320188,
This information is not currently available in cAlgo API but you can use Connect API to read this information. Have a look here https://connect.spotware.com/docs/api-reference/accounts-api
@Spotware