Schlagwortarchiv für: Trading

Overview

This is a simple working example of a flash arbitrage smart contract, whereby within a single transaction it:

  1. Instantly flash borrows a certain asset (ETH in this example) from Aave lending pools with zero collateral
  2. Calls UniswapV2 Router02 to wrap the flash liquidity of ETH into WETH and exchange it for DAI tokens
  3. Checks the exchange rate of DAI back into ETH on Sushiswap V1
  4. Calls SushiswapV1 Router02 to swap the DAI back into WETH and then ETH
  5. There’s also an independent function to withdraw all ETH and ERC20 tokens at the contract owner’s discretion

Before you start playing with this I highly recommend to have a read of the Aave Flash Loan mechanism and get an indepth conceptual understanding, as it’s equally important as understanding the code.

Since Sushiswap is a fork of UniswapV2, I also suggest familiarising yourself with the Uniswap V2 guide on trading via smart contracts, particularly if you plan on adding more swaps to your arbitrage strategy.

Deployment

The contract can be plonked directly onto Remix, using solidity compiler 0.6.12, and Metamask using Injected Web3.

On deployment, set the following parameters:

  • _AaveLendingPool: the LendingPoolAddressesProvider address corresponding to the deployment environment. see Deployed Contract Instances.
  • _UniswapV2Router: the Router02 address for UniswapV2 see here.
  • _SushiswapV1Router: the Router02 address for SushiswapV1. There isn’t an official testnet router02 so for demo purposes you can just use the uniswapV2 address when playing on the testnet since their codebase is identical (for now – which may not be the case in the future). Alternatively see Sushiswap repo for the mainnet router02 address to test in prod or deploy your own version of Router02 onto testnet.
  • Click ‚transact‘ and approve the Metamask pop up.
  • Once the flash arb contract is deployed, send some ETH or ERC20 token to this contract depending on what asset you’re planning to flash borrow from Aave in case you need extra funds to cover the flash fee.

Execution

On execution, set the following parameters:

  • _flashAsset: address of the asset you want to flash loan. e.g. ETH is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE. If you want to flash anything else see Reserved Assets but you will need to adjust the executeArbitrage() function accordingly.
  • _flashAmount: how much of _flashAsset you want to borrow, demoniated in wei (e.g. 1000000000000000000 for 1 ether).
  • _daiTokenAddress: for this demo we’re swapping with the DAI token, so lookup the reserved address of the DAI token. See Reserved Assets.
  • _amountToTrade: how much of the newly acquired _flashAsset you’d like to use as part of this arbitrage.
  • _tokensOut: how much of the ERC20 tokens from the first swap would you like to swap back to complete the arb. Denominated in actual tokens, i.e. 1 = 1 DAI token.
  • Click ‚transact‘ and approve in Metamask.

Result

If all goes well, a successful execution of this contract looks like this (Ropsten testnet).

Tips for further customization

  • This contract would typically be executed by a NodeJS bot (not part of this demo) via a web3.eth.Contract() call, referencing the deployed address of this contract and its corresponding ABI. You would usually get the bot to interact with price aggregators such as 1inch to assess arb opportunities and execute this contract if the right opportunity is found.
  • To have any chance of getting in front of other arb bots on significant arb opportunities the NodeJS bot needs to be hosted on your own fast Ethereum node. You will most likely come off second best going through the Infura API to interact with the Ethereum blockchain.
  • Some people like to get an unfair advantage by building Transaction-Ordering Dependence (front running) capabilities into the NodeJS component, typically using web3.eth.subscribe(‚pendingTransactions‘..) to monitor for newly submitted arb TXs. However this smart contract would then need to be significantly more complex and flexible enough to cater for a wide range of arbitrage permutations across multiple protocols.
  • User specified parameters (as opposed to hardcoded variables) should be passed via the flashloan() function in the first instance. You can subsequently set these parameters to contract variables with higher visibility across the contract.
  • There are no direct ETH pairs in UniswapV2 therefore the need for a WETH wrapper. Since Sushiswap is forked from UniswapV2 you’ll need to wrap in WETH as well.

If you found this useful and would like to send me some gas money:

0xef03254aBC88C81Cb822b5E4DCDf22D55645bCe6

Thanks, @fifikobayashi

Source: https://github.com/fifikobayashi/Flash-Arb-Trader

DISCLAIMER: This is not an investment advice or strategy; only an introductory material. If interested in using CDP, you should read more detailed materials involving more detailed descriptions of the liquidation process, fees, etc. Also, always do the math yourself and check your results. Do not trust the provided formulas if you have not checked they apply to your situation. Make sure you understand what you are doing. Be cautious and stay safe.

