terra-money / warp-contracts

Other
15 stars 14 forks source link

Feature Request: Adding if-else Condition Support for Job Creations #72

Open 0x7183 opened 1 year ago

0x7183 commented 1 year ago

BIG Labs is interested in contributing to Warp Contracts by adding the ability to use if-else conditions when creating jobs. We would like to discuss the technical aspects and implementation details with the Warp Contracts development team.

dev8723 commented 1 year ago

@0x7183 can you give a job example of using if else?

0x7183 commented 1 year ago

@llllllluc following some examples:

  1. A Grid bot using warp
  2. Most of the trading strategies
  3. Handling of errors in sub messages
dev8723 commented 1 year ago

@llllllluc following some examples:

  1. A Grid bot using warp
  2. Most of the trading strategies
  3. Handling of errors in sub messages

sorry i mean job example where the condition needs if else, can you write some sudo code to help me better understand? the more detail the better maybe use grid bot as example

0x7183 commented 1 year ago

With a grid bot we need to buy or sell an asset based on the price.

Right now there isn't a way to implement it using only warp.

We'll require a job for the buy message with the buy condition and a job with for the sell message with the sell condition. Also when a job is triggered we have to delete the other one and create a new buy and sell message updating the parameters based on the last message.

What we need is something like that in pseudo code:

If buy: buy msg else if sell: sell msg else: pass

Sorry for the formatting, but I'm from phone and is pretty late here.

If this isn't enough I'll provide more details tomorrow!

dev8723 commented 1 year ago

I see, this is a nice feature we should support, it's like having 2 condition field and 2 msgs fields, if cond 1 resolves to true, then execute msgs 1, if cond 2 resolves to true, then execute msgs 2, if both resolves to false, then do nothing, but what if both resolve to true? I'm trying to think of an elegant way to implement this. Maybe you can bring this up in warp telegram, and let @vladjdk and @simke9445 chime in.

dev8723 commented 1 year ago

when a job is triggered we have to delete the other one and create a new buy and sell message updating the parameters based on the last message.

I think this is already supported by the recurring job, where you can update var every time it executes (recurring job is after you execute, it will create a new one)

0x7183 commented 1 year ago

@vladjdk told us to open an issue on Github and discuss there the implementation details, if you're ok with it we can start working at it and make a PR at the end.

Just what is the main branch?

dev8723 commented 1 year ago

awesome! the pre release branch is in https://github.com/terra-money/warp-contracts/pull/67, looking forward to the PR!

simke9445 commented 1 year ago

Cool idea, me and @vladjdk were discussing this on several occasions, and its great that you guys took a hand of it.

Ideally this would work very similar to a switch statement.

Job would look like this:

in your case: