Krypto-trading-bot: Support margin trading (initially on Bitfinex)

Created on 14 Dec 2017  路  10Comments  路  Source: ctubio/Krypto-trading-bot

I'd really like to use this bot with my margin wallet on Bitfinex.

As far as I can see this is purely a matter of adding a flag to select the margin wallet, and using this flag to change a couple of parameters in the orders REST and WS api calls.

I'd be very happy to implement this improvement, but having looked through the code in this repo, it appears that these parameters are set in the precompiled binary that is not open source.

Is there a process for making improvements to these? Is this outside the scope of this project?

acknowledged bug

Most helpful comment

if you have any issue please open a new one; v1 of bitfinex margin is done :dancer:

All 10 comments

yea im sorry the api integrations are outside of this github project, but thanks for the suggestion, i will consider soOn''

can i pay you a small bounty to get it done very soon?

It seems like a very small amount of work.

only if you are happy with the final result; im currently updating json to v3 and later i look for thiz
if so you can grab then my addr from the commit msg easy

if you have any issue please open a new one; v1 of bitfinex margin is done :dancer:

Fantastic, thanks so much! How does one activate it? It doesnt look like its in the ui and I also dont see any changes in the config options. I tried "BITFINEX MARGIN" but that doesn't work.

reinstall and make use of the new config value (see https://github.com/ctubio/Krypto-trading-bot/blob/master/etc/K.sh.dist#L50)

Unfortunately this isn't quite right. In margin mode we are not trading with the funds in our wallet. Consequently the way that this is implemented is not quite right.

It actually requires a couple of separate calls.

https://docs.bitfinex.com/v1/reference#rest-auth-active-positions gives you the balance of the currency you are trading, and

https://docs.bitfinex.com/v1/reference#rest-auth-margin-information gives the balance of the base currency (in margin_limits).

Note also that balances may be negative (if you are shorting).

we dont use REST v1 for wallet data

WS v2 is what we use (see https://docs.bitfinex.com/v2/reference#ws-auth-wallets)

do you mean we miss this https://docs.bitfinex.com/v2/reference#ws-auth-margin ? or can you point to the reference in the ws v2 docs? thanks for your time''

also we are not reading exchange funds when using margin, we ask for WALLET_TYPE = margin

Sorry for the delay. Yes, good point re websocket rather than rest.

also we are not reading exchange funds when using margin, we ask for WALLET_TYPE = margin

The margin wallet works slightly differently to the exchange wallet. You do not trade with the funds in your margin wallet, these are used as collateral to access borrowed funds, which are what you trade with.

This means that "balance" is effectively split into two separate figures:
1. The amount of the base currency that you have available to borrow. (for the symbol LTC/USD, for example, you are borrowing USD to buy LTC); and
2. The amount of the trading currency that you have currently borrowed. (LTC, in the above example).

To retrieve these:

  1. To get the available funds for any coin, you would look at the https://docs.bitfinex.com/v2/reference#ws-auth-margin TRADEABLE_BALANCE field, although it will be often desirable to be able to add a user-configurable hard limit to that, since it is borrowed money, and it is also shared between all coins.

_I can add the UI and adapter code for this if you like._

  1. To get the current "balance" of the coin you are buying/selling, you would look at
    the AMOUNT field of https://docs.bitfinex.com/v2/reference#ws-auth-position.

thanks for the info''

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MiningInMySleep picture MiningInMySleep  路  4Comments

nonkreon picture nonkreon  路  5Comments

wulabs picture wulabs  路  3Comments

nonkreon picture nonkreon  路  5Comments

juaxix picture juaxix  路  4Comments