<p>There is opensource asset exchange called <a href="https://github.com/peatio/peatio" rel="nofollow noreferrer">Peatio</a> written in ruby. You can look into its source code to see what happens with assets during their lifetime there.</p>

<p>Mainly there are 3 steps for exchange:</p>

<ol>
<li>Deposit - put real coins to exchange's accounts</li>
<li>Exchange - change coins, by changing just values of accounts' balances</li>
<li>Withdraw - send real coins from exchange's accounts to end user</li>
</ol>

<p>When user sends deposit request, exchange generates new address (sends rpc request to btc node), and assigns it to deposit entity in db. User have to send sufficient amount of btc, to fulfill deposit. When special daemon watcher finds incoming transaction to the address assigned to some deposit entity, it compares incoming amount with required one and waits for confirmations. If there are enough btcs and confirmations - daemon increases amount of user's account balance.</p>

<p>Then, during user's exchanges, exchange engine just changes numbers in db, so no real transactions are provided. This allows very fast fast and network fee free exchanges.</p>

<p>When user decides to spend bitcoins from account, he sends withdrawal request to exchange. Exchange checks user's balance and if there are enough coins, sends them from its wallet to user's address and decreases user's balance</p>

<p>In such system security of the main server is critical. All coins are stored on wallets of the system and can be spent by it. So cold wallet is usually used in such exchanges. Nearly 90% of total amount of all coins are sent to some secured wallet: hardware wallet or at least wallet, that is stored on a system that doesn't have internet connection. When there is not enough coins on hot wallet to create withdrawal, alert is sent to admin, and he manually sends some coins from cold wallet to hot.</p>

<p>If you don't want to allow trading, and just want exchange, you can remove Exchange step, and create withdrawal just after deposit fulfillment. But then you have to determine price of the pair.</p>

<p>This is not the only approach to asset exchanges. There are also approaches when users control their wallets on exchange, and approaches when decisions to change user's balance are taken by several nodes together.</p>

CC BY-SA 3.0
2018-03-06T07:11:18.253Z
Really good answer, some technical doubts cleared. Thanks :-)
Vishal Dalve
CC BY-SA 3.0
2018-03-05T16:39:07.773Z
2018-03-05T16:39:07.773Z
MartinSolie
<p>I'm a softawre developer &amp; newly involved in Blockchain Technology. </p>

<blockquote>
  <p><strong>I need information about How Cryptocurrency Exchange Technically work?</strong>
  <strong>i.e Buy ETH using BTC or exchanging any coin with another coin etc</strong>.</p>
</blockquote>

<p>I know all the other terms/things needed for exchange like, Legal, security, KYC, peer to peer etc.</p>

<p>I search many articles but didn't found any <strong>technical architecture</strong>. found following</p>

<blockquote>
  <p>There are readymade API's like <strong>block.io, chain.com, blockcypher.com</strong> etc who provide such thing.
  but want to develope it from core ie <strong><em>bitcoind Github</em></strong>.</p>
</blockquote>

<ul>
<li>I have good conceptual knowledge of Blockchain, Solidity etc.</li>
<li>Working with Bitcoin Core for creating new address, sending BTC to another address vai CMD prompt.</li>
<li>Able to implement Block Explorer etc.</li>
<li>Able to create new Coin/Currency in Solidity using ETH Compiler.</li>
</ul>

<p>What I really need is Direction &amp; path to follow.
<strong>As the technology is new, resources are very few. Any technical help I really appreciate.</strong></p>

<p>Thank you, Have a great day.</p>

CC BY-SA 3.0
2018-03-05T08:47:32.333Z
Welcome to bitcoin.SE! I think it will be difficult to find such advise here. Mostly we are here to answer technical questions, but yours is extending to the conceptual level. And other exchanges would keep the way, how they do trading between the cryptos as a secret. There is a p2p exchange (https://github.com/bisq-network/exchange), which might have sources that you can look into...
pebwindkraft
CC BY-SA 3.0
2018-03-05T08:59:08.363Z
@pebwindkraft Thanks very much for sharing link. Its valuable for me. Is their anything that you can help(links,docs,pdf,groups), kindly share on vd30992@gmail.com
Vishal Dalve
CC BY-SA 3.0
2018-03-09T05:21:01.517Z
Why my question is on HOLD ??? Can anybody explain??
Vishal Dalve
CC BY-SA 3.0
2018-03-10T06:30:00.193Z
most likely because the way an exchange works is very hard to be answered in a single thread, and also it has very little to do with technical aspects of bitcoin :-)
pebwindkraft
CC BY-SA 3.0
2018-03-10T07:27:43.320Z
@pebwindkraft I agreed but no one even want to share a little amount of knowledge about it like #MartineSolie did. Is their any medium to ask such kind of questions?
Vishal Dalve
CC BY-SA 3.0
2018-03-10T07:33:25.263Z
I have done a quick search in bitcoin.SE, and found three links to "how do exchange work". Also bitcointalk.org maybe a forum to search for.
pebwindkraft
<bitcoin-core><blockchain><exchanges><cryptography><solidity>
Cryptocurrency Exchange Technical architecture? How to build it? (Developer Point of View)
Vishal Dalve
# Cryptocurrency Exchange Technical architecture? How to build it? (Developer Point of View)

