Skip to content

Instantly share code, notes, and snippets.

@normanlmfung
normanlmfung / gist:75cacda0065a717cf0fd311ae372ee45
Created July 19, 2021 02:17
python_profile_example_nested_func
import cProfile
from pstats import Stats, SortKey
import random
import hashlib
import time
def _perf_test_A():
for i in range(1000000):
i = random.randint(0, 100)
# _perf_test_B(i)
@normanlmfung
normanlmfung / gist:8bc9135606d526a92a8aa474c6f70030
Created July 19, 2021 03:39
python_performance_test_redis_vs_postgres
from datetime import datetime, date
import numpy as np
from numpy.random.mtrand import f
import pandas as pd
import cProfile
from pstats import SortKey, Stats
from pandas.core.frame import DataFrame
'''
@normanlmfung
normanlmfung / gist:211fe6116117a04d5b5bca16ba43888f
Last active September 21, 2021 04:54
ccxt.binance.load_markets retrieve perpetuals
import ccxt
from typing import Dict
class binanceperps(ccxt.binance):
def describe(self) -> Dict:
description = super().describe()
description["options"]["defaultType"] = "future"
return description
apiKey = 'lala'
secret = 'lala'
@normanlmfung
normanlmfung / gist:e83ba4e492286cdbedd777d28b37fe70
Created September 21, 2021 04:43
Binance ADAUSD_211231 contract specification
{
‘percentage’: True,
‘feeSide’: ‘get’,
‘tierBased’: False,
‘taker’: 0.0005,
‘maker’: 0.0001,
‘precision’: {
‘base’: 8,
‘quote’: 8,
‘amount’: 0,
@normanlmfung
normanlmfung / gist:e2336d2f0e5141c0e07f0709130b59f5
Last active September 21, 2021 04:48
Binance BTC/USDT Perpetual contract specification
{
‘percentage’: True,
‘feeSide’: ‘get’,
‘tierBased’: False,
‘taker’: 0.0004,
‘maker’: 0.0002,
‘precision’: {‘base’: 8, ‘quote’: 8, ‘amount’: 3, ‘price’: 2},
‘limits’: {‘amount’: {‘min’: 0.001, ‘max’: 1000.0},
‘price’: {‘min’: 556.72, ‘max’: 4529764.0}, ‘cost’: {‘min’: 5.0, ‘max’: None},
‘market’: {‘min’: 0.001, ‘max’: 100.0}},
@normanlmfung
normanlmfung / gist:101d5b21e2190f11d16111ccffbde684
Created September 24, 2021 02:59
binance BTCUSD_PERP contract specification
{
'percentage': True,
'feeSide': 'get',
'tierBased': False,
'taker': 0.0005,
'maker': 0.0001,
'precision': {
'base': 8,
'quote': 8,
'amount': 0,
@normanlmfung
normanlmfung / gist:4cc9de2359b7ff1f15df0d6f7008f31b
Last active November 18, 2021 09:28
ccxt: check consistency in field names from exchange.load_markets
from typing import Dict
from dotmap import DotMap
import ccxt
class binanceperps(ccxt.binance):
def describe(self) -> Dict:
description = super().describe()
description["options"]["defaultType"] = "future"
return description
@normanlmfung
normanlmfung / gist:770640edb2b3a1b732850aab8a8ff5c6
Last active October 10, 2021 01:00
generic position and pnl calculation
import sys
import time
import traceback
from datetime import datetime
from typing import Any, Dict, List
from gizmo.datetime_gizmo import timer
class PosPnl(object):
def __init__(self, ticker) -> None:
@normanlmfung
normanlmfung / gist:cc06568019f07dc3d189a8da30bfa22e
Last active October 10, 2021 00:59
ftx positiona and pnl calc
import arrow
from datetime import datetime
from typing import Dict, List
from gizmo.datetime_gizmo import timer
from src.mds.ccxt.ftx import CasinoFtx
from gizmo import pnl_gizmo
apiKey = 'lalala'
secret = 'lalala'
# https://huobiapi.github.io/docs/dm/v1/en/#query-history-transactions-via-multiple-fields
import re
import hmac
import base64
import requests
import hashlib
import urllib.parse as _urlencode
import datetime
import json
import collections