Search content
Sort by

Showing 20 of 49 results by butor
Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 13/06/2017, 03:19:42 UTC
I'm also curious how this is working with small amounts of exposure. The current lag time in transfers makes me think that this might be a lesson in futility if it takes 24 to 48 hours for a transaction to process with low fees. Or if the fees to process a transaction, makes the 2% return much smaller.

Besides rebalancing the accounts, there is no money transfers involved in the long/short strategy. So the transaction latency is not a concern.

The 2% return is net of exchange fees.
Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 01/06/2017, 14:03:21 UTC

Is there plans for OKCoin  Shorting to be implemented?

A first implementation is work in progress (link here). but hasn't been finished yet.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 09/07/2016, 14:44:28 UTC

Ah, right. I understand now. If that's the case, would it be easier to send the maximum amount available (without slippage) on one exchange to both exchanges?
Ie: exchange 1 has ask price 550 with amount 5, exchange 2 has bid price 600 with amount 10. You then place buy/sell orders for an amount of 5 on both exchanges. Ensuring no slippage.

That would be a possibility yes, but usually a discrepancy between prices tends to last a little bit. So it would be better to wait until you have enough liquidity to match your exposure. For example you don't want Blackbird to trade for $24 when the exposure you set is $5,000. I think it's better to wait until you have enough liquidity to send $5,000 orders.


Out of curiosity do you only examine the order book prices to a depth of 1? Seems like by doing so there'd be a few missed opportunities. However to examine with a depth of two the maths is much more involved.

During the liquidity check, Blackbird reads the order book in depth until it reaches a price that would cover its liquidity needs. So it doesn't just examine the first depth but the following ones as well, if necessary.


Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 30/06/2016, 01:06:18 UTC

Could you explain the idea behind "OrderBookFactor"? How does the number have a correlation with the liquidity? If I set it at 3.0, is it 3x the spread, or?

As you've probably understood, to stay market neutral the two orders that you send to the exchanges have to be both executed immediately. Since Blackbird sends limit orders (and not market orders because it would be too risky), you have to make sure that the orders can be fully executed at the price you defined. Indeed, if there is not enough liquidity the orders will only be partially executed, and you won't be market neutral anymore.

To prevent that situation, Blackbird makes sure that there is at least 3 times (parameter OrderBookFactor) the liquidity in the order book at the limit price that was defined before executing a trade. So before sending a trade of 2.0 BTC at $500 for example, Blackbird will make sure that there is at least 6.0 BTC at $500 available. Actually it's not exactly $500 but the value defined by the parameter PriceDeltaLimit to give a little bit of margin. But let's ignore that to keep the example simple.

Now, what happens if you don't check the liquidity first? You detect an arbitrage opportunity at $500 (ask price) and you directly send a buy limit order 2.0@$500 to the exchange. But here is the order book of the exchange at that time:

Ask_Price
Size
$500.00
0.5
$502.00
3.2
$503.00
5.4

Your order will be filled for 0.5@$500 and will stay open for the remaining 1.5. If the other order that you send to the other exchange was completely executed, you will have an imbalance: 0.5 BTC vs. 2.0 BTC.

Note: we use 3 times the liquidity because we need some margin in case of slippage: this occurs when the price changes between the time you send the order and the time the exchange processes it.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 14/06/2016, 00:58:26 UTC

1a) Do you check for the bid/ask spread within an exchange?  If this is the case isn't this counter intuitive, since the more illiquid the market the more volatile it is? How then do you strike a balance between liquidity risk and potential volatility profits?

No, we only check the bid/ask difference between separated exchanges: bid on exchange A vs. ask on exchange B, ask on exchange A vs. bid on exchange B. We don't need to look at the bid/ask spread within an exchange to do arbitrage.


1b) A way to ensure 0% liquidity risk that I can see is by buying at the lowest ask price at Exchange 1 and selling at the highest bid price at Exchange 2. Of course this is a smaller spread, but if the markets are as volatile as they've been in the past few days then there should be a few opportunities.

This is exactly what Blackbird does. Once the spread threshold SpreadEntry is reached the system will buy at the ask and sell at the bid. This is called crossing the spread and helps ensuring an immediate execution.


2) For exchanges that offer short-selling/margin-trading but with no API to do so, have you considered pure web automation, with something like Selenium?  Of course this would be much slower than an API call. However if your polling timeframe is 5 seconds then generally speaking using a web automation framework would be well within those bounds.

I know Selenium a little bit and I don't think speed would be an issue as the tasks can be executed at a pretty fast pace. I'm sure that it might be possible to implement, but could be rather complex (credentials, order generation, waiting until the order is 100% filled, verification, etc) and not as robust as the REST calls we are using now. But technically yes I think it's definitely possible.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 01/06/2016, 02:00:39 UTC
Does it still need to short dealing with only cryptocurrency ?
I don't think I understand the question. Can you elaborate?

