An inside look at our trading operations

User avatar
Steve Sokolowski
Posts: 1792
Joined: Wed Aug 27, 2014 3:27 pm
Location: State College, PA
Contact:

An inside look at our trading operations

Postby Steve Sokolowski » Thu May 12, 2016 9:08 am

At viewtopic.php?f=11&t=711, I provided an inside look at our daemon servers and how our architecture manages the 160 or so coins that we mine. Today, I will write another installment in this series that focuses on our trading infrastructure.

Prohashing allows mining of any scrypt coin and provides miners the choice to be paid in any coin, including coins that are not available for mining like Dash and Ethereum. Miners choose the proportions of coins that they want to be paid, and every share submission triggers an assignment of payout coins based on the current prices at the best available markets. As mining progresses, debts in coins requested for payout grow, while balances in coins being mined rise. The imbalance widens between the coins people are owed but we don't have, and the coins we mined but nobody wants. To avoid being a money transmitter, users are not permitted to deposit coins and they may not change their mind about the coins they are owed after a share is submitted.

A "balancer" runs periodically to solve this problem. It starts by examining the money we have on hand for each coin type - which is the total of the coins in our wallet and in every exchange, minus the withdrawal fees for that coin type in each exchange that has a positive balance of the coin. Then, the running debts to miners, which are updated upon each valid share submission, are subtracted from the debts calculated in the first step. The result of this calculation is a list of coins and their balances. Positive balances indicate that we have too many of that type of coin, and negative balances indicate that we have too few.

The next step is to rebalance our money so that our coins on hand are of the right type. To do that, coins that we have too many of are sold, and coins that we have too few of are purchased. Selling and buying use the same algorithm, so for the purpose of this example, I'll describe a situation where a coin has a surplus.

Selling a coin is a complex operation. Miners are paid based upon the value of the coin at the highest-priced market after all fees are paid, at the depth the market would be once the blocks we are currently holding have been sold. To achieve these prices, the top price at each exchange is compared. If there are enough coins in the exchange to cover the surplus and the highest order in the best market is large enough, then the sale occurs and the operation is finished. If not, then the entire best order is sold, and then the next best order is evaluated. This second-best order can be at the same exchange or at a different exchange. This process continues across exchanges until we have gotten rid of enough coins so that we only have enough remaining to cover owed balances.

Sometimes, however, the best value for our coins occurs through an "intermediate market." An example of such a market would be when Syscoins have markets trading for Litecoin, Bitcoin, and Monero. In that case, the system determines the adjusted price of Syscoins across all of these markets. To obtain the adjusted price of the SYS/LTC market, we might have:

Adjusted price = (best order of SYS/LTC) * (average price of selling the number of coins obtained from the sale of the best SYS/LTC order in LTC/BTC) - (trade fee for SYS/LTC) - (trade fee for LTC/BTC)

If this adjusted price is higher than the price of (SYS/BTC - trade fee for SYS/BTC), then multiple trades (selling the SYS, and then selling the obtained LTC) are executed to obtain BTC, which is the coin that is held for the pool's reserve. Otherwise, a direct trade occurs. The opposite is performed for buying coins if it is cheaper to purchase them through an intermediate market.

This algorithm needs to run frequently to keep the pool solvent at all times. The greatest risk to the pool occurs when a popular payout coin enters a bubble, and the balancer is unable to buy coins quickly enough. This situation occurred recently with Ethereum, when its price began rising so quickly that the ten minutes between balancer runs could result in losses of as much as 2%.

Other pool risks include forks and locked wallets. Forks are relatively easy to detect, because many exchanges provide their latest block number. If an exchange's block number falls outside of a specified range of the pool's block number, trading is automatically disabled at that exchange. If all exchanges report differing block numbers, then mining is disabled until the exchanges resolve the problem.

"Locked wallets" are a more difficult problem - these occur when exchanges, often without listing the reason, prevent deposits and withdrawals of a cryptocurrency. Yet, they allow trading to continue with the "paper coins" in the exchange. Cryptopia and Yobit do not provide an API to determine if a wallet is locked, and do not provide notification when a locking occurs. As a result, thousands of coins can be sent to a deposit address that is never credited to an exchange account. We are currently in the process of adding a "risk reduction factor" for these exchanges to artificially lower their prices. For example, if it is detected that 5% of our money is being lost at Cryptopia due to their locking wallets, then we will lower all Cryptopia prices by 5%. The artificially lower prices at Cryptopia will either result in more trades being executed at the more reliable exchange Poloniex, or will continue to execute trades at Cryptopia but earn us additional profit that is expected to be lost at some point in the future when one of their wallets is eventually locked.

