پیتھون ورژن آئس برگ کمیشن کی حکمت عملی

مصنف:نیکی, تخلیق: 2020-07-21 10:21:10, تازہ کاری: 2023-10-26 20:08:29

img

یہ مضمون پیوند کاری کے لئے دو کلاسیکی حکمت عملی لاتا ہے: آئس برگ کمیشن (خرید/فروخت) ۔ یہ حکمت عملی ایف ایم زیڈ پلیٹ فارم کے آئس برگ کمیشن جاوا اسکرپٹ ورژن سے پیوند کی گئی ہے۔ حکمت عملی کا پتہ ہےhttps://www.fmz.com/square/s:Iceberg/1

آئس برگ کمیشن ٹریڈنگ حکمت عملی کے تعارف کا جاوا اسکرپٹ ورژن کا حوالہ دیتے ہوئے:

آئس برگ کمیشن اس حقیقت کا حوالہ دیتا ہے کہ جب سرمایہ کار بڑے پیمانے پر لین دین کرتے ہیں تو ، مارکیٹ پر ضرورت سے زیادہ اثر انداز ہونے سے بچنے کے ل large ، بڑے آرڈر کمیشن کو خود بخود متعدد کمیشن میں تقسیم کیا جاتا ہے ، جو موجودہ آخری خرید / فروخت 1 قیمت اور تاجر کے ذریعہ طے شدہ قیمت کی بنیاد پر ہوتا ہے۔ حکمت عملی خود بخود ایک چھوٹا آرڈر کمیشن کرتی ہے۔ جب آخری کمیشن مکمل طور پر لین دین کیا جاتا ہے یا آخری قیمت موجودہ کمیشن قیمت سے نمایاں طور پر انحراف کرتی ہے تو ، کمیشن آپریشن خود بخود دوبارہ شروع ہوجاتا ہے۔

بہت سے ایکسچینج ٹریڈنگ پیجز آئس برگ کمیشننگ ٹولز کے ساتھ آتے ہیں ، جن میں بھرپور افعال ہوتے ہیں ، لیکن اگر آپ اپنی ضروریات کے مطابق کچھ افعال کو اپنی مرضی کے مطابق بنانا چاہتے ہیں یا کچھ افعال میں ترمیم کرنا چاہتے ہیں تو ، آپ کو زیادہ لچکدار ٹول کی ضرورت ہے۔ ایف ایم زیڈ پلیٹ فارم کو اس مسئلے کو صحیح طریقے سے حل کرنے کے لئے ڈیزائن کیا گیا ہے۔ ہمارے حکمت عملی مربع میں بہت زیادہ پائتھون ٹریڈنگ حکمت عملی نہیں ہے۔ کچھ تاجر جو ٹریڈنگ ٹولز اور حکمت عملی لکھنے کے لئے پائتھون زبان کا استعمال کرنا چاہتے ہیں انہیں مثالوں کا حوالہ دینے کی ضرورت ہے۔ لہذا ، کلاسیکی آئس برگ کمیشننگ حکمت عملی کو پائتھون ورژن میں پورٹ کیا گیا ہے۔

آئس برگ کمیشن برائے پائیتھون - خریداری

import random  # Import random number library

def CancelPendingOrders():     # The function of CancelPendingOrders is to cancel all pending orders of the current transaction.
    while True:                # Loop detection, call GetOrders function to detect the current pending order, if orders is an empty array, that is, len(orders) is equal to 0, indicating that all orders have been cancelled, you can exit the function and call return to exit.
        orders = _C(exchange.GetOrders)
        if len(orders) == 0 :
            return 

        for j in range(len(orders)):     # Traverse the current array of pending orders, and call CancelOrder to cancel the orders one by one.
            exchange.CancelOrder(orders[j]["Id"])
            if j < len(orders) - 1:      # Except for the last order, execute Sleep every time and let the program wait for a while to avoid canceling orders too frequently.
                Sleep(Interval)

LastBuyPrice = 0       # Set a global variable to record the the latest buying price.
InitAccount = None     # Set a global variable to record the initial account asset information.

def dispatch():        # Main functions of iceberg commission logic
    global InitAccount, LastBuyPrice     # Reference global variables
    account = None                       # Declare a variable to record the account information obtained in real time for comparison calculation.
    ticker = _C(exchange.GetTicker)      # Declare a variable to record the latest market quotes.
    LogStatus(_D(), "ticker:", ticker)   # Output time and latest quotation in the status bar
    if LastBuyPrice > 0:                 # When LastBuyPrice is greater than 0, that is, when the commission has started, the code in the if condition is executed.
        if len(_C(exchange.GetOrders)) > 0:    # Call the exchange.GetOrders function to get all current pending orders, determine that there are pending orders, and execute the code in the if condition.
            if ticker["Last"] > LastBuyPrice  and ((ticker["Last"] - LastBuyPrice) / LastBuyPrice) > (2 * (EntrustDepth / 100)):   # Detect the degree of deviation, if the condition is triggered, execute the code in the if, and cancel the order.
                Log("Too much deviation, the latest transaction price:", ticker["Last"], "Commission price", LastBuyPrice)
                CancelPendingOrders()
            else :
                return True
        else :    # If there is no pending order, it proves that the order is completely filled.
            account = _C(exchange.GetAccount)     # Get current account asset information.
            Log("The buying order is completed, the cumulative cost:", _N(InitAccount["Balance"] - account["Balance"]), "Average buying price:", _N((InitAccount["Balance"] - account["Balance"]) / (account["Stocks"] - InitAccount["Stocks"])))  # Print transaction information.
        LastBuyPrice = 0   # Reset LastBuyPrice to 0

    BuyPrice = _N(ticker["Buy"] * (1 - EntrustDepth / 100))   # Calculate the price of pending orders based on current market conditions and parameters.
    if BuyPrice > MaxBuyPrice:    # Determine whether the maximum price set by the parameter is exceeded
        return True

    if not account:               # If account is null, execute the code in the if statement to retrieve the current asset information and copy it to account
        account = _C(exchange.GetAccount)

    if (InitAccount["Balance"] - account["Balance"]) >= TotalBuyNet:  # Determine whether the total amount of money spent on buying exceeds the parameter setting.
        return False

    RandomAvgBuyOnce = (AvgBuyOnce * ((100.0 - FloatPoint) / 100.0)) + (((FloatPoint * 2) / 100.0) * AvgBuyOnce * random.random())   # random number 0~1
    UsedMoney = min(account["Balance"], RandomAvgBuyOnce, TotalBuyNet - (InitAccount["Balance"] - account["Balance"]))

    BuyAmount = _N(UsedMoney / BuyPrice)   # Calculate the buying quantity
    if BuyAmount < MinStock:         # Determine whether the buying quantity is less than the minimum buying quantity limit on the parameter.
        return False 
    LastBuyPrice = BuyPrice          # Record the price of this order and assign it to LastBuyPrice
    exchange.Buy(BuyPrice, BuyAmount, "spend:¥", _N(UsedMoney), "Last transaction price", ticker["Last"]) # Place orders
    return True

def main():
    global LoopInterval, InitAccount    # Refer to LoopInterval, InitAccount global variables
    CancelPendingOrders()               # Cancel all pending orders when starting to run
    InitAccount = _C(exchange.GetAccount)   # Account assets at the beginning of the initial record
    Log(InitAccount)                        # Print initial account information
    if InitAccount["Balance"] < TotalBuyNet:    # If the initial assets are insufficient, an error will be thrown and the program will stop
        raise Exception("Insufficient account balance")
    LoopInterval = max(LoopInterval, 1)      # Set LoopInterval to at least 1
    while dispatch():                        # The main loop, the iceberg commission logic function dispatch is called continuously, and the loop stops when the dispatch function returns false.
        Sleep(LoopInterval * 1000)           # Pause each cycle to control the polling frequency.
    Log("委托全部完成", _C(exchange.GetAccount))   # When the loop execution jumps out, the current account asset information is printed.

