ctubio / Krypto-trading-bot

Self-hosted crypto trading bot (automated high frequency market making) written in C++
https://127.0.0.1:3000
Other
3.33k stars 819 forks source link

Bitmex: TBP Logic #986

Open asfbhero opened 5 years ago

asfbhero commented 5 years ago

I can’t get tbp to work as it should. Now that I’ve got things working in terms of trading it’s now time to work on risk management.

As of now it looks like the bot doesn’t understand if tbp held should be applied to the bid side or the ask side. I imagine this could be fixed by having the bot query the bitmex api and see if the net position is long or short, then hold that side.

Coding this seems a bit over my head but I’ll give it a shot, @ctubio can you point me in the right direction and I’ll poke at it after work tonight.

Camille92 commented 5 years ago

Are you referring to https://github.com/ctubio/Krypto-trading-bot/issues/976 ?

If not TBP is calculated with the ewma ! Anyways I don't think net position is a good help here.

asfbhero commented 5 years ago

I don’t think it’s what was discussed there.

Say I’m using manual mode with 1 btc in margin. I want the bot to stop buying when I’ve spent 50% of my margin on buys and stop selling when I’ve used 50% of my margin on sells.

The problem is that since the margin is in bitcoin, the bot only sees that Bitcoin held has gone down, regardless if I’ve used that bitcoin margin to accumulate long or short positions in bitcoin.

If I’m long eos/xbt it’s fine, because I’m net short bitcoin, having used 50% of my margin buying eos and selling xbt, so it will set the bid to tbp held.

But if I’m net short eos/btc, having used 50% of my margin buying btc and selling eos, it will still see that I have 50% of the bitcoin in my margin account, and it will set the bid to tbp held.

So no matter if you have too many Buys or too many Sells, the bot will only stop buying, and never stop selling.

It’s not that tbp is wrong, it’s that no matter what side of the trade you are on it always thinks that you are short the margin currency.

MiningInMySleep commented 5 years ago

Running into a possibly related issue where the bot, upon running out of margin, won't recognize that and proceeds to spam orders (which get "insufficient margin" error) until IP banned.

asfbhero commented 5 years ago

Yeah, it’s related. I haven’t really had time to play with it since I’m in the middle of a big project at work.

My only solution has been to come up with a new bitmex specific strategy that trades less and with bigger sizing. Though this obviously isn’t and ideal strategy with such high rebates available.

Sent from my iPhone

On Aug 22, 2019, at 12:41 PM, MiningInMySleep notifications@github.com wrote:

Running into a possibly related issue where the bot, upon running out of margin it won't recognize that and proceeds to spam orders (which get "insufficient margin" error) until IP banned.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

ctubio commented 5 years ago

lemme reread all comments slowly again to see if i can understand it