Time for transfert a far lower between market when dealing with cryptocurrency only but still need one or more hours to confirm transaction.
But i understand it's totally out of bot's strategy to perform any transfer between markets.
Yes that's correct. Since we want to be hedged against the market, the two orders (long and short) need to be executed as fast as possible. If we need a USD/CNY conversion before it will also have to be exectued as fast as possible. As you mentioned there is no money or bitcoin transfer in this project so the hours needed to confirm a transaction don't apply here.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 26/05/2016, 20:54:51 UTC
Hi!

Interesting project. Have you considered adding checks for triangular arbitrage opportunities? For example, coincheck.jp offers margin trading (so does okcoin.cn for that matter) meaning that the bot could work for a triangular arbitrage between JPY/BTC/USD or CNY/BTC/USD. Also opens up plenty more exchanges.

The only forseeable problem is that you'd have to find a reliable website to convert USD<->JPY/CNY for the initial deposit into the balance, but that shouldn't be a problem considering the wealth of money exchange platforms out there (OFX, TransferWise, etc.)

Anyway, seriously interesting venture and I'll keep checking back on this.

Thanks. Yes this is something we've already considered (see previous posts on this thread). Adding this extra layer of currency conversion (e.g. USD/CNY) would generate more inefficiencies that can be captured as arbitrage opportunities. We will need to add the real-time currency rate into the spread calculation and the currency risk will need to be hedged.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 23/05/2016, 23:33:13 UTC
Good morning Butor,
Impressive work.

I see you only trade USD/BTC

Is it possible to change settings to do for exemple BTC/ETH on poloniex/kraken ?

Or is it only due to lake of short selling on both marketplace for such pair ?

Hi netmonk, thanks.

The structure of the code should allows programmers to (relatively) easily add new exchanges and new cryptocurrencies. Basically you "just" need to change the API calls from BTC to ETH. For example, the bid/ask information call on Bitfinex would change from:

https://api.bitfinex.com/v1/ticker/btcusd

to:

https://api.bitfinex.com/v1/ticker/ethbtc

And yes, at least one exchange needs to offer short selling on ETH and be implemented in Blackbird to do BTC/ETH arbitrage.

Warning: if you do BTC/ETH arbitrage you will be hedged against the market risk on ETH but not on BTC anymore. USD/BTC and USD/ETH would be safer, unless you are willing to accept BTC risk.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 26/02/2016, 15:36:38 UTC

Anyone know if you can margin trade on Bitfinex if you're in New York state? I can't exchange trade, but I can fund my margin account via wire transfer....so?

Does anyone know?

I have the same problem as you. This is due to the BitLicense license issued by the NY State Department of Financial Services.

Bitfinex decided to avoid having to comply to that license by imposing limitations to NY residents: we can no longer hold BTC on our accounts, among other things. More info here on their FAQ.

Fortunately, I opened an account on Bitfinex before the license so I can still margin trade to test Blackbird.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 20/02/2016, 16:54:22 UTC
Any thoughts on adding https://www.poloniex.com/ ? They allow margin trading

Quoting this to add to my project queue. Seems poloniex has a decent API: https://poloniex.com/support/api/

perhaps OP will add it, I am still waiting to see what happens on the chinese exchange now it is after New Years.  Smiley

Yes thanks, Poloniex sounds indeed promising as their API covers short selling with marginBuy and marginSell.

Unfortunately, I am not authorized to open an account on Poloniex since I live in New York. But I already created the generic files poloniex.h and poloniex.cpp if anyone wants to implement the functions.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 08/02/2016, 17:45:29 UTC

Do any implemented exchanges other than Bitfinex support short selling?

For the moment, only Bitfinex offers an API to short sell. We hope that 796.com will offer a similar API soon.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 07/02/2016, 14:57:46 UTC

I am really impressed by the project you are working on, using short selling is definitely a good idea to avoid fund transfer between exchanges (and the associated fees that would make arbitrage unprofitable).
But I have a few questions regarding how you tackle the inner risks of short selling. First of all, the potential loss while using short selling is (theoretically) infinite since the price has not an upper bound. Of course, since you are also buying, the winning would be as important as the loss. But this is true only if you strategy is perfectly market neutral, in other words: ONLY IF YOU BUY EXACTLY AT THE SAME TIME AS YOU SHORT SELL WITH EXACTLY THE SAME AMOUNT OF BTC. Your algorithm probably does not guarantee these two points so my question is did you try to assess the delay between short selling and buying? Did you assess the gap between them (in terms of btc amount)?

Thanks. The potential loss while using short selling is indeed infinite ...in theory. In reality, if your loss gets close to a defined amount of your account, you will get a margin call from the exchange. So you will never lose more than what you have on your margin account: if you only deposited $20 and you don't want to meet the margin calls then $20 will be your maximum loss.

That being said, Blackbird sends the two long and short orders at the same time. But if one is fully executed and not the other one (i.e. the market moved away from one order) then yes you won't be market neutral, that's correct. A solution would be to divide every order into child orders, e.g. a $50,000 order becomes 500 * $100 child orders. When you send your child orders you make sure than the number of already filled long orders is similar to the number of already filled short orders until all the orders are sent and fully filled. So the long/short unbalance would be $100 maximum at any time. That would be a nice implementation for Blackbird.

