Skip to content

Instantly share code, notes, and snippets.

View lvthillo's full-sized avatar

Lorenz Vanthillo lvthillo

View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@lvthillo
lvthillo / macd.py
Last active January 12, 2021 18:23
signal = stock_data['macds'] # Your signal line
macd = stock_data['macd'] # The MACD that need to cross the signal line
advice = ["No data"] # Since you need at least two hours in the for loop
for i in range(1, len(signal)):
# If the MACD crosses the signal line upward
if macd[i] > signal[i] and macd[i - 1] <= signal[i - 1]:
advice.append("BUY")
# The other way around
elif macd[i] < signal[i] and macd[i - 1] >= signal[i - 1]:
@lvthillo
lvthillo / rsi.py
Last active January 11, 2021 18:52
# Calculate RSI
stock_data['rsi_14']
print(stock_data)
# Get most recent RSI value of our data frame
# In our case this represents the RSI of the last 15 min
last_rsi = stock_data['rsi_14'].iloc[-1]
print(last_rsi)
# stock_data contains historical data of ETH/BTC with a period of 1 hhour
# the volume is calculated by using historical data
# run this as close to each 1h interval (e.g. 7.59h or 9.59m)
last_items = stock_data.tail(24)
print(last_items)
day_volume_self_calculated = last_items['volume'].sum()
print(day_volume_self_calculated)
# better way to do it
ticker = exchange.fetch_ticker(coin_pair)
@lvthillo
lvthillo / ohlcv.py
Last active January 12, 2021 18:18
import ccxt
import os
import re
import time
import pandas as pd
from stockstats import StockDataFrame as Sdf
def get_historical_data(coin_pair, timeframe):
"""Get Historical data (ohlcv) from a coin_pair
import ccxt
import os
import re
# configure exchange
exchange = getattr(ccxt, 'binance')({
'apiKey': os.environ['APIKEY'],
'secret': os.environ['SECRET'],
'timeout': 10000,
'enableRateLimit': True
@lvthillo
lvthillo / setup.py
Last active January 11, 2021 20:33
import ccxt
import os
# configure exchange
exchange = getattr(ccxt, 'binance')({
'apiKey': os.environ['APIKEY'],
'secret': os.environ['SECRET'],
'timeout': 10000,
'enableRateLimit': True
})
@lvthillo
lvthillo / publish.py
Created August 14, 2020 14:05
Python script to publish to SNS topic
import json
import boto3
client = boto3.client('sns')
mesg = json.dumps({
"default": "default",
"body": "this is a test"
})
response = client.publish(
@lvthillo
lvthillo / GreenHighQueueSubscription.yaml
Created August 14, 2020 13:24
GreenHighQueueSubscription
GreenHighQueueSubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint: !GetAtt GreenHighQueue.Arn
Protocol: sqs
FilterPolicy:
color:
- green
number:
- numeric:
@lvthillo
lvthillo / BlueYellowQueueSubscription.yaml
Created August 14, 2020 13:23
BlueYellowQueueSubscription
BlueYellowQueueSubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint: !GetAtt BlueYellowQueue.Arn
Protocol: sqs
FilterPolicy:
color:
- blue
- yellow
RawMessageDelivery: True