0bps

Strategy vault / Tools & templates

Binance Websocket Subscription to Perpetual Contract Market Information

Python strategy by GCC.

Author
GCC
Complexity
Starter · 20 lines
Parameters
0

The original spec has no written description. Read the source below.

Source Python

import json
def main():
    LogStatus("Connecting...")
    # client = Dial("wss://stream.binance.com:9443/stream?streams=btcusdt@aggTrade/ethusdt@aggTrade|reconnect=true")    #Multiple trading pairs
    # client = Dial("wss://stream.binance.com:9443/ws/btcusdt@aggTrade|reconnect=true")    #Single trading pair
    # client = Dial("wss://dstream.binance.com/ws/btcusd_perp@aggTrade|reconnect=true")    #Coin-based,ticker
    client = Dial("wss://fstream.binance.com/ws/btcusdt@aggTrade|reconnect=true")
    if not client:    
        Log("Connection failed, Program exited")
        return
    while True:
        buf = client.read(-2)
        Log('tt',buf)
        if buf:
            obj = json.loads(buf)
            # Log(obj)
            # Log('Trading pair',obj['data']['s'], 'price', obj['data']['p']) #Multiple trading pairs 
            Log(obj['p'])    #Test
        Sleep(5000)
    client.close()

Published by GCC on the FMZ strategy square · last modified 2021-11-24. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a tested, production-ready module from strategies/Binance-Websocket-Subscription-to-Perpetual-Contract-Market-Information.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open