Meanwhile, note that to make sure the orders are almost instantly fully executed we do the following:

  • we always cross the spread
  • before we send an order we make sure that there is at least 3 times (by default) the liquidity in the order book than what we need for that order.


My second question is: you advise to use only small amounts to begin arbitraging (which is clearly prudent if we do not want to be ruined in a few minutes !). But if I run your algo, is my maximum loss really equal to my investment? Assume the algorithm goes crazy and order 1000btc for short selling! (The algo does need any money for that!) Assume the trend goes up... I could end up with 100000 dollars of debt due to the guys who borrowed me the btc even if I started to trade with 10$!!
How do you prevent this to happen, did you take this in account in your project or does the exchanges doing short selling prevent us from this event by rejecting too large short selling orders? If so what is the limit? 

Again, you will get a margin call from the exchange if your potential loss is above the limit. If you don't meet the margin call then the exchange will close your BTC position, usually at market price, and their loss will be covered by your margin account. So yes, you could entirely lose your margin account, but not more.

Note that as for now, Blackbird doesn't deal with margin calls.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 07/02/2016, 14:41:18 UTC

Is BTC-E currently working? I see it's implemented

No BTC-e is not yet implemented. From the README file:

The following exchange should be implemented soon:
  • BTC-e

I will post something here when the implementation is done.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 03/02/2016, 02:59:56 UTC
I got it resolved by removing 796.com for the moment and also opened an issue with them as i
* suspected it is an issue with their API
* wanted to know if they will enable short sells via API

;-)

I will probably go ahead and patch it into mine tonight, but leave it commented out until after New Year. Exciting times though, 796 support is very nice.

Fingers crossed their API will allow short selling. We would double the arbitrage opportunities!

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 02/02/2016, 05:08:08 UTC

Thanks mxnsch and siameze!

Hopefully it will be possible to programmatically short sell on 796.com. For the moment, we still only have Bitfinex that offers that feature.

PS: the Chinese New Year is next Monday (February 8th).
Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 30/01/2016, 23:15:14 UTC

I am currently trying to get 796 working, but struggling. Does anybody have a working 796 integration?

A first implementation of 796.com has been done (link to cpp file here) but has never been tested. The getLimitPrice() function has to be rewritten to match the other exchanges.

Note that 796.com only trade Bitcoin futures contracts.
Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 28/01/2016, 04:59:38 UTC

Hi enigma969, thank you for your interest.

Let's say I have 3000$ available to invest, what exchanges would you recommend? Should I split money up over all exchanges that are currently supported?

Yes, if you want to maximize your exposure you should put $1,500 on Bitfinex and $1,500 on one of the other supported exchanges. But please first test with a small amount of money!


What hosting solution do you recommend? You said something about a Google Server?

I don't have any specific recommendation. I personally use a laptop for programming and troubleshooting and a Google Cloud server (Compute Engine Micro) to run Blackbird 24/7.
The CPU and memory consumptions are usually low (C++ helps here) but you need a correct Internet connection.


I always get warnings like "WARNING: 2 second(s) too late at 01/26/2016 19:47:51" - It's because of latency right?

Yes this is probably due to the latency of your Internet connection. See a workaround here (issue #39).
Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 20/01/2016, 20:52:15 UTC

Is there any reason you don't have the files appending to make a bigger file?

I though the best way (and easiest way) was to create one log file per execution. Since Blackbird is supposed to run many days in a row, the size of a single log file can end up being hundreds of MB.


I wanted to just let it run for awhile and at a point, I started running into problems when it tries to execute trades.

It might be an issue with Kraken. I just uploaded a new version on GitHub that will give more details about the issue. Also, could you please open an issue on the issue page and we can continue from there? Thanks.


Max Iteration - means how long the bot should run right (in seconds?)

Yes that's correct, but not in seconds. DebugMaxIteration represents the number of market analysis loops. So Blackbird will run for approximately {DebugMaxIteration * GapSec} seconds.

Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 20/01/2016, 17:26:12 UTC
I got the bot working...Thanks for your help on github!  So I notice that the console doesn't pipe out data - I could only determine it was running by taking a peek at the logfile - is that expected behavior or should I see output in the console window running blackbird?   

Yes this is the expected behavior. We decided to output everything to a log file rather than the console.
Post
Topic
Board Trading Discussion
Re: Bitcoin arbitrage on GitHub: ~2% monthly return, market-neutral long/short
by
butor
on 20/01/2016, 04:29:46 UTC
This is because unfortunately Kraken doesn't provide the API to short sell programmatically for the moment. I really hope they will do it soon. Meanwhile, please change KrakenCanShort back to false. I will hardcode this value to avoid any confusion.

FYI, to avoid any confusion I just hardcoded the exchanges that can short sell and the ones that can't. As of today, only Bitfinex can short sell.

Thanks