Buy on the SDK
1. Create order buy instance:
Params | Type | Description |
---|---|---|
target | string | Resource receiving address. |
amount | number | The number amount of resources |
price | "FAST" | "MEDIUM" | "SLOW" | number |
|
duration | number | The duration of the bought resource, time unit is equal to millisecond. |
allowPartialFill | boolean | Allow the order to be filled partially or not |
maxPrice (optional) | number | The highest price allow sdk create an order, if user set price is "FAST", "MEDIUM" or "SLOW" and estimate price is bigger than maxPrice, this order creation will be canceled. |
fulfilledOnly (optional) | boolean | If fulfilledOnly = true, the SDK will only create order if the system is ready to fill 100% |
2. Auto create order buy energy for Bot
This feature is used to monitor and automatically create order buy energy for the Bots when the energy decreases to a threshold.
Whenever TronSave build a transaction, there will be a minimum waiting time of 15 seconds before the next call, unless TronSave determines that the buy order is erroneous, in which case there will be no waiting time.
2.1. Start this feature:
Params | Type | Description |
---|---|---|
frequency | number | time interval TronSave check balance and energy to buy energy in millisecond, default is 10000. Minimum value is 3000 |
2.2. Add the Bots you want to monitor:
Step 1: Create buy config of each bot:
Parameter
Params | Type | Description |
---|---|---|
buyThreshold | number | If the energy falls below this threshold, TronSave will create an order to buy energy. |
target | string | Resource receiving bot address. |
amount | number | The number of resources |
price | "FAST" | "MEDIUM" | "SLOW" | number |
|
duration_millisec | number | The duration of the bought resource, time unit is equal to millisecond. |
allowPartialFill | boolean | Allow the order to be filled partially or not |
maxPrice (optional) | number | The highest price allow sdk create an order, if user set price is "FAST", "MEDIUM" or "SLOW" and estimate price is bigger than maxPrice, this order creation will be canceled. |
fulfilledOnly (optional) | boolean | If fulfilledOnly = true, the SDK will only create order if the system is ready to fill 100% |
Step 2: Passing listBots
to tronSave.autoBuyEnergy.startObserverTarget
built-in function to start observer your bots.
2.3. Stop monitoring one bot:
To stop observer one bot address in your listBots
passing your bot address to tronSave.autoBuyEnergy.cancelObserverTarget
Parameter
Params | Type | Description |
---|---|---|
target | string | Bot address. |
Stop all Bot:
To stop observer all bot using tronSave.autoBuyEnergy.cancelObserverAllTarget
2.4. Listen events buy energy:
Event lists
Event Name | Description | Response Type |
---|---|---|
buyerInfo | result of get trx balance of buyer | |
statusTarget | result of get energy bot/ threshold | |
prepairOrder | result of get estimate trx + check order pending on market | |
executeOrder | result of build transaction | |
resultOrder | last result, if success => orderId on market |
3.Create order buy with API key of internal account
Parameter
Params | Type | Description |
---|---|---|
target | string | Resource receiving bot address. |
amount | number | The number of resources |
price | "FAST" | "MEDIUM" | "SLOW" | number |
|
duration | number | The duration of the bought resource, time unit is equal to millisecond. |
allowPartialFill | boolean | Allow the order to be filled partially or not |
sponsor (optional) | string | Sponsor, if available. |
apiKey (optional) | string | API key of internal account. If undefined, will take the internal account associated with the current address. |
Last updated