Skip to content

Instantly share code, notes, and snippets.

View ranaroussi's full-sized avatar

Ran Aroussi ranaroussi

View GitHub Profile
@ranaroussi
ranaroussi / api.py
Created December 22, 2015 11:10 — forked from alanhamlett/api.py
Serialize SQLAlchemy Model to dictionary (for JSON output) and update Model from dictionary attributes.
import uuid
import wtforms_json
from sqlalchemy import not_
from sqlalchemy.dialects.postgresql import UUID
from wtforms import Form
from wtforms.fields import FormField, FieldList
from wtforms.validators import Length
from flask import current_app as app
from flask import request, json, jsonify, abort
@ranaroussi
ranaroussi / premarket.py
Last active April 21, 2022 17:24
Retrieve Pre-Market data from Google Finance (python 3.x)
"""
Retrieve Pre-Market data from Google Finance
Ported to Python 3.x
Original code by Dr. Pawel Lachowicz
http://www.quantatrisk.com/2015/05/07/hacking-google-finance-in-pre-market-trading-python/
"""
import requests
import json
from time import sleep
@ranaroussi
ranaroussi / 00-pandas-profiling.ipy
Created February 6, 2016 13:37
pandas_profiling shorthand for ipython
# Place this script in
# ~/.ipython/profile_default/startup
# -------------------------------------------
import pandas_profiling
from pandas.core.base import PandasObject
def df_profile(df):
return pandas_profiling.ProfileReport(df)
@ranaroussi
ranaroussi / encrypt_decrypt.sh
Created August 29, 2016 20:20
openssl encrypt/decrypt shortcuts (for .bashrc/.bash_aliases)
# encrypt/descrupy
encrypt(){
if [ -z "$1" ]
then
echo "Missing argument: Use encrypt [in] [out]"
else
if [ -z "$2" ]
then
cp $1 /tmp/$1
openssl enc -aes-256-cbc -e -in /tmp/$1 -out $1
@ranaroussi
ranaroussi / eurusd_order.py
Last active March 5, 2023 11:10
order EUR.USD using ezIBpy
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import ezibpy
import time
# initialize ezIBpy
ibConn = ezibpy.ezIBpy()
ibConn.connect(clientId=1234, host="localhost", port=7497)
@ranaroussi
ranaroussi / ezibpy-callback
Last active June 1, 2017 15:23
ezIBpy: Tick Callback Example (repo: https://github.com/ranaroussi/ezibpy)
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import ezibpy
import time
# ---------------------
# create a callback method to be called on every tick/bid/ask
def ibCallback(caller, msg, **kwargs):
if "tick" in kwargs:
@ranaroussi
ranaroussi / ezibpy-stock-braket.py
Last active October 15, 2016 11:22
using ezIBpy to create a bracket order for AAPL
import ezibpy
import time
# initialize ezIBpy
ibConn = ezibpy.ezIBpy()
ibConn.connect(clientId=100, host="localhost", port=4001)
# create a contract
contract = ibConn.createStockContract("AAPL")
@ranaroussi
ranaroussi / df_to_file.py
Last active December 14, 2016 07:30
A Generic method to save Pandas objects to file, based on file extension found in the output path.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A Generic method to save Pandas objects to file,
based on file extension found in the output path.
Usage:
df.to_file("/path/to/file.csv")
"""
@ranaroussi
ranaroussi / plot_candlestick.py
Last active July 28, 2019 18:29
plot_candlestick
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
# future-compatibility with Panda 0.25
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
import numpy as np
@ranaroussi
ranaroussi / gist:557b9615ff79d98ec3bb7f4032bbedf7
Last active February 28, 2017 10:50
Example of a rapid prototyping of a strategy idea
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
example of a rapid prototyping of a strategy idea using pandas
(c) Ran Aroussi <http://aroussi.com>
"""
import matplotlib.pyplot as plt
from pandas_datareader import data