0bps

Strategy vault / Other

ZT Exchange Interface Can Be Used for Connecting Platforms; Currently Does Not Support Less Popular Exchanges ZT

Python strategy by BTC[策略代写]团队.

PythonOther
Author
BTC[策略代写]团队
Complexity
Starter · 72 lines
Parameters
0

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

Source Python

#!Python3

"""
"Strategy writing » and (this program helps), write toQQ:35787501

ZT Exchange interface, can be used to connect exchanges not currently supported by the platform ZT
"""

from requests import get, post
from hashlib import md5
from urllib.parse import urlencode


class ZT:
    def __init__(self, api_key, secret_key):
        self.api_key = api_key
        self.secret_key = secret_key
        self.host = "https://www.ztb.im"
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                          'AppleWebKit/537.36 (KHTML, like Gecko) '
                          'Chrome/92.0.4515.159 Safari/537.36',
            "content-type": "application/x-www-form-urlencoded",
            'X-SITE-ID': '1',
        }

    def http_post(self, path, params):
        return post(f"{self.host}{path}", data=urlencode(params), headers=self.headers, timeout=5)

    def get_sign(self, params):
        return md5((urlencode(params) + f"&secret_key={self.secret_key}").encode()).hexdigest().upper()

    def get_ticker(self, symbol):
        return float(
            get(
                f"{self.host}/api/v1/trades?symbol={symbol}&size=1", headers=self.headers, timeout=5
            ).json()[0]["price"]
        )

    def send_order(self, symbol, side, price, amount):
        path = "/api/v1/private/trade/limit"
        params = {
            "amount": amount,
            "api_key": self.api_key,
            "market": symbol,
            "price": price,
        }
        all_side = {"close_sell": 1, "open_buy": 2}
        params["side"] = all_side[side]
        params["sign"] = self.get_sign(params)
        return str(self.http_post(path, params).json().get("result", {'id': "0"})["id"])

    def select_order(self, symbol, oid):
        path = "/api/v1/private/order/pending/detail"
        params = {
            "api_key": self.api_key,
            "market": symbol,
            "order_id": oid,
        }
        params["sign"] = self.get_sign(params)
        return not self.http_post(path, params).json()['result']

    def cancel_order(self, symbol, oid):
        path = "/api/v1/private/trade/cancel"
        params = {
            "api_key": self.api_key,
            "market": symbol,
            "order_id": oid,
        }
        params["sign"] = self.get_sign(params)
        return self.http_post(path, params).json()

Published by BTC[策略代写]团队 on the FMZ strategy square · last modified 2023-04-20. 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 production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/ZT-Exchange-Interface-Can-Be-Used-for-Connecting-Platforms;-Currently-Does-Not-Support-Less-Popular-Exchanges-ZT.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