(Asked by: username_0 on 2018-03-05)

I'm a softawre developer & newly involved in Blockchain Technology.

> **I need information about How Cryptocurrency Exchange Technically work?**
> **i.e Buy ETH using BTC or exchanging any coin with another coin etc**.

I know all the other terms/things needed for exchange like, Legal, security, KYC, peer to peer etc.

I search many articles but didn't found any **technical architecture**. found following

> There are readymade API's like **block.io, chain.com, blockcypher.com** etc who provide such thing.
> but want to develope it from core ie ***bitcoind Github***.

* I have good conceptual knowledge of Blockchain, Solidity etc.
* Working with Bitcoin Core for creating new address, sending BTC to another address vai CMD prompt.
* Able to implement Block Explorer etc.
* Able to create new Coin/Currency in Solidity using ETH Compiler.

What I really need is Direction & path to follow.
**As the technology is new, resources are very few. Any technical help I really appreciate.**

Thank you, Have a great day.

**Tags:** bitcoin-core, blockchain, exchanges, cryptography, solidity

> **Comments:**
> **username_1**: Welcome to bitcoin.SE! I think it will be difficult to find such advise here. Mostly we are here to answer technical questions, but yours is extending to the conceptual level. And other exchanges would keep the way, how they do trading between the cryptos as a secret. There is a p2p exchange (https://github.com/bisq-network/exchange), which might have sources that you can look into...  
> **username_0**: @username_1 Thanks very much for sharing link. Its valuable for me. Is their anything that you can help(links,docs,pdf,groups), kindly share on vd30992@gmail.com  
> **username_0**: Why my question is on HOLD ??? Can anybody explain??  
> **username_1**: most likely because the way an exchange works is very hard to be answered in a single thread, and also it has very little to do with technical aspects of bitcoin :-)  
> **username_0**: @username_1 I agreed but no one even want to share a little amount of knowledge about it like #MartineSolie did. Is their any medium to ask such kind of questions?  
> **username_1**: I have done a quick search in bitcoin.SE, and found three links to "how do exchange work". Also bitcointalk.org maybe a forum to search for.  

---

## 1 answers

### Answer by username_2 on 2018-03-05. Score: 3 | Accepted answer

There is opensource asset exchange called [Peatio](https://github.com/peatio/peatio) written in ruby. You can look into its source code to see what happens with assets during their lifetime there.

Mainly there are 3 steps for exchange:

1. Deposit - put real coins to exchange's accounts
2. Exchange - change coins, by changing just values of accounts' balances
3. Withdraw - send real coins from exchange's accounts to end user

When user sends deposit request, exchange generates new address (sends rpc request to btc node), and assigns it to deposit entity in db. User have to send sufficient amount of btc, to fulfill deposit. When special daemon watcher finds incoming transaction to the address assigned to some deposit entity, it compares incoming amount with required one and waits for confirmations. If there are enough btcs and confirmations - daemon increases amount of user's account balance.

Then, during user's exchanges, exchange engine just changes numbers in db, so no real transactions are provided. This allows very fast fast and network fee free exchanges.

When user decides to spend bitcoins from account, he sends withdrawal request to exchange. Exchange checks user's balance and if there are enough coins, sends them from its wallet to user's address and decreases user's balance

In such system security of the main server is critical. All coins are stored on wallets of the system and can be spent by it. So cold wallet is usually used in such exchanges. Nearly 90% of total amount of all coins are sent to some secured wallet: hardware wallet or at least wallet, that is stored on a system that doesn't have internet connection. When there is not enough coins on hot wallet to create withdrawal, alert is sent to admin, and he manually sends some coins from cold wallet to hot.

If you don't want to allow trading, and just want exchange, you can remove Exchange step, and create withdrawal just after deposit fulfillment. But then you have to determine price of the pair.

This is not the only approach to asset exchanges. There are also approaches when users control their wallets on exchange, and approaches when decisions to change user's balance are taken by several nodes together.

> **Comments:**
> **username_0**: Really good answer, some technical doubts cleared. Thanks :-)  

---

