Bitcoin Forum
April 24, 2024, 01:12:45 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 3 4 5 6 7 8 9 10 11 12 13 14 »  All
  Print  
Author Topic: [ANN] MarginBot - A Bitfinex Margin Lending Management Bot  (Read 45868 times)
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 19, 2014, 08:29:13 PM
Last edit: September 20, 2017, 05:43:37 PM by HowardF
 #1

Description

MarginBot is  a PHP based Margin Lending Management Bot for the Bitfinex API.  It will do it's best to keep any money in the "deposit" wallet lent out at the highest rate possible while avoiding long periods of pending loans (as often happens when using the Flash Return Rate, or some other arbitrary rate). There are numerous options and setting to tailor the bot to your requirements.

Now that we're several versions into this bot, it has several years of stable performance history, and several users who have been using it for more than 3 years.  I myself have been running it on several accounts for ~4 years now, and it has consistently outperformed FRR.  I recently added in Cryptocurrency lending as well, one of the most requested features.  It currently supports all currencies that Bitfinex supports, and you can easily add new currencies as Bitfinex does.

Future Plans
We're always working to add features and improve MarginBot.  My current plan is to try to add some other exchanges, such as Poloniex, though my experience so far has been that the other exchanges tend to have terrible rates compared to Bitfinex.  If anyone has any suggestions for future additions, we're always open to ideas.

Installation

Download the most current version, unzip to a folder on your server, then browse to that folder. An install script will run you through the rest of the process.

Note: If you get the following error during install:
Code:
PHP Parse error:  syntax error, unexpected ''America/Los_Angeles\\');' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) in /var/www/html/web/install.php on line 92
you most likely have your PHP configured without short_open_tag = on.  Make sure to set
Code:
short_open_tag = on

Upgrading From Older Versions
If you are upgrading from an older version, you may sometimes be required to run through a quick upgrade process the first time you log in.  As of v.1.07+ the bot should automatically detect if you need to upgrade and send you there.  However if it doesn't work for some reason, just go to yoursite.com/MarginBot/update.php and it should detect if you need to upgrade or not.


Updates
  • 11/22/2014 - Update v0.1.02 posted - Details
  • 11/24/2014 - Update v0.1.03 posted - Details
  • 11/26/2014 - Update v0.1.04 posted - Details
  • Critical Update - 12/16/2014 - Update v0.1.05 posted - Details
  • 12/18/2014 - Update v0.1.06 posted
  • 8/17/2017 - Update v0.1.07 posted - Details
  • 9/19/2017 - Update v0.1.08 posted - Details

Requirements