What is a CDP?

CDP is a Collateralized Debt Position, a smart contract where you store your ETH funds as collateral in order to take out a loan. Maker’s CDP allows you to take out a decentralized loan denominated in DAI stable coin.

As an ETH hodler, why should I care?

Suppose, as a true believer in Ethereum, you have invested all your available fiat into ETH already. Suddenly, there is a market situation such that you would like to “buy the dip” or simply increase your stack of ETH but you cannot since you have no fiat left. Nevertheless, thanks to CDP you can lock your already owned ETH as a collateral, take out a loan in DAI (~USD), and buy more ETH with it. This is called leverage and the principle is the same as margin trading.

What is the catch you are not telling me?

Well, the catch is that you have to repay your money otherwise your CDP gets liquidated and/or you lose your collateral. Please, never let your CDP liquidate! It is way more expensive than repaying.

Can you give an example of a bad loan setup?

Suppose you lock 150 ETH in CDP, Ether price is currently 900 USD. The max collateral/loan ratio of Maker CDP is currently set to 150%. Therefore, you can take out 90 000 DAI (100ETH*price) as a loan. Remember the loan is always in DAI. However, since you borrowed the maximum amount allowed (two-thirds of collateral), your liquidation price is exactly 900. If the price drops to 899.9, your CDP will be liquidated because its collateral is insufficient. Always make sure the liquidation price is sufficiently low.

OK, I see I shouldn’t go too much into debt here. Is that all?

No, there is another case that may arise. Suppose the previous situation, however, you take out only 30k Dai instead of 90k. Since your collateral/loan ratio is now higher, you are protected from liquidation as long as the price of ETH is above the liquidation price of around 300 USD (sounds sufficient). Remember again that the loan is denominated in DAI. If the ETH price goes to 500 USD, nothing changes and you still owe 30k DAI. This may cause issues when investing the borrowed funds. Suppose you invested the whole loan in ETH at the initial price of 900 but now one is worth 500 and you have no other money available. The CDP does not go into liquidation this time. However, you cannot repay the debt and free your collateral (you can partially but it’s still quite bad).

What do you suggest to avoid this?

If you plan to invest the borrowed DAI, never collateralize your entire bag of ETH. Always save an appropriate amount of money (form irrelevant) to be able to pay off the CDP at liquidation prices.

How do I find out how much is “appropriate”?

You need to do the math. I derived some formulas that may be helpful. They apply to the case of leveraging ETH only, i.e. using your bag of ETH to get a loan and invest in ETH again. As have been mentioned, you should have enough ETH left elsewhere to be prepared to repay the debt if the price begins to approach the liquidation price. I assume the purchase of ETH is at the same price as at the time the CDP is opened.

Notation: S = all ETH holdings you have prior to CDP, P = the current price of ETH in USD, LP = your desired liquidation price (yes, this is a parameter you must choose – please be cautious and set it at a safe low level that you consider unlikely to be reached)

Calculating the amount of ETH to deposit as collateral (deposit): D = S/[1-(2LP-2P)/3P]

Calculating the amount of DAI to “draw” from the CDP (loan): L = (2/3) *D *LP

Remember, you must always have S-D amount of ETH available to step in and avoid liquidation of your CDP. That should guarantee you are safe from the liquidation or the need to use additional funds. Nevertheless, it is still possible your investments will not be profitable and you end up losing money.

I am only waiting for the next paycheck and need the funds only temporarily to buy the dip right now. Can I collateralize my whole stack of ETH?

Yes, you can since you know you will get additional funds to repay the debt. However, remember not to go too much into debt to avoid liquidation.

I used the loan to buy ETH. Can I collateralize these funds as well?

Yes, you can but be VERY careful. You’d better do the math right! I would not recommend this since things may get messy and you may lose track of your debt easily.

I want to learn more and maybe get a CDP. What should I do next?

