New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why buy/sell using 0.95 percent? #2434

Closed
PaulGuo opened this Issue Aug 12, 2018 · 9 comments

Comments

Projects
None yet
3 participants
@PaulGuo
Copy link

PaulGuo commented Aug 12, 2018

I'm submitting a ...
[ ] bug report
[x] question about the decisions made in the repository

Releated Code

    amount = this.portfolio.currency / this.price * 0.95;

    log.info(
      'Trader',
      'Received advice to go long.',
      'Buying ', this.brokerConfig.asset
    );

  } else if(direction === 'sell') {

    if(!this.exposed) {
      log.info('NOT selling, already no exposure');
      return this.deferredEmit('tradeAborted', {
        id,
        adviceId: advice.id,
        action: direction,
        portfolio: this.portfolio,
        balance: this.balance,
        reason: "Portfolio already in position."
      });
    }

    amount = this.portfolio.asset * 0.95;

Expected result (what you hoped would happen)

amount = this.portfolio.currency / this.price * 1;
amount = this.portfolio.asset * 1;

Actual result (unexpected outcome)

amount = this.portfolio.currency / this.price * 0.95;
amount = this.portfolio.asset * 0.95;

Other information

Why 0.95 percent?

@askmike

This comment has been minimized.

Copy link
Owner

askmike commented Aug 12, 2018

Why 0.95 percent?

That's not 0.95%, that's 95%.

Buy: Gekko figures out an amount of asset to buy based on how much currency you have, because this is how you need to create orders on exchanges. Imagine you have 1000 dollars and bitcoin is 1000 dollar. If Gekko tries to buy 1 Bitcoin things break down if before the buy is complete the price moves up to $1001 (since you can't afford 1 bitcoin anymore)*. this 95% allows the price to move 5% before execution is complete.

*Price is simplified: Gekko uses a "rough" concept of price when calculating the amount to buy (the close of the last 1 minute candle) since the orderbook is not exposed to Gekko (only Gekko Broker). On top of that the orderbook might move before the buy is complete (while partially filled or not filled at all).

As to why 95% when selling? There used to be some issues with rounding of amounts (up). On some exchanges (like binance) you can't create limit orders for any amount you might have. For example if you have 0.0000019 bitcoin you can only sell 0.000001 (through a limit order). However Since Gekko Broker all amounts are always rounded down. Meaning we can remove this 95% limitation. I'm very open to a PR :)

@askmike

This comment has been minimized.

Copy link
Owner

askmike commented Aug 13, 2018

However Since Gekko Broker all amounts are always rounded down. Meaning we can remove this 95% limitation [when selling]. I'm very open to a PR :)

I fixed this myself now since someone else was also wondering about it.

So to sum up:

  • When selling: this is now fixed in latest develop branch.
  • When buying: unfortunately that's a limitation given the current design, full story ^.
@storshun

This comment has been minimized.

Copy link

storshun commented Aug 15, 2018

@askmike sanity-checking with you before I royally screw myself, changing this:
amount = this.portfolio.currency / this.price * 0.95; or
amount = this.portfolio.asset * 0.95;
to a different percentage (say.... 0.475) would not be your suggested method of limiting the exposure to a given trading pair so you could run two bots on the same exchange... right?
I spent some time reading through #937 tonight, and it sounds like there's more involved than doing this as a hack-y work-around.
Cheers

@askmike

This comment has been minimized.

Copy link
Owner

askmike commented Aug 18, 2018

@storshun I would not do that. That might mess up things like exposure calculation.

@askmike

This comment has been minimized.

Copy link
Owner

askmike commented Aug 23, 2018

@storshun

That might mess up things like exposure calculation.

Thinking about removing this, would should make it easier to tweak things. See here: https://forum.gekko.wizb.it/thread-57589-post-60038.html#pid60038

@storshun

This comment has been minimized.

Copy link

storshun commented Aug 23, 2018

I'm clearly going to have to learn how to code up strats. I've been basically tweaking existing config.js files and getting by with that, but it sounds like stop-loss might still be a ways out from UI implementation? Not casting shade, I get that it takes time to get this stuff done right. :)
Thanks for all the continued support on the project @askmike!

@storshun

