ndeloof:synx_exec go.mod import base64
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey from cryptography.hazmat.primitives.serialization import load_pem_private_key
def logon_raw_data(private_key: Ed25519PrivateKey, sender_comp_id: str, target_comp_id: str, msg_seq_num: str, sending_time: str): """ Computes the value of RawData (96) field in Logon message. """ payload = chr(1).join([ 'A', sender_comp_id, target_comp_id, msg_seq_num, sending_time, ]) signature = private_key.sign(payload.encode('ASCII')) return base64.b64encode(signature).decode('ASCII')
with open('private_key.pem', 'rb') as f: private_key = load_pem_private_key(data=f.read(), password=None)
raw_data = logon_raw_data(private_key, sender_comp_id='5JQmUOsm', target_comp_id='SPOT', msg_seq_num='1', sending_time='20240612-08:52:21.613')cryptography.hazmat.primitives.serializationMaker Order: symbol=BTCUSDT side=BUY type=LIMIT quantity=1 price=20000 selfTradePreventionMode=NONE Taker Order: symbol=BTCUSDT side=SELL type=LIMIT quantity=1 price=20000 selfTradePreventionMode=NONE Result: No STP is triggered and the orders will match. Order status of the maker order: { "orderId": 292864713, "symbol": "BTCUSDT", "status": "FILLED", "clientOrderId": "43N239GaUaqshfG7825184", "price": "20000", "avgPrice": "20000", "origQty": "1", "executedQty": "1", "cumQty": "1", "cumQuote": "20000", "timeInForce": "GTC", "type": "LIMIT", "reduceOnly": false, "closePosition": false, "side": "BUY", "positionSide": "BOTH", "stopPrice": "0", "workingType": "CONTRACT_PRICE", "priceMatch": "NONE", "selfTradePreventionMode": "NONE", "goodTillDate": 0, "priceProtect": false, "origType": "LIMIT", "updateTime": 1692849639460} Order status of the taker order: { "orderId": 292864714, "symbol": "BTCUSDT", "status": "FILLED", "clientOrderId": "43N239GaUaqshfG7825184", "price": "20000", "avgPrice": "20000", "origQty": "1", "executedQty": "1", "cumQty": "1", "cumQuote": "20000", "timeInForce": "GTC", "type": "LIMIT", "reduceOnly": false, "closePosition": false, "side": "SELL", "positionSide": "BOTH", "stopPrice": "0", "workingType": "CONTRACT_PRICE", "priceMatch": "NONE", "selfTradePreventionMode": "NONE", "goodTillDate": 0, "priceProtect": false, "origType": "LIMIT", "updateTime": 1692849639460} Scenario B: User sends an order with “EXPIRE_MAKER” that would match with their orders that are already on the book. Scenario C: User sends an order with “EXPIRE_TAKER” that would match with their orders that are already on the book. Scenario D: User has an order on the book, and then sends an order with “EXPIRE_BOTH” that would match with the existing order. Scenario E: User has an order on the book with “EXPIRE_MAKER”, then sends a new order with “EXPIRE_TAKER” which would match with the existing order. Maker Order: symbol=BTCUSDT side=BUY type=LIMIT quantity=1 price=20002 selfTradePreventionMode=EXPIRE_MAKER Taker Order: symbol=BTCUSDT side=SELL type=LIMIT quantity=1 price=20000 selfTradePreventionMode=EXPIRE_TAKER Result: The taker order's STP mode will be triggered, so the taker order will be revoked. Maker order: { "orderId": 292864710, "symbol": "BTCUSDT", "status": "NEW", "clientOrderId": "testMaker1", "price": "20002", "avgPrice": "0.0000", "origQty": "1", "executedQty": "0", "cumQuote": "0", "timeInForce": "GTC", "type": "LIMIT", "reduceOnly": false, "closePosition": false, "side": "BUY", "positionSide": "BOTH", "stopPrice": "0", "workingType": "CONTRACT_PRICE", "priceMatch": "NONE", "selfTradePreventionMode": "EXPIRE_MAKER", "goodTillDate": 0, "priceProtect": false, "origType": "LIMIT", "time": 1692849639460, "updateTime": 1692849639460} Taker order: { "orderId": 292864712, "symbol": "BTCUSDT", "status": "EXPIRED_IN_MATCH", "clientOrderId": "testTaker1", "price": "20000", "avgPrice": "0.0000", "origQty": "1", "executedQty": "0", "cumQuote": "0", "timeInForce": "GTC", "type": "LIMIT", "reduceOnly": false, "closePosition": false, "side": "SELL", "positionSide": "BOTH", "stopPrice": "0", "workingType": "CONTRACT_PRICE", "priceMatch": "NONE", "selfTradePreventionMode": "EXPIRE_TAKER", "goodTillDate": 0, "priceProtect": false, "origType": "LIMIT", "time": 1692849639460, "updateTime": 1692849639460} Scenario F: User sends a market order with “EXPIRE_MAKER” which would match with an existing order. 100 USD08:52:2120000292864713169284963946029286471420002292864710292864712100 Other Topics Home Support Center FAQ Crypto Derivatives Futures Contracts USDⓈ-M Futures Contracts What Is Self Trade Prevention (STP)? What Is Self Trade Prevention (STP)? 2023-08-29 11:33 What is Self Trade Prevention (STP)? Self Trade Prevention (STP) is a mechanism employed by trading platforms to prevent users from inadvertently trading against themselves. This situation, known as self-trading, occurs when a user's own orders match each other on the order book. STP is particularly important in maintaining a fair and transparent trading environment, as it helps to prevent manipulation of market prices and ensures that trading activity accurately reflects genuine market interest. At Binance, Self Trade Prevention (STP) prevents orders of users, or the user's “tradeGroupId”, to match against their own. What defines a self-trade? A self-trade can occur in either scenario: The order traded against the same account. The order traded against an account with the same “tradeGroupId”. What happens when STP is triggered? There are four possible modes for what the system will do if an order could create a self-trade. NONE: This mode exempts the order from self-trade prevention. Accounts or “tradeGroupIds” will not be compared, no orders will be revoked, and the trade will occur. EXPIRE_TAKER: This mode prevents a trade by immediately revoking the taker order's remaining quantity. EXPIRE_MAKER: This mode prevents a trade by immediately revoking the potential maker order's remaining quantity. EXPIRE_BOTH: This mode prevents a trade by immediately revoking both the taker and the potential maker orders' remaining quantities. STP will occur depending on the STP mode of the taker order. Thus, the STP mode of an order that goes on the book is no longer relevant and will be ignored for all future order processing. How do I set STP mode for an order? STP can only be set using field “selfTradePreventionMode” through the API endpoints below: POST /fapi/v1/order POST /fapi/v1/batchOrders What is a “tradeGroupId”? Different accounts with the same “tradeGroupId” are considered part of the same "trade group". Orders submitted by members of a trade group are eligible for STP according to the taker order's STP mode. A user can confirm if their accounts are under the same “tradeGroupId”' from the API from GET fapi/v2/account (REST API). If the value is -1, then the “tradeGroupId“ has not been set for that account, the STP may only take place between orders of the same account. Which symbols support STP? All symbols in GET fapi/v1/exchangeInfo support STP. Which order types support STP? The following order types support STP when Time in force (timeInForce) is set to GTC/IOC/GTD: Limit order Market order Take profit order Stop market order Take profit market order Trailing stop market order Please note that STP won't take effect for Time in force (timeInForce) in FOK or GTX. Do modify orders support STP? No. Modify orders do not support STP. How to tell if an order is revoked due to STP? The order status will be shown as “EXPIRED_IN_MATCH”. In the user data stream event “ORDER_TRADE_UPDATE”, the field X will show “EXPIRED_IN_MATCH” if an order is revoked due to STP. { "e":"ORDER_TRADE_UPDATE2023-08-29 11:33- 👋 Hi, I’m @Suliamanshirsad
- 👀 I’m interested in ...
- 🌱 I’m currently learning ...
- 💞️ I’m looking to collaborate on ...
- 📫 How to reach me ...
- 😄 Pronouns: ...
- ⚡ Fun fact: ...