آئس برگ کمیشن برائے پائیتھون - فروخت

حکمت عملی کا منطق خریدنے کے ساتھ ایک ہی ہے، صرف ایک معمولی فرق کے ساتھ.

import random

def CancelPendingOrders():
    while True:
        orders = _C(exchange.GetOrders)
        if len(orders) == 0:
            return
        
        for j in range(len(orders)):
            exchange.CancelOrder(orders[j]["Id"])
            if j < len(orders) - 1:
                Sleep(Interval)

LastSellPrice = 0
InitAccount = None

def dispatch():
    global LastSellPrice, InitAccount
    account = None
    ticker = _C(exchange.GetTicker)
    LogStatus(_D(), "ticker:", ticker)   
    if LastSellPrice > 0:
        if len(_C(exchange.GetOrders)) > 0:
            if ticker["Last"] < LastSellPrice and ((LastSellPrice - ticker["Last"]) / ticker["Last"]) > (2 * (EntrustDepth / 100)):
                Log("Too much deviation, the latest transaction price:", ticker["Last"], "Commission price", LastSellPrice)
                CancelPendingOrders()
            else :
                return True
        else :
            account = _C(exchange.GetAccount)
            Log("The buy order is completed, and the accumulated selling:", _N(InitAccount["Stocks"] - account["Stocks"]), "Average selling price:", _N((account["Balance"] - InitAccount["Balance"]) / (InitAccount["Stocks"] - account["Stocks"])))
            LastSellPrice = 0

    SellPrice = _N(ticker["Sell"] * (1 + EntrustDepth / 100))
    if SellPrice < MinSellPrice:
        return True

    if not account:
        account = _C(exchange.GetAccount)

    if (InitAccount["Stocks"] - account["Stocks"]) >= TotalSellStocks:
        return False 

    RandomAvgSellOnce = (AvgSellOnce * ((100.0 - FloatPoint) / 100.0)) + (((FloatPoint * 2) / 100.0) * AvgSellOnce * random.random())
    SellAmount = min(TotalSellStocks - (InitAccount["Stocks"] - account["Stocks"]), RandomAvgSellOnce)
    if SellAmount < MinStock:
        return False 

    LastSellPrice = SellPrice
    exchange.Sell(SellPrice, SellAmount, "Last transaction price", ticker["Last"])
    return True

def main():
    global InitAccount, LoopInterval
    CancelPendingOrders()
    InitAccount = _C(exchange.GetAccount)
    Log(InitAccount)
    if InitAccount["Stocks"] < TotalSellStocks:
        raise Exception("Insufficient account currency")
    LoopInterval = max(LoopInterval, 1)
    while dispatch():
        Sleep(LoopInterval)
    Log("All commissioned", _C(exchange.GetAccount))

حکمت عملی آپریشن

تبادلہ ٹیسٹ کا نمونہ بنانے کے لئے WexApp استعمال کریں:

خریدنا:

img

فروخت:

img

حکمت عملی کا منطق پیچیدہ نہیں ہے۔ جب حکمت عملی پر عملدرآمد کیا جاتا ہے تو ، یہ حکمت عملی کے پیرامیٹرز اور موجودہ مارکیٹ کی قیمت کی بنیاد پر متحرک طور پر آرڈرز لگائے گا اور منسوخ کردے گا۔ جب لین دین کی رقم / سکے کی تعداد پیرامیٹر سیٹنگ نمبر تک پہنچ جاتی ہے یا اس کے قریب ہوجاتی ہے تو ، حکمت عملی رک جاتی ہے۔ حکمت عملی کا کوڈ بہت آسان اور ابتدائیوں کے لئے موزوں ہے۔ دلچسپی رکھنے والے قارئین اسے تبدیل کرسکتے ہیں اور اپنی تجارتی طرز کے مطابق حکمت عملی تیار کرسکتے ہیں۔


متعلقہ

مزید