You should check the Maker CDP dashboard (https://dai.makerdao.com/) out and watch their introductory video and terminology guide. There is a couple of advanced things that I omitted and you should look into them (e.g. WETH, PETH). Further, visit the maker subreddit r/makerdao (please read the sad stories of liquidated CDPs) or other of their communities. Make sure you understand what you are doing before creating a CDP. It may be worth it to test the process on the Kovan testnet.

Why did you write this tutorial?

There was no complex material for beginners around that would highlight CDP’s possibilities as well as risks. I hope I introduced the instrument properly and it will get more traction eventually. Also, I am a big fan of the DAI stable coin.

I think there is something wrong in this text or something important is missing.

That is, of course, possible. In such a case, please, comment or pm me. I will be updating this text continuously.

DISCLAIMER: This is not an investment advice or strategy; only an introductory material. If interested in using CDP, you should read more detailed materials involving more detailed descriptions of the liquidation process, fees, etc. Also, always do the math yourself and check your results. Do not trust the provided formulas if you have not checked they apply to your situation. Make sure you understand what you are doing. Be cautious and stay safe.

Source: https://reddit.com

A new exchange has suddenly taken the crypto-space by storm, reaching 3 million users in mere six months since it launched on July 14th 2017 and growing so fast it temporarily does not accept new users at all.

“Servicing existing members is higher priority at this point,” Changpeng Zhao, Binance’s founder, says before further adding:

“Full team working around the clock. Both tech and support. Just too much demand. Added 250,000 new users in the last 24 hours. Just crazy!”

The Hong Kong based exchange held an ICO raising around 30,000 eth, currently worth $30 million, for 100 million BNB ECR20 tokens.

The raised funds are now dwarfed by BNB’s total market cap of some $1.2 billion with Binance’s founders holding half of it, but why did this exchange suddenly rise to top volumes of $10 billion in the past 24 hours, twice that of Bithumb?

The answer might be a number of reasons. First, it is the only exchange to offer Eth pairs, something many have asked for, especially with ever increasing bitcoin fees.

As such, instead of having no option but to buy, say, TRX with BTC, or a number of other coins/tokens, you can now choose whether to buy them with eth or with btc.

That in itself might have led to strong support by the eth community for the exchange and they indeed were the first to mention it in every two sentences.

Secondly, the ICO itself may have created a base of supporters who were monetarily incentivized to recommend the exchange.

With the third reason perhaps being that the team seems decent. Changpeng Zhao is no newcomer to this space. He was the third employee at blockchain.info and a co-founder as well as CTO at OKCoin.

He thus, presumably, knows a thing or two about exchanges. Binance boasts 1.4 million transactions a second, multilingual support, including in Chinese and Spanish, as well as multi-coin support.

It is probably the latter that has given rise to this exchange, proving once again that satisfying market demand can be very rewarding indeed.

Kraken used to be a lingering exchange of no one’s care until they added ethereum back when few had eth trading. Then, it suddenly became a player, until it could not keep up any longer with users given a catalogue of errors instead of a trading interface.

Binance might have perhaps risen in any event, but the market was demanding eth trading pairs, and with it so being the only exchange to provide them, it might perhaps be the primary reason it has so risen.

And with its rise, a new dimension might enter this space. Bitcoin’s only competitive advantage – trading pairs – might no longer be such an advantage as ethereum now enters to compete even in that area.

Source: trustnodes.com – Binance Adds 250,000 New Users a Day

Source: cuvialabs.com

Joel Monegro wrote an insightful piece on crypto-economics called “The Fat Protocol” .  In it,  he concludes that unlike the Internet which is monetized at the application level,  the Blockchain is monetized at the protocol level.    This is analogous to owning a piece of TCP/IP and deriving an economic benefit every time it is utilized.   We created the Monegro Index as a homage to Joel and to clearly illustrate and track this crypto-economic principle.

The economic implication of “The Fat Protocol” are many.   As an investor in a Blockchain application or sub-token,  you are giving up protocol token for app tokens,  which are arguably much less valuable.  As a blockchain app developer,  you are giving up app tokens in exchange for protocol tokens.   Unlike the Internet,  there is an economic disincentive to standardize.   Interesting to see how this all shakes out.

Weiterlesen

Source: simplytradingtips.comTwitterGoogle+PinterestEmailSumoMe

My look when I see candlestick

This was the exact reaction I had when I understood the power of reading candlestick charts and how reading them helped me become the boss of my own finances.

By the end of this post you will have a firm understanding on everything you need to know about candlestick charts as well as how to read candlestick charts like a pro. This guide will serve you as your personal reference when it comes to understanding candlestick charts; so bookmark this page right now.

Let’s begin!

Trading is a game, a game of war. It is the war between buyers and sellers, where Candlestick charts are scoreboards which indicate who is winning.

Candlestick charts need various data to form their shape; data about the sessions’ OHLC (Open, High, low and Close) price action. Each candlestick represents a single session, and a session can be of 1, 5,15, 30 minutes to hours or even days and weeks.

Reading candlestick charts and finding their patterns are as easy as learning how to drive. We might feel confused at first, but soon after the initial phase it becomes the easiest thing to do.

Candlestick charts are thought to have been invented by a Japanese named Homma. Since they were developed by the Japanese they are also known as “Japanese Candlestick charts”, and they were later introduced to the western world by “Steve Nison”.