Skip to content

Instantly share code, notes, and snippets.

jmoz / gist:17c1060cc2344e2662ea159a1cfd825c
Created March 1, 2023 19:13
Minimal .gitlab-ci.yml to run tests via docker
image: docker/compose:latest
- docker:dind
- build
- test
- deploy
jmoz / Dockerfile
Created January 15, 2023 13:25
Minimal Python 3.11-slim Dockerfile
FROM python:3.11-slim
RUN mkdir /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 /
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 /
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 / 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
RUN mkdir /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 /
Created July 1, 2020 10:52
asyncio aiohttp FTX prices
import asyncio
import aiohttp
symbols = [
jmoz / ftx_websockets.js
Created June 2, 2020 07:59
FTX Websockets Javascript
const symbols = [
const ws_init = function () {
ws = new WebSocket("wss://");
jmoz /
Created May 12, 2020 13:31
FTX API get balance
import FtxClient
c = FtxClient(
balance = c.get_balances()
btc_total = next((b['total'] for b in balance if b['coin'] == 'BTC'))
jmoz /
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 /
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
and fix
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.