Skip to content

Instantly share code, notes, and snippets.

@jmoz
jmoz / gist:17c1060cc2344e2662ea159a1cfd825c
Created March 1, 2023 19:13
Minimal .gitlab-ci.yml to run tests via docker
image: docker/compose:latest
services:
- docker:dind
stages:
- build
- test
- deploy
@jmoz
jmoz / Dockerfile
Created January 15, 2023 13:25
Minimal Python 3.11-slim Dockerfile
FROM python:3.11-slim
ENV PYTHONUNBUFFERED=1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt .
RUN apt-get update && apt-get -y install git libxml2-dev libxslt-dev gcc zlib1g-dev
RUN pip3 install --upgrade pip setuptools wheel
@jmoz
jmoz / ccxt_fetch_all_candles.py
Created August 24, 2022 02:43
ccxt fetch all candles
async def fetch_all_candles(self, symbol, timeframe='1d', limit=5000, end_time=None):
"""If `end_time` is passed it is inclusive in results.
This will page through all results and remove the duplicate record, finally make an extra call which will be
empty and break the generator. Had to make the extra call as `limit` was not always max 5000 sometimes it
returned 5001 or even 4995, so it was impossible to just break if the len() was < 5000.
Ccxt paging with `since` is broken, so we must use params end_time and hack the start_time to 0 else
library code will override and break pagination.
"""
@jmoz
jmoz / asyncio_producer_consumer.py
Created August 23, 2022 05:47
asyncio producer consumer basic layout
import asyncio
async def producer(queue):
i = 1
while True:
await queue.put(f'item {i}')
i += 1
await asyncio.sleep(5)
@jmoz
jmoz / Dockerfile
Created October 10, 2020 06:45
Dockerfile for Django, python-slim (requirements had Twisted which caused gcc and other errors)
FROM python:3.8-slim
ENV PYTHONUNBUFFERED=1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc build-essential \
&& pip3 install -r requirements.txt \
@jmoz
jmoz / Asyncio_aiohttp_FTX_prices.py
Created July 1, 2020 10:52
asyncio aiohttp FTX prices
import asyncio
import aiohttp
symbols = [
'BTC-PERP',
'ETH-PERP',
'EOS-PERP',
'BCH-PERP',
'LTC-PERP',
@jmoz
jmoz / ftx_websockets.js
Created June 2, 2020 07:59
FTX Websockets Javascript
const symbols = [
"BTC-PERP",
"BTC/USD",
"ETH-PERP",
"ETH/USD",
];
const ws_init = function () {
ws = new WebSocket("wss://ftx.com/ws/");
@jmoz
jmoz / ftx_api_balance.py
Created May 12, 2020 13:31
FTX API get balance
import FtxClient
c = FtxClient(
api_key='YOURKEY',
api_secret='YOURSECRET',
)
balance = c.get_balances()
print(balance)
btc_total = next((b['total'] for b in balance if b['coin'] == 'BTC'))
@jmoz
jmoz / ccxt_ftx_balance.py
Created May 12, 2020 11:40
Python CCXT FTX API get balance
import ccxt
c = ccxt.ftx({
'apiKey': 'YOURKEY',
'secret': 'YOURSECRET',
'enableRateLimit': True,
#'headers': {'FTX-SUBACCOUNT': 'YOURSUBACCOUNTNAME'}, # uncomment line if using subaccount
})
balance = c.fetch_balance()
@jmoz
jmoz / rsi.py
Created September 27, 2019 07:41
RSI calculation to match Tradingview
import pandas as pd
def rsi(ohlc: pd.DataFrame, period: int = 14) -> pd.Series:
"""See source https://github.com/peerchemist/finta
and fix https://www.tradingview.com/wiki/Talk:Relative_Strength_Index_(RSI)
Relative Strength Index (RSI) is a momentum oscillator that measures the speed and change of price movements.
RSI oscillates between zero and 100. Traditionally, and according to Wilder, RSI is considered overbought when above 70 and oversold when below 30.
Signals can also be generated by looking for divergences, failure swings and centerline crossovers.