Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
yuyasugano / fetchOHLCV_test.py
Last active May 16, 2022
ccxt library in Python to fetch OHLCV data test
View fetchOHLCV_test.py
#!/usr/bin/python
import ccxt
import calendar
from datetime import datetim
binance = ccxt.binance()
now = datetime.utcnow()
unixtime = calendar.timegm(now.utctimetuple())
since = (unixtime - 60*60) * 1000 # UTC timestamp in milliseconds
@yuyasugano
yuyasugano / Flashswap.sol
Created Apr 3, 2022
New Flashswap code for BSC
View Flashswap.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.6 <0.8.0;
import './UniswapV2Library.sol';
import './interfaces/IERC20.sol';
import './interfaces/IUniswapV2Pair.sol';
import './interfaces/IUniswapV2Factory.sol';
import './interfaces/IUniswapV2Router02.sol';
@yuyasugano
yuyasugano / ohlcv.py
Created Sep 14, 2020
Obtain ohlcv data with ccxt library in Python
View ohlcv.py
#!/usr/bin/python
import ccxt
import calendar
from datetime import datetime, date, timedelta
binance = ccxt.binance()
def min_ohlcv(dt, pair, limit):
# UTC native object
since = calendar.timegm(dt.utctimetuple())*1000
@yuyasugano
yuyasugano / ema_backtesting.py
Created Aug 1, 2020
backtesting.py ema strategy
View ema_backtesting.py
from backtesting import Strategy
from backtesting.lib import crossover
def EMA_Backtesting(values, n):
"""
Return exponential moving average of `values`, at
each step taking into account `n` previous values.
"""
close = pd.Series(values)
return talib.EMA(close, timeperiod=n)
@yuyasugano
yuyasugano / Flashswap.sol
Created Oct 3, 2021
Modified Flashswap.sol for PancakeSwap & ApeSwap
View Flashswap.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.6 <0.8.0;
import './utils/SafeMath.sol';
import './UniswapV2Library.sol';
import './interfaces/IERC20.sol';
import './interfaces/IUniswapV2Pair.sol';
import './interfaces/IUniswapV2Factory.sol';
import './interfaces/IUniswapV2Router02.sol';
@yuyasugano
yuyasugano / profit.js
Last active Feb 19, 2022
arbitrage flashloan profit
View profit.js
...
const oneSplitRates = {
buy: new BigNumber(oneSplitResult1.returnAmount * unitRate).shiftedBy(-toTokenDecimals[j]).toString(),
sell: new BigNumber(oneSplitResult2.returnAmount).shiftedBy(-fromTokenDecimals[i]).toString()
}
console.log(`1inch Exchange ${targetTokens[j]}/${fromTokens[i]}: ${JSON.stringify(oneSplitRates)}`);
let profit = (oneSplitRates.sell - oneSplitRates.buy);
// profit needs to be eth price
if (fromTokens[i] != 'WETH') {
View authorizer.py
def lambda_handler(event, context):
token = event['authorizationToken']
effect = 'Deny'
if token == 'cs':
effect = 'Allow'
return {
'principalId': '*',
'policyDocument': {
'Version': '2012-10-17',
@yuyasugano
yuyasugano / stats.py
Created Nov 9, 2020
3 ways to do test of normality with Scipy library in Python
View stats.py
from scipy import stats
print('Skewness is {0} and Kurtosis is {1}'.format(stats.skew(a), stats.kurtosis(a, fisher=False)))
Skewness is 0.07652272048424928 and Kurtosis is 2.772732673807923
print('Skewness is {0} and Kurtosis is {1}'.format(stats.skew(b), stats.kurtosis(b, fisher=False)))
Skewness is -0.03504745242988745 and Kurtosis is 1.7525462915557393
stats.describe(a)
DescribeResult(nobs=1000, minmax=(-2.8249022278040115, 3.0569511100204605), mean=-0.053648592943343135,
variance=0.9768884437369372, skewness=0.07652272048424928, kurtosis=-0.2272673261920768)
@yuyasugano
yuyasugano / flashloan.js
Created Dec 19, 2021
MLC-FlashLoanDemo Example
View flashloan.js
// test a flashloan in Multipler V1
require('dotenv').config();
const Web3 = require('web3');
const BigNumber = require('bignumber.js');
const abis = require('./abis');
const instance = require('./build/contracts/Flashloan.json');
const web3 = new Web3(
new Web3.providers.HttpProvider(process.env.BSC_HTTPS)
);
@yuyasugano
yuyasugano / Flashloan.sol
Created Dec 19, 2021
MLC-FlashloanDemo Example
View Flashloan.sol
pragma solidity ^0.5.0;
import "./base/FlashLoanReceiverBase.sol";
import "./interfaces/ILendingPoolAddressesProvider.sol";
import "./interfaces/ILendingPool.sol";
contract Flashloan is FlashLoanReceiverBase {
address public receiver = address(this);
address public constant BNB_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;