This comment has been minimized.

Copy link

storshun commented Aug 23, 2018

Hit "comment" too quickly. I meant to add:
How do you plan on limiting exposure in the future? For instance, let's say I'm really good - REALLY good - and I end up being a whale on the market. Obviously I won't want 100% of my assets or currency popping onto the book every time. :) Presume I won't want to divvy my assets across different currencies as a means of limiting exposure.

@askmike

This comment has been minimized.

Copy link
Owner

askmike commented Aug 24, 2018

but it sounds like stop-loss might still be a ways out from UI implementation?

I've implemented them in a way where they are tied to the strategy: it's up to the strategy to trigger an advice that comes with a stoploss. The strategy can expose this in the UI as a strategy parameter (so users can tweak things like stop %), but that's up to the strategy. As for visualizing them that's another story.. Not sure yet.

How do you plan on limiting exposure in the future? For instance, let's say I'm really good - REALLY good - and I end up being a whale on the market.

Note that Gekko is framework for building trend following trading bots. If you are a whale (I mean not just big trader but want to influence the price your way, etc) - you wouldn't use Gekko but something else.

That said I will work on this, this has been a much requested feature. The hard things here are:

  • It's really had to do this 100% properly: If Gekko crashes at any point and gets restarted it should pick up exactly where it left off, Also if you trade USD/BTC and you "limit" a bot to 100USD and BTC flash crashes (to 100USD) can it than go and sell 1 bitcoin? Etc.
  • There are other limitations as well such as API rate limits. If you can limit Gekko to something like 10% of your balance, people will run 10 of those on on account and that will break.
  • It's hard for Gekko to play nicely with other tools that also trade on the same account (and same currencies). Read this. This is only a problem when people restrict Gekko to 10% and do something else with the 90%.
  • Some exchanges (like binance) have APIs like that make it hard get information on your historical trades if there is a lot of trading activity happening on your account.

TLDR: changing the amount Gekko trades is not hard, but everything else is.

@storshun

This comment has been minimized.

Copy link

storshun commented Aug 24, 2018

I've implemented them in a way where they are tied to the strategy: it's up to the strategy to trigger an advice that comes with a stoploss.

I'm sure that means something useful, but I'm not at the point where I understand how to accomplish that. That said, I'm not putting that burden on your back. I'll work to figure that out on my own based on your "how to create a strategy" documentation.

If you are a whale (I mean not just big trader but want to influence the price your way, etc) - you wouldn't use Gekko but something else.

Definitely not what I meant. I simply mean becoming a large volume trader via Gekko through prolonged success.

As for the difficulties, I have a few thoughts, most of them have nothing to do with programming though:

If Gekko crashes at any point and gets restarted it should pick up exactly where it left off

That would obviously be ideal, but I'm not familiar with many (any?) programs that exhibit that behavior. Most executables that crash seemingly don't know they crashed cause they are no longer operating, and some sense of state is lost on relaunch. I wouldn't expect (as a fairly technically minded person) Gekko to be special in that regard. I guess real-time logging could give you something akin to a state machine, or possibly giving Gekko an actual state machine and referencing that after a relaunch against the state of the account when it gets private data.

Also if you trade USD/BTC and you "limit" a bot to 100USD and BTC flash crashes (to 100USD) can it than go and sell 1 bitcoin?

You warn us every time we launch Gekko. :)

If you can limit Gekko to something like 10% of your balance, people will run 10 of those on on account and that will break.

I think if that's part of your documentation, people will realize that's not OK to do, or they'll play the numbers game and try it anyway. In either case, you've done your job to inform, it's not your fault if people misuse the tool and lock themselves out of API access.

It's hard for Gekko to play nicely with other tools that also trade on the same account

I'm definitely not the audience for this statement, so I don't have much to offer - I only use Gekko, and only on one exchange. I fully realize I'm not a power-user, though I would like to be eventually, and my view may be myopic.

I'm very much a believer in the "I warned you, but it's your decision" doctrine, rather than seeing you and your fellow contributors banging your head against the wall trying to solve every problem the community throws back at you. I think the vast, vast majority of users appreciate what you've created, are thankful it's come as far as it has, and are largely accepting of idiosyncratic behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment