This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # setup EMA indicator values | |
| def setup_ema(): | |
| ticksAgo = datetime.datetime.now() - timedelta(hours= 24) | |
| candlesticks = client.get_historical_klines(EXCHANGE, Client.KLINE_INTERVAL_3MINUTE, str(ticksAgo)) | |
| for candle in candlesticks: | |
| del candle[-6:] | |
| ema = pd.DataFrame(candlesticks, columns=['date', EXCHANGE+'_O', EXCHANGE+'_H', \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def telegram_EMA(sma, back=50, show=False): | |
| file = 'EMAs.jpg' | |
| ax = sma[-back:].plot(y="BTCUSDT_C", kind="line", color="k", \ | |
| linewidth=3, use_index=True, x_compat=True, \ | |
| rot=25, linestyle='-', figsize=(6, 5)) | |
| sma[-back:].plot(y="EMA20", kind="line", ax=ax, color="y", \ | |
| x_compat=True, rot=25, linestyle=':', figsize=(6, 5)) | |
| sma[-back:].plot(y="EMA50", kind="line", ax=ax, color="r", \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| file = "stats.jpg" | |
| # create your own numerical lists here... | |
| days = [30, 21, 14, 5, 2] | |
| data = [10, 19, 6, 34, 12] | |
| labels = days | |
| plt.xticks(range(len(data)), labels) | |
| plt.xlabel('Days') | |
| plt.ylabel('% Position Gain') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dateFrom = '2022-08-05 12:00:00' | |
| positionData = getPositionInfo(startDate=timezoneGMT(parser.parse(dateFrom)), exchange='BTCUSDT') | |
| file = coin +'.jpg' | |
| ax = plt.gca() | |
| dateFrom = str(timezoneGMT(parser.parse(dateFrom))) | |
| positionData.plot(kind='line',x='date',y=coin[:3],ax=ax, marker='.', \ | |
| title= coin[:3] +" since "+dateFrom) | |
| plt.savefig(file, bbox_inches='tight') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| client = Client(config.BINANCE_API_KEY, config.BINANCE_API_SECRET, tld='us') | |
| def getPositionInfo(startDate=None, exchange='BTCUSDT'): | |
| if not startDate: | |
| return | |
| candlesticks = client.get_historical_klines(exchange, Client.KLINE_INTERVAL_1HOUR, str(startDate)) | |
| # trim each candle | |
| for candle in candlesticks: | |
| del candle[-6:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| buyingQty, sellingQty = getBuyingDataETH(side='SELL') | |
| # SHORT SELL order | |
| headers={"Authorization":CMclient.bearerToken, 'Content-Type': 'application/x-www-form-urlencoded'} | |
| payload = {'orderType':'limit', 'buyingCurrency':'USD', 'sellingCurrency':'ETH', | |
| 'buyingQty':buyingQty, 'sellingQty':sellingQty, 'margin':'true', 'userData':'foo'} | |
| response = requests.request("POST", f'{COINMETRO}/exchange/orders/create', headers=headers, data=payload) | |
| responseJson = json.loads(response._content) | |
| orderID = responseJson['orderID'] | |
| print(responseJson) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| payload = {'orderType':'market', 'buyingCurrency':'USD', 'sellingCurrency':coin, | |
| 'sellingQty':pSize, 'margin':'true'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getBuyingDataETH(side, usd=None, eth=None): | |
| book = CMclient.get_full_book('ETHUSD') | |
| topBid = float(list(book['book']['bid'].items())[0][0]) | |
| topAsk = float(list(book['book']['ask'].items())[0][0]) | |
| spread = topAsk-topBid | |
| print('bid', topBid, 'ask', topAsk, 'spread', spread, '%', spread/topAsk*100) | |
| if side=='SELL': | |
| sellingQty = eth | |
| buyingQty = eth*topAsk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| payload = {'orderType':'limit', 'buyingCurrency':'ETH', 'sellingCurrency':'USD', | |
| 'buyingQty':buyingQty, 'sellingQty':sellingQty} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getAmountETH(positionSize, timeFrom): | |
| checkToken() | |
| latestPrice = CMclient.get_latest_trades(pair='ETHUSD', From=timeFrom)['tickHistory'][-1]['price'] | |
| buyAmount = float("{:.4f}".format(positionSize/latestPrice)) | |
| return latestPrice, buyAmount |
NewerOlder