Skip to content

Instantly share code, notes, and snippets.

View MtkN1's full-sized avatar

MtkN1 MtkN1

View GitHub Profile
@MtkN1
MtkN1 / bybit_ticker_ts.py
Created October 9, 2024 09:48
Add “ts” to the Bybit Ticker store
import asyncio
import pybotters
class CustomTicker(pybotters.DataStore):
_KEYS = ["symbol"]
def _onmessage(self, msg, topic_ext: list[str]) -> None:
item = msg["data"]
@MtkN1
MtkN1 / discord_notify.py
Last active October 8, 2024 03:11
Discord notify sample
import json
import os
import requests
# Discord の チャンネルの編集 -> 連携サービス -> ウェブフックを作成 -> ウェブフック URL をコピー で取得できる
WEBHOOK_URL = os.getenv("WEBHOOK_URL", "https://discordapp.com/api/webhooks/...")
# bitFlyer REST API で ticker を取得する (サンプル)
r = requests.get("https://api.bitflyer.com/v1/ticker")
@MtkN1
MtkN1 / bittrade_http.py
Last active September 6, 2024 18:30
pybotters 1.5 Sample code
# /// script
# requires-python = ">=3.8"
# dependencies = [
# "pybotters>=1.5",
# "rich>=9.1",
# ]
# ///
import asyncio
import os
@MtkN1
MtkN1 / pydantic_cattrs_timeit.ipynb
Created July 28, 2024 16:00
pydantic vs. cattrs performance
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MtkN1
MtkN1 / README.md
Created June 6, 2024 07:54 — forked from florimondmanca/httpx-urllib3.md
URLLib3 transport implementation (Extracted from HTTPX)

urllib3-transport

An HTTPCore transport that uses urllib3 as the HTTP networking backend. (This was initially shipped with HTTPX.)

When used with HTTPX, this transport makes it easier to transition from Requests to HTTPX by keeping the same underlying HTTP networking layer.

Compatible with: HTTPX 0.15.x, 0.16.x (i.e. HTTPCore 0.11.x and HTTPCore 0.12.x).

Note: not all urllib3 pool manager options are supported here — feel free to adapt this gist to your specific needs.

@MtkN1
MtkN1 / pyproject.toml
Created May 10, 2024 08:54
pyproject.toml differences between Hatch v1.9 and v1.10
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "hatch-demo"
dynamic = ["version"]
description = ''
readme = "README.md"
requires-python = ">=3.8"
@MtkN1
MtkN1 / noxfile.py
Created April 4, 2024 14:06
nox for Rye (it works, sort of)
import nox
import os
from pathlib import Path
PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]
VENV_BACKEND = "uv"
def ensurepath():
rye_home = os.getenv("RYE_HOME")
@MtkN1
MtkN1 / Dockerfile
Created March 26, 2024 13:01
Dockerfile for uv
# build stage
FROM python:3.12-bookworm AS build
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.cargo/bin:$PATH"
WORKDIR /app
COPY requirements.txt requirements.txt
@MtkN1
MtkN1 / tmp.pOln6CFBQq.py
Created February 5, 2024 15:15
Rate limit test for GMO Coin WebSocket
import asyncio
import json
import logging
from contextlib import AsyncExitStack
import websockets
logger = logging.getLogger("websockets.client")
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
@MtkN1
MtkN1 / model.py
Last active January 22, 2024 15:45
Binance Spot Pydantic Models from datamodel-code-generator
# generated by datamodel-codegen:
# filename: https://github.com/binance/binance-api-swagger/raw/master/spot_api.yaml
# timestamp: 2024-01-22T15:18:47+00:00
from __future__ import annotations
from typing import List, Optional
from pydantic import BaseModel, Field, RootModel