Skip to content

Instantly share code, notes, and snippets.

@jmoz
jmoz / ls_colors
Created January 18, 2010 13:18
ls_colors file to change colour of ls
# di=5;34;43 Setting the LS_COLORS di parameter to the above example will make directories appear in flashing blue text with an orange background
#0 = Default Colour
#1 = Bold
#4 = Underlined
#5 = Flashing Text
#7 = Reverse Field
#31 = Red
#32 = Green
#33 = Orange
#34 = Blue
@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.
@jmoz
jmoz / pagination.py
Created January 17, 2013 00:03
A Pagination class in Python.
class Pagination(object):
"""A Pagination object to be used for querying and displaying pagination links on frontend
Example usage:
>>> p = Pagination(total=15, per_page=5, current_page=1)
>>> p.start
0
>>> p.pages
[1, 2, 3]
@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 / pagination_tests.py
Created January 18, 2013 16:25
A unittest for Python Pagination class.
import unittest
from pagination import Pagination
class PaginationTest(unittest.TestCase):
def test_start(self):
p = Pagination(15, per_page=5, current_page=1)
self.assertEqual(0, p.start)
p.current_page = 2
@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 / DomXpath.php
Created June 26, 2012 14:49
DomXpath example
<?php
/**
* @author James Morris <james@jmoz.co.uk>
*/
$html = <<<'EOF'
<html>
<body>
<h1>Foo</h1>
<div id="content">
@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 / 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 / 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()