BitShares Forum

Main => General Discussion => Topic started by: maqifrnswa on August 27, 2014, 01:55:53 pm

Title: How you can help the economy: Arbitrage for programmers
Post by: maqifrnswa on August 27, 2014, 01:55:53 pm
Many here are technically inclined, but not necessarily financially experienced. Right now bitsharesx is still in its infancy, and as such has small liquidity. That creates an opportunity for profit by arbitrage. Such profit also injects liquidity - so it's a win-win.

Here are two quick ways you can participate:
1) Inter-exchange arbitrage If you know the "true" market rate for BTSX in dollars (e.g., from coinmarketcap/bter/btc38 prices), you can trade the spread between such a "true" price and the price trading for BTSX:USD in bitsharesx:
fill in the gaps...

Code: [Select]
while True:
    time.sleep(2)
    new_price = get_true_price()
    sec_since_update += 2
    if abs(new_price - last_price) / last_price > (SPREAD / 3):
        log("Price moved  -  old:  %f   new:  %f" % (last_price, new_price))
        log("Seconds since previous update:  %d" % sec_since_update)

        client.cancel_all_orders("USD", SYMBOL)
        client.wait_for_block()
        usd_balance = client.get_balance("USD")
        btsx_balance = client.get_balance(SYMBOL)
        client.submit_bid(0.3*(usd_balance * new_price), SYMBOL, new_price * (1+SPREAD), "USD")
        client.submit_ask(0.3*btsx_balance, SYMBOL, new_price * (1-SPREAD), "USD")
        last_price = new_price

2) Three-legged arbitrage If you can trade BTSX:BitUSD (bitsharesx), BitUSD:BTC (https://bter.com/trade/btc_bitusd), and BTC:BTSX (https://bter.com/trade/BTSX_BTC), you can use arbitrage to generate more coins if the exchange rates are not "correct":
right now (1400 UTC 2014-08-27) if I start with 1 BTSX and convert it to BTC then BITUSD then back to BTSX I end up with
1* 0.0000710 BTC/BTSX * 551.00 BitUSD/BTC * 26.698008 BTSX/USD = 1.044452771
That means if there are no fees, and I just buy one BTC then use that to buy BitUSD thenuse that to buy BTSX, and I end up with 4% more BTSX then I started with, free money.

3) Discount trading just check this out, and act accordingly:
https://bter.com/trade/BITUSD_USD
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: yellowecho on August 27, 2014, 02:44:07 pm
I have a little programming experience but don't feel comfortable enough to execute the code (and risk placing incorrect orders stuck in a while loop).  Could someone comment each line of code and further explain the details?  For instance, what does the function 'get_true_price()' actually do?  Where does it get that price and what does the function do?  Does it pull from an internal price feed?  And from the looks of it SYMBOL and SPREAD are the only variables that need to be modified to 'fill in the gaps'.. am I reading that correctly?  Gah, I'm such a n00b  :D
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: maqifrnswa on August 27, 2014, 02:50:04 pm
I have a little programming experience but don't feel comfortable enough to execute the code (and risk placing incorrect orders stuck in a while loop).  Could someone comment each line of code and further explain the details?  For instance, what does the function 'get_true_price()' actually do?  Where does it get that price and what does the function do?  Does it pull from an internal price feed?  And from the looks of it SYMBOL and SPREAD are the only variables that need to be modified to 'fill in the gaps'.. am I reading that correctly?  Gah, I'm such a n00b  :D

The gaps include writing the functions in that skeleton, including get_true_price() and all the client.*. It's up to the programmer to choose where and how to get the price; there is no internal price feed for that.
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: biophil on August 27, 2014, 02:50:41 pm
I have a little programming experience but don't feel comfortable enough to execute the code (and risk placing incorrect orders stuck in a while loop).  Could someone comment each line of code and further explain the details?  For instance, what does the function 'get_true_price()' actually do?  Where does it get that price and what does the function do?  Does it pull from an internal price feed?  And from the looks of it SYMBOL and SPREAD are the only variables that need to be modified to 'fill in the gaps'.. am I reading that correctly?  Gah, I'm such a n00b  :D

I'm in the same boat. It's killing me to have my BTSX stake just sitting around when arbitrage opportunities are growing on trees. I'd tip heavily to get my hands on a nice modular arbitrage tool.

Sent from my SCH-S720C using Tapatalk 2

Title: Re: How you can help the economy: Arbitrage for programmers
Post by: soniq on August 27, 2014, 02:52:16 pm
I have a little programming experience but don't feel comfortable enough to execute the code (and risk placing incorrect orders stuck in a while loop).  Could someone comment each line of code and further explain the details?  For instance, what does the function 'get_true_price()' actually do?  Where does it get that price and what does the function do?  Does it pull from an internal price feed?  And from the looks of it SYMBOL and SPREAD are the only variables that need to be modified to 'fill in the gaps'.. am I reading that correctly?  Gah, I'm such a n00b  :D

I'm in the same boat. It's killing me to have my BTSX stake just sitting around when arbitrage opportunities are growing on trees. I'd tip heavily to get my hands on a nice modular arbitrage tool.

Sent from my SCH-S720C using Tapatalk 2

I second that
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: bytemaster on August 27, 2014, 02:56:57 pm
Keep in mind that the arb bot probably needs to factor in relative short/long demand... the strategy that works "long term" (flux around "true price") is not the best "short term" which is "flux around premium".   

The "premium" we see right now suggests that the rate of return demanded on BitUSD is about 14% between "now" and "when the peg hits parity".     
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: biophil on August 27, 2014, 02:58:55 pm
Keep in mind that the arb bot probably needs to factor in relative short/long demand... the strategy that works "long term" (flux around "true price") is not the best "short term" which is "flux around premium".   

The "premium" we see right now suggests that the rate of return demanded on BitUSD is about 14% between "now" and "when the peg hits parity".   

Agreed, but zero-delay arbitrage across exchanges works no matter what your time horizon is.

Sent from my SCH-S720C using Tapatalk 2

Title: Re: How you can help the economy: Arbitrage for programmers
Post by: maqifrnswa on August 27, 2014, 03:19:10 pm
Agreed, but zero-delay arbitrage across exchanges works no matter what your time horizon is.

This is what I'm thinking - exchanges have liquidity, bitsharesx doesn't at the moment, so let's inject some of that exchange liquidity into bitsharesx using zero-delay arb.
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: bytemaster on August 27, 2014, 03:20:18 pm
Agreed, but zero-delay arbitrage across exchanges works no matter what your time horizon is.

This is what I'm thinking - exchanges have liquidity, bitsharesx doesn't at the moment, so let's inject some of that exchange liquidity into bitsharesx using zero-delay arb.

+1... lots of financial incentive out there for people to develop this :)
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: bitmeat on August 27, 2014, 03:20:50 pm
Be mindful to take into account liquidity and exchange fees.
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: xeroc on August 27, 2014, 06:20:40 pm
+1... lots of financial incentive out there for people to develop this :)
... and not release the code ..

a.k.a ... not deliver until unprofitable ... (reminds you of sth.?)
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: luckybit on August 27, 2014, 06:52:26 pm
I have a little programming experience but don't feel comfortable enough to execute the code (and risk placing incorrect orders stuck in a while loop).  Could someone comment each line of code and further explain the details?  For instance, what does the function 'get_true_price()' actually do?  Where does it get that price and what does the function do?  Does it pull from an internal price feed?  And from the looks of it SYMBOL and SPREAD are the only variables that need to be modified to 'fill in the gaps'.. am I reading that correctly?  Gah, I'm such a n00b  :D

How are we supposed to use the code? Does it connect to the RPC API or what?
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: luckybit on August 27, 2014, 06:55:11 pm
I have a little programming experience but don't feel comfortable enough to execute the code (and risk placing incorrect orders stuck in a while loop).  Could someone comment each line of code and further explain the details?  For instance, what does the function 'get_true_price()' actually do?  Where does it get that price and what does the function do?  Does it pull from an internal price feed?  And from the looks of it SYMBOL and SPREAD are the only variables that need to be modified to 'fill in the gaps'.. am I reading that correctly?  Gah, I'm such a n00b  :D

I'm in the same boat. It's killing me to have my BTSX stake just sitting around when arbitrage opportunities are growing on trees. I'd tip heavily to get my hands on a nice modular arbitrage tool.

Sent from my SCH-S720C using Tapatalk 2

I second that

We need a scripting language built into the interface somehow. It's that simple.
The more complicated it is to do the less people there will be doing it.

I can handle C++ but someone has to make a blog like "how to make bots using Bitshares API".

Then do a brief run through of the different functions. Best way to do it is let us input our scripts or our code directly into Bitshares. If it has to deal with compiling and the formulas for arbitrage aren't documented then less people will make bots.

+1... lots of financial incentive out there for people to develop this :)
... and not release the code ..

a.k.a ... not deliver until unprofitable ... (reminds you of sth.?)

I'm not even asking about the code. I want to know how to interact with the API so I can write my own code. Also I want the formulas which make up the underlying basis of the arbitrage bots.

As far as I know it gets a set of price feeds and compares them, then trades on the difference. The code itself is very simple for any programmer. It looks like it's using RPC API http://bitshares.org/documentation/group__rpc__api.html

I will see if I can write a script myself later today.

Title: Re: How you can help the economy: Arbitrage for programmers
Post by: xeroc on August 27, 2014, 07:21:52 pm
checkout:
https://bitsharestalk.org/index.php?topic=5562.0;all

Some of my own code (no market, just interface)
https://github.com/xeroc/pytshares/blob/master/btsrpcapi.py
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: maqifrnswa on August 28, 2014, 09:07:01 pm
checkout:
https://bitsharestalk.org/index.php?topic=5562.0;all

Some of my own code (no market, just interface)
https://github.com/xeroc/pytshares/blob/master/btsrpcapi.py

awesome, thanks - great demonsrtation of RPC calls

I wanted to modify the three-legged inter-exchange arbitrage to demonstrate another common case (one we're in right now)

bidask
BTC/BTSX0.00006550.000066
BitUSD/BTC540600
BTSX/BitUSD26.527

this is the current bter and bitsharesx snapshot. There is an opportunity for free, instant money there - while also evening out liquidity
1) the spread of BitUSD/BTC is so large that if you place a bid that is fulfilled less than    561.1672278339 or an ask greater than 576.1198329252, and you 2) move the exact same amount of what you purchased through the BTC->BTSX->BitUSD or BitUSD->BTSX->BTC chain, you will end up with more BitUSD and BTC than you started with, instantly.

Title: Re: How you can help the economy: Arbitrage for programmers
Post by: szert on August 28, 2014, 09:21:45 pm
Arbitrage requires a lot of liquidity but It's just such a pain to do it manually.

If someone already have a working arbitrage bot I'm more than happy to throw in some assets for operations.

 I understand that a sw for a proper arbitrage fund is complicated but to bring some liquidity and stabilise BTSX and BitUSD markets I'm happy to throw in some money with a gentleman's agreement :)
Title: Re: How you can help the economy: Arbitrage for programmers
Post by: emailtooaj on August 28, 2014, 09:28:13 pm
Arbitrage requires a lot of liquidity but It's just such a pain to do it manually.

If someone already have a working arbitrage bot I'm more than happy to throw in some assets for operations.

 I understand that a sw for a proper arbitrage fund is complicated but to bring some liquidity and stabilise BTSX and BitUSD markets I'm happy to throw in some money with a gentleman's agreement :)

I'm with szert, Count me in also please.