Files
DisneyandGitHub d6399b92aa Feat/support binance (#22)
* add docs

* Add Binance exchange support

- Updated the environment configuration to include Binance as a selectable exchange option.
- Enhanced the README documentation to reflect the addition of Binance.
- Implemented the Binance exchange adapter and integrated it into the existing exchange framework.
- Modified the basis arbitrage strategy to support Binance alongside existing exchanges.
- Added tests to ensure proper functionality and integration of Binance within the trading system.

* Enhance README with detailed Binance exchange configuration

- Added comprehensive instructions for setting up Binance as an exchange option.
- Included environment variable specifications for API keys, market types, and trading symbols.
- Provided examples for both perpetual and spot trading strategies.
- Clarified the use of WebSocket and REST for the Binance adapter.

* Enhance exchange support and testing framework

- Added a new test suite for exchange contracts to ensure consistency and functionality across supported exchanges.
- Refactored exchange ID handling to utilize a centralized list of supported exchanges, improving maintainability.
- Updated CLI argument parsing and help documentation to reflect the new exchange structure.
- Introduced utility functions for validating supported exchanges and their display names.
- Enhanced the BasisApp and strategy runner to leverage the new exchange validation logic.
- Added a new test command for running exchange-related tests.

* Refactor exchange contract tests and update CLI commands

- Removed the trailing supported exchanges set and simplified the logic for trailing stop support in the exchange contract tests.
- Updated the test command for exchange contracts to exclude unnecessary tests, streamlining the testing process.
- Enhanced test descriptions for clarity and improved understanding of the functionality being tested.
2026-02-27 11:37:44 +08:00

12 KiB
Raw Permalink Blame History

title, source, fetched_at
title source fetched_at
General Info | Binance Open Platform https://developers.binance.com/docs/binance-spot-api-docs/testnet/general-info 2026-02-26T10:38:09.806Z

How can I use the Spot Test Network?

Step 1: Log in on this website, and generate an API Key.

Step 2: Follow the official documentation of the Spot API, replacing the URLs of the endpoints with the following values:

Spot API URLs

Spot Test Network URLs

  • https://api.binance.com/api

  • https://api-gcp.binance.com/api

  • https://api1.binance.com/api

  • https://api2.binance.com/api

  • https://api3.binance.com/api

  • https://api4.binance.com/api

  • https://testnet.binance.vision/api

  • https://api1.testnet.binance.vision/api

  • wss://ws-api.binance.com/ws-api/v3

  • wss://ws-api.binance.com:9443/ws-api/v3

  • wss://ws-api.testnet.binance.vision/ws-api/v3

  • wss://ws-api.testnet.binance.vision:9443/ws-api/v3

  • wss://stream.binance.com/ws

  • wss://stream.binance.com:9443/ws

  • wss://stream.testnet.binance.vision/stream

  • wss://stream.testnet.binance.vision:9443/stream

  • wss://stream.binance.com/stream

  • wss://stream.binance.com:9443/stream

  • wss://stream.testnet.binance.vision/stream

  • wss://stream.testnet.binance.vision:9443/stream

  • wss://stream-sbe.binance.com/ws

  • wss://stream-sbe.binance.com:9443/ws

  • wss://stream-sbe.testnet.binance.vision/ws

  • wss://stream-sbe.testnet.binance.vision:9443/ws

  • wss://stream-sbe.binance.com/stream

  • wss://stream-sbe.binance.com:9443/stream

  • wss://stream-sbe.testnet.binance.vision/stream

  • wss://stream-sbe.testnet.binance.vision:9443/stream

  • tcp+tls://fix-oe.binance.com:9000

  • tcp+tls://fix-oe.testnet.binance.vision:9000

  • tcp+tls://fix-dc.binance.com:9000

  • tcp+tls://fix-dc.testnet.binance.vision:9000

  • tcp+tls://fix-md.binance.com:9000

  • tcp+tls://fix-md.testnet.binance.vision:9000


Can I use the /sapi endpoints on the Spot Test Network?

No, only the /api endpoints are available on the Spot Test Network:


How to get funds in/out of the Spot Test Network?

All users registering on the Spot Test Network automatically receive a balance in many different assets. Please note that these are not real assets and can be used only on the Spot Test Network itself.

All funds on the Spot Test Network are virtual, and can not be transferred in/out of the Spot Test Network.


What are the restrictions on the Spot Test Network?

IP Limits, Order Rate Limits, Exchange Filters and Symbol Filters on the Spot Test Network are generally the same as on the Spot API.

All users are encouraged to regularly query the API to get the most up-to-date rate limits & filters, for example by doing:

curl "https://testnet.binance.vision/api/v3/exchangeInfo"


All my data has disappeared! What happened?

The Spot Test Network is periodically reset to a blank state. That includes all pending and executed orders. During that reset procedure, all users automatically receive a fresh allowance of all assets.

These resets happen approximately once per month, and we do not offer prior notification for them.

Starting from August 2020, API Keys are preserved during resets. Users no longer need to re-register new API Keys after a reset.


What is the difference between klines and uiKlines?

On the Spot Test Network, these 2 requests always return the same data.


What are RSA API Keys?

RSA API Keys are an alternative to the typical HMAC-SHA-256 API Keys that are used to authenticate your requests on the Spot API.

Unlike HMAC-SHA-256 API Keys where we generate the secret signing key for you, with RSA API Keys, *you* generate a pair of public+private RSA keys, send us the public key, and sign your requests with your private key.


What type of RSA keys are supported?

We support RSA keys of any length from 2048 bits up to 4096 bits. We recommend 2048 bits keys as a good balance between security and signature speed.

When generating the RSA signature, use the PKCS#1 v1.5 signature scheme. This is the default when using OpenSSL. We currently do not support the PSS signature scheme.


How can I use RSA API Keys?

Step 1: Generate the private key test-prv-key.pem. Do not share this file with anyone!

openssl genrsa -out test-prv-key.pem 2048

Step 2: Generate the public key test-pub-key.pem from the private key.

openssl rsa -in test-prv-key.pem -pubout -outform PEM -out test-pub-key.pem

The public key should look something like this:

-----BEGIN PUBLIC KEY-----bL4DUXwR3ijFSXzcecQtVFU1zVWcSQd0Meztl3DLX42l/8EALJx3LSz9YKS0PMQWMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAv9ij99RAJM4JLl8Rg47bdJXMrv84WL1OK/gid4hCnxo083LYLXUpIqMmL+O6fmXAvsvkyMyT520Cw0ZNCrUkWoCjGE4JZZGF4wOkWdF37JFWbDnE/GF5mAykKj+OMaECBlZ207KleQqgVzHjKuCbhPMuBVVD3IhjBfIc7EEM438LbtayMDx4dviPWwm127jwn8qd9H3kv5JBoDfsdYMB3k39r724CljqlAfX33GpbV2LvEkL6Da3OFk+grfN98X2pCBRz5+1N95I2cRD7o+jwtCr+65E+Gqjo4OI60F9Gq5GDcrnudnUw13a4zwlU6W+Cy8gJ4R0CcKTc4+VhYVX5wW2tzLVnDqvjIN8hjhgtmUv8hr19Wn+42ev+5sNtO5QAS6sJMJG5D+cpxCNhei1Xm+1zXliaA1fvVYRqon2MdHcedFeAjzVtX38+Xweytowydcq2V/9pUUNZIzUqX7tZr3F+Ao3QOb/CuWbUBpUcbXfGv7AI1ozP8LRByyu6O8Z1dZNdkdjWVt83maUrIJHjjc7jlZY9JbH6EyYV5TenjJaupvdlx72vA7Fcgevx87seog2JALAJqZQNT+t9/tmrTUSEp3t4aINKUC1QC0CYKECAwEAAQ==-----END PUBLIC KEY-----

Step 3: Register your public key on the Spot Test Network.

During registration, we will generate an API Key for you that you will have to put in the X-MBX-APIKEY header of your requests, exactly the same way as you would do for HMAC-SHA-256 API Keys.

Step 4: When you send a request to the Spot Test Network, sign the payload using your private key.

Here is an example Bash script to post a new order and sign the request using OpenSSL. You can adapt it to your favorite programming language:

#!/usr/bin/env bash# Set up authentication:API_KEY="put your own API Key here"PRIVATE_KEY_PATH="test-prv-key.pem"# Set up the request:API_METHOD="POST"API_CALL="api/v3/order"API_PARAMS="symbol=BTCUSDT&side=SELL&type=LIMIT&timeInForce=GTC&quantity=1&price=0.2"# Sign the request:timestamp=$(date +%s000)api_params_with_timestamp="$API_PARAMS&timestamp=$timestamp"signature=$(echo -n "$api_params_with_timestamp" \            | openssl dgst -sha256 -sign "$PRIVATE_KEY_PATH" \            | openssl enc -base64 -A)# Send the request:curl -H "X-MBX-APIKEY: $API_KEY" -X "$API_METHOD" \    "https://testnet.binance.vision/$API_CALL?$api_params_with_timestamp" \    --data-urlencode "signature=$signature"

What are Ed25519 API keys?

Ed25519 API keys are an alternative to RSA API keys, using asymmetric cryptography to authenticate your requests on the Spot API.

Like RSA API keys, Ed25519 keys are asymmetric: you generate a keypair, share the public key with Binance, and use your private key to sign requests.


Why use Ed25519 instead of RSA API keys?

Ed25519 digital signature scheme provides security comparable to 3072-bit RSA keys, while having much smaller signatures that are faster to compute:

API key type

Signature size

Signature operation

HMAC-SHA-256

64 bytes

0.00 ms

Ed25519

88 bytes

0.03 ms

RSA (2048-bit)

344 bytes

0.55 ms

RSA (4096-bit)

684 bytes

3.42 ms


How can I use Ed25519 API keys?

Step 1: Generate the private key test-prv-key.pem. Do not share this file with anyone!

openssl genpkey -algorithm ed25519 -out test-prv-key.pem

Step 2: Compute the public key test-pub-key.pem from the private key.

openssl pkey -pubout -in test-prv-key.pem -out test-pub-key.pem

The public key should look something like this:

-----BEGIN PUBLIC KEY-----MCowBQYDK2VwAyEACeCSz7VJkh3Bb+NF794hLMU8fLB9Zr+/tGMdVKCC2eo=-----END PUBLIC KEY-----

Step 3: Register your public key on the Spot Test Network.

During registration, we will generate an API key for you. Please put it in the X-MBX-APIKEY header of your requests, exactly the same way as with other API key types.

Step 4: When you send a request to the Spot Test Network, sign the payload using your private key.

Here is an example in Python that posts a new order signed with Ed25519 key. You can adapt it to your favorite programming language.

#!/usr/bin/env python3import base64import requestsimport timefrom cryptography.hazmat.primitives.serialization import load_pem_private_key# Set up authenticationAPI_KEY='put your own API Key here'PRIVATE_KEY_PATH='test-prv-key.pem'# Load the private key.# In this example the key is expected to be stored without encryption,# but we recommend using a strong password for improved security.with open(PRIVATE_KEY_PATH, 'rb') as f:    private_key = load_pem_private_key(data=f.read(),                                       password=None)# Set up the request parametersparams = {    'symbol':       'BTCUSDT',    'side':         'SELL',    'type':         'LIMIT',    'timeInForce':  'GTC',    'quantity':     '1.0000000',    'price':        '0.20',}# Timestamp the requesttimestamp = int(time.time() * 1000) # UNIX timestamp in millisecondsparams['timestamp'] = timestamp# Sign the requestpayload = '&'.join([f'{param}={value}' for param, value in params.items()])signature = base64.b64encode(private_key.sign(payload.encode('ASCII')))params['signature'] = signature# Send the requestheaders = {    'X-MBX-APIKEY': API_KEY,}response = requests.post(    'https://testnet.binance.vision/api/v3/order',    headers=headers,    data=params,)print(response.json())