At the end of every day, payouts are executed. Shortly after midnight, withdrawals are initiated for all exchanges to bring owed coins to our local wallets. After the transactions have had enough time to be mined, about six hours later payouts are sent. Sometimes, as happens frequently with the bitcoin network, payouts fail because transactions from all exchanges haven't yet confirmed, so they are retried later in the day. In the rare case that we had so much bad luck that our entire reserve was depleted, we delay payouts so that money can be pulled from bank accounts to purchase coins to make up the difference. In the more frequent case when more bitcoins than we need to hold as reserve accumulate in our wallets, Chris sells the excess bitcoins and either uses the dollars to pay down pool expenses or distributes the dollars as profit to the pool's owners.

The full details of the trader are far more complicated and two-thirds of the code is designed solely to prevent and deal with error conditions, but this general overview provides a window into the complexity of cryptocurrency trading. We execute between 1,500 and 50,000 trades per day, depending on which coins are being mined, to obtain the best price for coins across market pairs, and the trader is responsible for informing the mining server of the most likely price we can obtain for our coins. The codebase for the trading engine alone exceeds 5,000 lines. In future articles, I'll provide more details about how the mining server handles coin selection and assignment.
User avatar
CritterDog
Posts: 259
Joined: Tue Feb 23, 2016 12:21 pm

Re: An inside look at our trading operations

Postby CritterDog » Thu May 12, 2016 2:25 pm

Is this why I have not been paid my Vergecoin in 2 days and now today Bitcoin did not pay?
User avatar
Chris Sokolowski
Site Admin
Posts: 889
Joined: Wed Aug 27, 2014 12:47 pm
Location: State College, PA

Re: An inside look at our trading operations

Postby Chris Sokolowski » Fri May 13, 2016 5:29 am

Hi. I apologize for the delay. One of our daemon servers crashed and I just got it back online. The payouts have all executed.
gaanthony
Posts: 78
Joined: Mon Feb 01, 2016 8:42 pm

Re: An inside look at our trading operations

Postby gaanthony » Sat May 14, 2016 3:07 am

In thinking about the trading operations, from a miner perspective, the question that weights on my mind is, what is the most profitable coin in which to be paid; BTC, LTC, Ethereum, etc.? My preference has been Bitcoin, as I don't have the time nor patience to maintain multiple wallets and trade myself but do think sometimes it might be more profitable to take payout in another coin, but that'd require in my opinion a lot of monitoring of the various markets and various calculations. Do you have some insight that you could share?
User avatar
Steve Sokolowski
Posts: 1792
Joined: Wed Aug 27, 2014 3:27 pm
Location: State College, PA
Contact:

Re: An inside look at our trading operations

Postby Steve Sokolowski » Sat May 14, 2016 8:03 am

gaanthony wrote:In thinking about the trading operations, from a miner perspective, the question that weights on my mind is, what is the most profitable coin in which to be paid; BTC, LTC, Ethereum, etc.? My preference has been Bitcoin, as I don't have the time nor patience to maintain multiple wallets and trade myself but do think sometimes it might be more profitable to take payout in another coin, but that'd require in my opinion a lot of monitoring of the various markets and various calculations. Do you have some insight that you could share?


At the time coins are earned, there isn't any difference in profitability. You'll earn the same amount of money no matter which coin is paid.

However, transaction fees on the bitcoin network are high, which will cost you money. One way you can increase your profits is to get paid in a coin that has a high market capitalization, like Ethereum, so that you can then move it at a low gas cost rather than paying high bitcoin transaction fees when you want to spend it.

The most profitable way to be paid, however, is to create a Coinbase wallet and use it to store your bitcoin. Coinbase pays the transaction fees for outgoing payments, so you can save money by using them as your savings wallet. Centralized providers like Coinbase are the way bitcoin is heading because of the blocksize crisis, and another advantage of having your money in Coinbase is that you can sell out at any time. However, keep in mind that Coinbase tracks all transactions and disables accounts at random and often provides no reason, so the advantages of using Coinbase to save money are outweighed by the risks of Coinbase intruding on your privacy.
Some1notu
Posts: 59
Joined: Tue Oct 06, 2015 7:48 am

Re: An inside look at our trading operations

Postby Some1notu » Sun May 15, 2016 1:52 am

Coinbase sucks, use Circle.com
kutt
Posts: 5
Joined: Mon Aug 28, 2017 3:07 am

Re: An inside look at our trading operations

Postby kutt » Mon Aug 28, 2017 3:35 am

Some1notu wrote:Coinbase sucks, use Circle.com


Don't agree with you
User avatar
GregoryGHarding
Posts: 358
Joined: Sun Apr 16, 2017 3:01 pm
Contact:

Re: An inside look at our trading operations

Postby GregoryGHarding » Mon Aug 28, 2017 9:00 pm

kutt wrote:
Some1notu wrote:Coinbase sucks, use Circle.com


Don't agree with you



why did you bump a 4 month old post for that one liner?
------------------------------->View My Hashflare Earnings Spreadsheet<------------------------------
--------------------------------->Join the Prohashing Slack Group Here<--------------------------------

Return to “Prohashing Blog”

Who is online

Users browsing this forum: No registered users and 1 guest