A live webserver running
  • PHP 5.1+ (with CURL support)
  • MySQL
  • Access to add a cronjob
  • A Bitfinex Account with API Access
  • At least $50 in your Bitfinex "Deposit" wallet. Preferably $100 or more. ( Note: This is a bitfinex requirement, not a bot requirement. Bitfinex doesn't allow Margin Loans of less than $50. )

I'm sure everyone reading this already has a bitfinex account, but if you don't for some reason, please consider using my affiliate code ( vsAnxuo5bM ) when signing up. By doing so, you'll save 10% on all fees for the first month, and it will help support further development of this code.


Links

Github Repo

Latest Download (From GitHub)

Reddit Discussion


Screenshots















Donate

Developing this software, and testing the various strategies for lending that led to its development have taken significant time and effort. If you find this software useful, please send a donation our way. All donations support the continued development of this software, and help to cover my distribution and support costs.

Bitcoin: 1A3y1xDXtyZySmPZySbpz7PPog4Vsyqig1

Ethereum: 0xf159d969e065b20083b50c930b71d29364ae5247



Edit: Updated All of the images to represent v1.08

1713921166
Hero Member
*
Offline Offline

Posts: 1713921166

View Profile Personal Message (Offline)

Ignore
1713921166
Reply with quote  #2

1713921166
Report to moderator
The forum was founded in 2009 by Satoshi and Sirius. It replaced a SourceForge forum.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713921166
Hero Member
*
Offline Offline

Posts: 1713921166

View Profile Personal Message (Offline)

Ignore
1713921166
Reply with quote  #2

1713921166
Report to moderator
Sukrim
Legendary
*
Offline Offline

Activity: 2618
Merit: 1006


View Profile
November 20, 2014, 11:47:38 PM
 #2

Looks nice, do you have comparison data vs. the "standard": Lending 30 days at FRR?

https://www.coinlend.org <-- automated lending at various exchanges.
https://www.bitfinex.com <-- Trade BTC for other currencies and vice versa.
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 12:46:19 AM
 #3

Looks nice, do you have comparison data vs. the "standard": Lending 30 days at FRR?

Unfortunately, I don't.  I've never run any of the accounts I manage at FRR beyond the first few weeks I used bitfinex, because I didn't like how often my money stayed unlent.  Thats a big part of the goal of this bot, it keeps my money lent almost all the time, with no downtime.  Even with dozens of loans closing daily, very little money goes a full hour unlent, and during high volatility, I've had significant portions of my money lent out several times in a single hour.

If anyone has been running their account on FRR auto renew and wants to share some of their return data, I'll be happy to correlate it to my returns.  I have good data using basically this bot for about 5 months, and data using an earlier, simpler version of this bot back to January, so any period from then on should work to at least give us a rough idea.   I can convert the data to just a % return / day so you don't have to share actual balances if you don't want.

I also have a bitfinex account right now that I can put maybe $2000 into and post the daily results here if that would interest anybody.

HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 12:51:55 AM
 #4

I should also point out that chart above is an actual account running the bot, with real returns AFTER FEES, so you can get an estimate of returns from there....  It is an account that occasionally gets used for trading and paying bills though, so its not a 100% pristine investment return.


Sukrim
Legendary
*
Offline Offline

Activity: 2618
Merit: 1006


View Profile
November 21, 2014, 12:55:49 AM
Last edit: November 21, 2014, 01:13:36 AM by Sukrim
 #5

%/day would be great, I'll look into parsing the csv files...

Edit: Done. I'm not sure if I did more manual work a few months back, but recently I mostly tried (when I thought FRR might go down further) to have whatever is available in some fixed rates if I got around to set some (every 2 days or so), the rest ran on "autopilot". Here's the swap payment data for November, depending on how you view "days", it could be one day off.

Code:
0,06140%	01.11.2014
0,06727% 02.11.2014
0,06598% 03.11.2014
0,06663% 04.11.2014
0,06504% 05.11.2014
0,06206% 06.11.2014
0,05659% 07.11.2014
0,05555% 08.11.2014
0,05490% 09.11.2014
0,05887% 10.11.2014
0,06133% 11.11.2014
0,05927% 12.11.2014
0,05223% 13.11.2014
0,07998% 14.11.2014
0,06349% 15.11.2014
0,04800% 16.11.2014
0,04660% 17.11.2014
0,06829% 18.11.2014
0,06706% 19.11.2014
0,06721% 20.11.2014
0,06621% 21.11.2014

https://www.coinlend.org <-- automated lending at various exchanges.
https://www.bitfinex.com <-- Trade BTC for other currencies and vice versa.
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 12:59:49 AM
 #6

%/day would be great, I'll look into parsing the csv files...

Ok, just want to make sure we're parsing the same info here, so %/day after fees right?

Sukrim
Legendary
*
Offline Offline

Activity: 2618
Merit: 1006


View Profile
November 21, 2014, 01:15:54 AM
 #7

Exactly.

Get history_USD, filter by Description "Swap Payment on wallet deposit", divide Balance by Amount and multiply by 100, then add another column for the date (I just used the date the interest was paid). Since the percentages were relatively small, I used 5 digits after the comma for no real reason.

https://www.coinlend.org <-- automated lending at various exchanges.
https://www.bitfinex.com <-- Trade BTC for other currencies and vice versa.
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 01:50:01 AM
 #8

Code:
11/1/2014		0.070107%
11/2/2014 0.071485%
11/3/2014 0.070634%
11/4/2014 0.069861%
11/5/2014 0.066710%
11/6/2014 0.065107%
11/7/2014 0.065237%
11/8/2014 0.061520%
11/9/2014 0.059754%
11/10/2014 0.058940%
11/11/2014 0.058172%
11/12/2014 0.057646%
11/13/2014 0.076388%
11/14/2014 0.089101%
11/15/2014 0.075083%
11/16/2014 0.068916%
11/17/2014 0.072677%
11/18/2014 0.071281%
11/19/2014 0.070086%
11/20/2014 0.069047%


HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 01:56:00 AM
 #9

Get history_USD, filter by Description "Swap Payment on wallet deposit", divide Balance by Amount and multiply by 100, then add another column for the date (I just used the date the interest was paid). Since the percentages were relatively small, I used 5 digits after the comma for no real reason.

I should also mention, the bot does this automatically every day to calculate returns (exactly this formula), so figuring out your actual returns with this bot running is a breeze.  It automatically updates a database table that looks like this:

Code:
id		userid	tid		date		balance		return	return_percent
343 1 1389744985 1/14/2014 21969.48 135.58 0.617142

DoubleSwapper
Full Member
***
Offline Offline

Activity: 172
Merit: 100


View Profile
November 21, 2014, 02:02:54 AM
 #10

Very interesting project!

Can you elaborate a bit on what algorithm the bot uses to determine the lending rate at which it will put the offer? Will it always try to lend as much as possible or can you set limits like "lend out 1k per hour"?
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 02:19:49 AM
 #11

Very interesting project!

Can you elaborate a bit on what algorithm the bot uses to determine the lending rate at which it will put the offer? Will it always try to lend as much as possible or can you set limits like "lend out 1k per hour"?

I'm actually in bed using a tablet right now, so I can get you a much more detailed reply tomorrow if this doesn't clear it up, but here is a copy/paste of basically the same question answered over on reddit:
(also, there is no setting to limit the amount it lends per hour.  It tries to keep everything lent all the time.  My philosophy, and the last year of experience, has taught me that hours of interest lost waiting for a slightly higher rate will end up losing far more than you'll ever make up on the slightly higher rates.  Also, as this bot splits available money among several loans, after a while, you end up having a lot of small loans out, which means there is almost always a loan closing, so there's almost always at least a little available to lend when rates do spike.  If you really want to keep some available for spikes, there is a High Hold setting that lets you basically set aside $x to lend at a minimum of y% / day )


From Reddit: http://www.reddit.com/r/bitfinex/comments/2mt0nv/marginbot_a_bitfinex_margin_lending_management_bot/
Quote
basically, if you look at the settings image:



theres a couple of settings of interest:
  • Gap Top
  • Gap Bottom
  • Spread Lends
basically it splits your current available money into (Spread Lends) loans, then it loads the full lendbook from bitfinex. It skips through the lendbook until it hits (Gap Bottom) $USD in total value, and offers the first loan at this rate -.0001%/day.
If your Spread Lends is higher than 1, it will then try to evenly spread the rest of your money between the Gap Bottom setting and the Gap Top setting. For Example:
Gap Bottom = $25,000
Gap Top = $100,000
Spread Lends = 3
so, it will look through the lendbook, find the rate where where the total offers = $25,000 for lend 1
then it'll find the rate where total offers = $62,500 (midway between $25,000 and $100,000) for lend offer 2
then it'll find the rate where total offers = $100,000 for lend offer 3
However, it will never lend lower than your Minimum Lend Rate setting. Also, it will make all offers for 2 days, unless the rate is above your "Minimum for 30 Day" setting, then it'll make the offer for 30 days. This is so it can catch flash runs and try to keep high rate loans out for as long as possible.

DoubleSwapper
Full Member
***
Offline Offline

Activity: 172
Merit: 100


View Profile
November 21, 2014, 02:26:09 AM
 #12

Very interesting project!

Can you elaborate a bit on what algorithm the bot uses to determine the lending rate at which it will put the offer? Will it always try to lend as much as possible or can you set limits like "lend out 1k per hour"?

I'm actually in bed using a tablet right now, so I can get you a much more detailed reply tomorrow if this doesn't clear it up, but here is a copy/paste of basically the same question answered over on reddit:
(also, there is no setting to limit the amount it lends per hour.  It tries to keep everything lent all the time.  My philosophy, and the last year of experience, has taught me that hours of interest lost waiting for a slightly higher rate will end up losing far more than you'll ever make up on the slightly higher rates.  Also, as this bot splits available money among several loans, after a while, you end up having a lot of small loans out, which means there is almost always a loan closing, so there's almost always at least a little available to lend when rates do spike.  If you really want to keep some available for spikes, there is a High Hold setting that lets you basically set aside $x to lend at a minimum of y% / day )


From Reddit: http://www.reddit.com/r/bitfinex/comments/2mt0nv/marginbot_a_bitfinex_margin_lending_management_bot/
Quote
basically, if you look at the settings image:

theres a couple of settings of interest:
  • Gap Top
  • Gap Bottom
  • Spread Lends
basically it splits your current available money into (Spread Lends) loans, then it loads the full lendbook from bitfinex. It skips through the lendbook until it hits (Gap Bottom) $USD in total value, and offers the first loan at this rate -.0001%/day.
If your Spread Lends is higher than 1, it will then try to evenly spread the rest of your money between the Gap Bottom setting and the Gap Top setting. For Example:
Gap Bottom = $25,000
Gap Top = $100,000
Spread Lends = 3
so, it will look through the lendbook, find the rate where where the total offers = $25,000 for lend 1
then it'll find the rate where total offers = $62,500 (midway between $25,000 and $100,000) for lend offer 2
then it'll find the rate where total offers = $100,000 for lend offer 3
However, it will never lend lower than your Minimum Lend Rate setting. Also, it will make all offers for 2 days, unless the rate is above your "Minimum for 30 Day" setting, then it'll make the offer for 30 days. This is so it can catch flash runs and try to keep high rate loans out for as long as possible.
Absolutely amazing job! I wish BFX would have implemented a system like this natively. That would clear up a lot of the stupid discussions about the FRR! I'll make sure to take a closer look at this project tomorrow!
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 04:10:36 PM
 #13

So, I just realized, if anyone was trying to email the "bug report" address found in the code of this bot, it wasn't forwarding correctly to me.  It's fixed now, but any emails sent before this morning probably didn't make it to me.  Sorry about that.    Undecided

noggin-scratcher
Full Member
***
Offline Offline

Activity: 136
Merit: 100


View Profile
November 21, 2014, 05:50:14 PM
 #14

Well consider me taken by surprise... I wasn't expecting it but, if I have the alignment of days right, your bot is outperforming my manual swap-managing. Not 100% of the time and not by very much, but for a majority of the days listed.

That said, it looks like I make up most of the difference by reacting better for those 2 days when the rates spiked - looking at the overall percentage increase across the full period, it's... well that's very slightly in the bot's favour too, but I think it's close enough to call it a wash, and suggests that if rates ever spiked for longer I might pull ahead.

Still, further evidence for the proposition that idle funds is the main thing to avoid.

Bitfinex referral code: uOaxAuXdVX
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 06:31:55 PM
 #15

Well consider me taken by surprise... I wasn't expecting it but, if I have the alignment of days right, your bot is outperforming my manual swap-managing. Not 100% of the time and not by very much, but for a majority of the days listed.

That said, it looks like I make up most of the difference by reacting better for those 2 days when the rates spiked - looking at the overall percentage increase across the full period, it's... well that's very slightly in the bot's favour too, but I think it's close enough to call it a wash, and suggests that if rates ever spiked for longer I might pull ahead.

Still, further evidence for the proposition that idle funds is the main thing to avoid.

Actually, if you apply the differences to any significant amount of money, its not a small difference....

Lets say a $50,000 balance (and this doesn't include daily compounding):

Code:
Date		MarginBot Returns	 MarginBot $50,000 Return 	FRR Returns	 FRR $50,000 Return 
10/31/2014 0.0727% $36.33 0.061% $30.70
11/1/2014 0.0701% $35.06 0.067% $33.64
11/2/2014 0.0715% $35.75 0.066% $32.99
11/3/2014 0.0706% $35.32 0.067% $33.32
11/4/2014 0.0699% $34.93 0.065% $32.52
11/5/2014 0.0667% $33.36 0.062% $31.03
11/6/2014 0.0651% $32.56 0.057% $28.30
11/7/2014 0.0652% $32.62 0.056% $27.78
11/8/2014 0.0615% $30.76 0.055% $27.45
11/9/2014 0.0598% $29.88 0.059% $29.44
11/10/2014 0.0589% $29.47 0.061% $30.67
11/11/2014 0.0582% $29.09 0.059% $29.64
11/12/2014 0.0577% $28.83 0.052% $26.12
11/13/2014 0.0764% $38.20 0.080% $39.99
11/14/2014 0.0891% $44.55 0.063% $31.75
11/15/2014 0.0751% $37.54 0.048% $24.00
11/16/2014 0.0689% $34.46 0.047% $23.30
11/17/2014 0.0727% $36.34 0.068% $34.15
11/18/2014 0.0713% $35.64 0.067% $33.53
11/19/2014 0.0701% $35.05 0.067% $33.61
11/20/2014 0.0691% $34.53 0.066% $33.11

$720.22 $646.98

Total Difference 11.320% $73.23


and i'm pretty sure this would hold up over any rate spikes, since my returns always spike by quite a bit along with the rates...  like i said, theres almost always some money coming off loan to take advantage of any spikes, and since loans update every 10 minutes, it catches even tiny flash spikes...

The above is adjusted so our days match up by the way
Edit: and I rounded all my returns to 5 decimals to keep it fair
Edit 2: argh, formatting tables here is a pain, heres the csv i used to make this, if anyone is interested:
http://fuckedgox.com/MBot/MarginBotCompare.csv



noggin-scratcher
Full Member
***
Offline Offline

Activity: 136
Merit: 100


View Profile
November 21, 2014, 06:34:56 PM
 #16

Comparing bot to FRR, sure, small differences add up. But I'm not FRR-ing it up, which puts me pretty much in line with the bot... give me a minute and I'll round up some actual numbers.



Bitfinex referral code: uOaxAuXdVX
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 06:45:17 PM
 #17

Oh, sorry, for some reason I got out of order there a bit and was thinking Sukrim's numbers were yours. : Smiley  Yeah, I'd love to see your numbers as well, out of curiosity...

I have to imagine if you micromanage your lends you can probably outperform just about any bot out there, but I only have so much time, and can't devote a ton of time to lending just to make a few pennies a day more, so for my needs the bot works pretty well.  I would love to see how it stacks up to a closely managed account though.

noggin-scratcher
Full Member
***
Offline Offline

Activity: 136
Merit: 100


View Profile
November 21, 2014, 07:18:45 PM
Last edit: November 21, 2014, 07:43:51 PM by noggin-scratcher
 #18

I think I have these in the right order and on the right days. Somehow doesn't look quite the same as when I was comparing it earlier but anyway...

Code:
Date		MarginBot Returns	 noggin-scratcher Return
10/31/2014 0.0727% 0.0677%
11/1/2014 0.0701% 0.0630%
11/2/2014 0.0715% 0.0672%
11/3/2014 0.0706% 0.0665%
11/4/2014 0.0699% 0.0662%
11/5/2014 0.0667% 0.0640%
11/6/2014 0.0651% 0.0639%
11/7/2014 0.0652% 0.0605%
11/8/2014 0.0615% 0.0595%
11/9/2014 0.0598% 0.0568%
11/10/2014 0.0589% 0.0597%
11/11/2014 0.0582% 0.0590%
11/12/2014 0.0577% 0.0590%
11/13/2014 0.0764% 0.0996%
11/14/2014 0.0891% 0.0983%
11/15/2014 0.0751% 0.0634%
11/16/2014 0.0689% 0.0674%
11/17/2014 0.0727% 0.0690%
11/18/2014 0.0713% 0.0708%
11/19/2014 0.0701% 0.0719%
11/20/2014 0.0691% 0.0725%

Ah, have located the difference between now and earlier; was previously using the 5 d.p. numbers quoted higher up the thread, which appear to have mostly rounded up slightly when cut down to 3 d.p. -- using the more detailed figures for MarginBot, and my actual start/end balance, I make the overall percentages +1.45037% for the bot and +1.43566% for my efforts. Which if I've done the right calculations would be 28.438% and 28.115% if extended over the course of a full year.

End conclusion: I'm spending a lot of time on not quite keeping up with a surprisingly simple algorithm. I should probably get a bot.

Bitfinex referral code: uOaxAuXdVX
HowardF (OP)
Full Member
***
Offline Offline

Activity: 145
Merit: 100

I do Stuff, and stuff.....


View Profile
November 21, 2014, 07:46:12 PM
 #19

Cool, for my own amusement, i'm going to add all these numbers into an excel file if you don't mind.  Looks like on an average day the bot out performs you by a tiny amount like you said, but you occasionally seem to have a much better day, which probably makes it pretty close to a wash, but i'd like to see the exact difference in a spreadsheet.

noggin-scratcher
Full Member
***
Offline Offline

Activity: 136
Merit: 100


View Profile
November 21, 2014, 07:54:04 PM
 #20

Cool, for my own amusement, i'm going to add all these numbers into an excel file if you don't mind.  Looks like on an average day the bot out performs you by a tiny amount like you said, but you occasionally seem to have a much better day, which probably makes it pretty close to a wash, but i'd like to see the exact difference in a spreadsheet.

No objection to the spreadsheet thing. If you want more numbers I have almost a year of 'em.

Bitfinex referral code: uOaxAuXdVX
Pages: [1] 2 3 4 5 6 7 8 9 10 11 12 13 14 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!