Question: TIIIThis programming assignment will give you experience with using graphs, and crypto currency exchange trading.Different cryptocurrencies have different exchange rates. For example, the exchange rates
TIIIThis programming assignment will give you experience with using graphs, and crypto currency exchange trading.Different cryptocurrencies have different exchange rates. For example, the exchange rates for Bitcoin to Ethereum crypto currencies are:Bitcoin to Ethereum When the path to and from the nodes are in eq
Ethereum to Bitcoin for
The price is quoted as a currency pair and can be read as: if you have one bitcoin and you want to trade it for ethereum, you will receive ethereum for your one bitcoin. To create a graph, you will enter the nodesedges into the graph like this:nodefrom, nodeto directededgeweight Using this convention, here is the syntax to enter the currency pairs above, into a graph:
import networkx as nx
g nxDiGraph
gaddweightededgesfromethbtcbtc 'eth',
Your program will search the graph, for paths which maximize the amount of money traded from one currency to another. For example, to go from Bitcoin btc to Ethereum eth you would receive Ethereum coins. However, there also exists a path:
btcxrpbch 'eos', ltc 'eth'
If you start from bitcoin, and then trade to ripple, bitcoincash a separate currency from bitcoin eos, litecoin, to ethereum, you will receive Ethereum coins. An additional ethereum, which is worth $
Note: these are real prices, from coingecko, as of the time I wrote this assignment.
When this scenario occurs we refer to it as disequilibrium. Your program will search all paths in the graph from every currency to every other currency for all possible paths. Then your program will add logic to detect disequilibrium.
The easiest way to do this, is to find a path from node to node and also a path from node to node Then multiply the weights in the path from node to node and the weights in the path from node to node If the paths are in equilibrium, when you multiply the path weights they should be exactly
If the value when you multiply the path weights, is not exactly you have found disequilibrium, and an arbitrage opportunity!
Data Requirements
Your program will get exchange rates from coingecko
The coingecko API details for simpleprice can be found here:
coingecko api website
It returns the following JSON:
ethereum:eth:btc:"bitcoin":eth:btc:
Your program should parse the JSON, then enter the ticker symbol as the node name, for each currency pair. Meaning you only have one node for btcnot bitcoin like this:
gaddweightededgesfromethbtcbtc 'eth',
Your program only needs to trade the top crypto currencies there are hundreds more Use these ids and vscurrencies in the JSON api url above.
Note: the coin full name id and ticker vscurrencies are both required in the url to get the price quote.
Your program needs to get the most recent prices every time your program runs. Meaning you cannot copypaste the json by hand, save it and run your program.
Programming Requirements
You will need the following code snippets to create your graph, search paths, and calculate the weights.
We will be using the networkx python library for building graphs, because it is very easy to use. For documentation on networkx visit:
networkx
To create a graph:
import networkx as nx
g nxDiGraph
To add edges:
gaddweightededgesfromethbtcbtc 'eth',
To calculate the weight currency exchange rate of an edge:
gbtcethweight # returns
gethbtcweight # returns
To see all the nodes in a graph use:
gnodes # list of all nodes
To see all paths from node to node:
nxallsimplepathsgbtceth # returns every path from btc to eth Each path is returned as a list of strings.
The function above will return all paths from node to nodein this case btc and eth After you have all the paths from node to node your program needs to do the following for each path.
For each path from node to node calculate the weight of the path, by multiplying all the edges of the weights in the path.
For example, one of the paths from btc to eth is btcxrp 'eth'
To calculate the weight of the path multiply the weights of all the edges in the path:
gbtcxrpweight gxrpethweight #
Then calculate the weight of the reverse path. For the example above, the reverse path would be ethxrpbtc The path weight is calculated as follows:
gethxrpweight gxrpbtcweight #
Now that you have the weight of the path to and from node and node multiply them both:
When the path to and from the nodes are in equilibrium, the factor of both path weights, will be exactly
As you can see in this example
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
