مارکیٹ سینٹر کلائنٹ

مصنف:fmzero، تاریخ: 2020-01-19 23:29:25
ٹیگز:

بزنس سینٹر کلائنٹ

یہاںکلائنٹتعاونکاروباری مرکزاستعمال

مارکیٹنگ سینٹرز کیوں؟

مارکیٹ تک رسائی کے لئے REST اور Websocket موجود ہیں ، اور جب ویب ساکٹ کو کسی بھی ناقابل تسخیر عوامل کی وجہ سے ان کے کنکشن کو زبردستی منقطع کردیا جاتا ہے تو ، اس کی حکمت عملی میں غلطیوں کو برداشت کرنے کے لئے مختلف میکانزم کی ضرورت ہوتی ہے۔ REST اکثر سب سے زیادہ مستحکم طریقہ ہوتا ہے۔ جب آپ کے پاس ایک ہی پلیٹ فارم پر چلنے والی متعدد پالیسیاں ہیں ، جیسے OKEx ، اور یہ ایک ہی سرور پر چلتی ہیں ، تو REST API تک رسائی کی تعدد محدود ہوتی ہے (مزید تفصیلات کے لئے پلیٹ فارم API دستاویزات دیکھیں) ، اور اس کو محدود کرنے کے مختلف طریقے ہیں ، جیسے IP کی حد ، اکاؤنٹ کی حد ، یا دونوں کا مجموعہ۔ REST درخواستوں کی تعداد کو کم کرنے کے لئے مارکیٹ سینٹر کا استعمال کریں

传统方式

行情中心

کام کا مرکز تعینات

  1. ماخذ کوڈمرتب کریں اور تعینات کریں
  2. دوہری تعیناتی
  3. اگر آپ کو مدد کی ضرورت ہو تو براہ کرم رابطہ کریں: wx:btstarinfo, Q:6510575

براہ مہربانی نوٹ کریں

  • مارکیٹنگ سینٹر صرف مارکیٹنگ ڈیٹا انٹرفیس فراہم کرتا ہے، اور کوئی بھی انٹرفیس نہیں ہے
  • کام کا مرکز صرف لینکس، یونیکس پر چلتا ہے

API

  • GetSupportList حاصل کریں
  • سبسکرائب کریںSpotTicker
  • سبسکرائب کریںSpotDepth
  • سبسکرائب کریںSpotTrade
  • گیٹ اسپاٹ ٹکر
  • GetSpotDepth حاصل کریں
  • GetSpotTrade
  • سبسکرائب کریںFutureTicker
  • SubscribeFutureDepth (مستقبل کی گہرائی)
  • سبسکرائب کریںFutureTrade
  • حاصلFutureTicker
  • حاصل کریںFutureDepth
  • گیٹ فیوچر ٹریڈ

// a client for market center, https://github.com/goex-top/market_center
// api list 
// * GetSupportList
// * SubscribeSpotTicker
// * SubscribeSpotDepth
// * ~~SubscribeSpotTrade~~
// * GetSpotTicker
// * GetSpotDepth
// * ~~GetSpotTrade~~
// * SubscribeFutureTicker
// * SubscribeFutureDepth
// * ~~SubscribeFutureTrade~~
// * GetFutureTicker
// * GetFutureDepth
// * ~~GetFutureTrade~~

// params wit web
// var udspath = /tmp/goex.market.center //ref to https://github.com/goex-top/market_center/blob/1e1bb15c69a1da6fddbba3d506920e91f9ec7842/const.go#L35

// local variable
// var client = null

var ReqType = {
    ReqType_GetSupportList: 1,
    ReqType_SubscribeSpotDepth: 2,
    ReqType_SubscribeSpotTicker: 3,
    ReqType_SubscribeFutureDepth: 4,
    ReqType_SubscribeFutureTicker: 5,
    ReqType_GetSpotDepth: 6,
    ReqType_GetSpotTicker: 7,
    ReqType_GetFutureDepth: 8,
    ReqType_GetFutureTicker: 9,
}

//---------------------------------------
function newUDSClient() {
    var client = Dial('unix://'+udspath)
    if (null === client) {
        throw 'new usd client fail'
    }
    return client
}

function udsRequest(client, req) {
    try {
        client.write(JSON.stringify(req))
        var rsp = client.read(20)
        if (rsp === null) {
            return null
        }
    
        var obj = JSON.parse(rsp)
        if(obj.status !== 0) {
            return null
        }
        return obj.data
    }
    catch(e) {
        return null
    }
    
}

function GetSupportList(client) {
    var req = {type:ReqType.ReqType_GetSupportList}
    var rsp = udsRequest(client, req)
    if (rsp === null) {
        return null
    }
    return rsp
}

function GetSpotDepth(client, exchangeName, pair) {
    var req = {type:ReqType.ReqType_GetSpotDepth, exchange_name: exchangeName, currency_pair: pair}
    var rsp = udsRequest(client, req)
    if(rsp === null) {
        return null
    }
    return {Asks:rsp.AskList, Bids:rsp.BidList, Time:rsp.UTime, Info:rsp.rsp}
}

function GetSpotTicker(client, exchangeName, pair) {
    var req = {type:ReqType.ReqType_GetSpotTicker, exchange_name: exchangeName, currency_pair: pair}
    var rsp = udsRequest(client, req)
    if(rsp === null) {
        return null
    }
    return {
        Last:parseFloat(rsp.last), 
        Buy:parseFloat(rsp.buy), 
        Sell:parseFloat(rsp.sell), 
        Volume:parseFloat(rsp.vol), 
        Time:parseFloat(rsp.date), 
        High:parseFloat(rsp.high), 
        Low:parseFloat(rsp.low), 
        Info:rsp
    }
}

function SubscribeSpotDepth(client, exchangeName, pair, period) {
    var req = {type:ReqType.ReqType_SubscribeSpotDepth, exchange_name: exchangeName, currency_pair: pair, period: period}
    var rsp = udsRequest(client, req)
    return rsp
}

function SubscribeSpotTicker(client, exchangeName, pair, period) {
    var req = {type:ReqType.ReqType_SubscribeSpotTicker, exchange_name: exchangeName, currency_pair: pair, period: period}
    var rsp = udsRequest(client, req)
    return rsp
}

function GetFutureDepth(client, exchangeName, contractType, pair) {
    var req = {type:ReqType.ReqType_GetFutureDepth, exchange_name: exchangeName, contract_type: contractType, currency_pair: pair}
    var rsp = udsRequest(client, req)
    if(rsp === null) {
        return null
    }
    return {Asks:rsp.AskList, Bids:rsp.BidList, Time:rsp.UTime, Info:rsp.rsp}
}

function GetFutureTicker(client, exchangeName, contractType, pair) {
    var req = {type:ReqType.ReqType_GetFutureTicker, exchange_name: exchangeName, contract_type: contractType, currency_pair: pair}
    var rsp = udsRequest(client, req)
    if(rsp === null) {
        return null
    }
    return {
        Last:parseFloat(rsp.last), 
        Buy:parseFloat(rsp.buy), 
        Sell:parseFloat(rsp.sell), 
        Volume:parseFloat(rsp.vol), 
        Time:parseFloat(rsp.date), 
        High:parseFloat(rsp.high), 
        Low:parseFloat(rsp.low), 
        Info:rsp
    }
}

function SubscribeFutureDepth(client, exchangeName, contractType, pair, period) {
    var req = {type:ReqType.ReqType_SubscribeFutureDepth, exchange_name: exchangeName, contract_type: contractType, currency_pair: pair, period: period}
    var rsp = udsRequest(client, req)
    return rsp
}

function SubscribeFutureTicker(client, exchangeName, contractType, pair, period) {
    var req = {type:ReqType.ReqType_SubscribeFutureTicker, exchange_name: exchangeName, contract_type: contractType, currency_pair: pair, period: period}
    var rsp = udsRequest(client, req)
    return rsp
}

var MarketCenterClient = (function() {
    function MarketCenterClient() {
        if (typeof udspath === 'undefined' || udspath === '') {
            throw 'udspath not defined'
        }
        this.client = newUDSClient()
        this.list = GetSupportList(this.client)
        Log("this.list:" + this.list)
    }

    MarketCenterClient.prototype.GetSpotTicker = function(exchangeName, pair) {
        if (typeof exchangeName === 'undefined' || exchangeName === '') {
            throw 'GetSpotTicker exchangeName not defined'
        }
        if (typeof pair === 'undefined' || pair === '') {
            throw 'GetSpotTicker pair not defined'
        }
        return GetSpotTicker(this.client, exchangeName, pair)
    }

    MarketCenterClient.prototype.GetSpotDepth = function(exchangeName, pair) {
        if (typeof exchangeName === 'undefined' || exchangeName === '') {
            throw 'GetSpotDepth exchangeName not defined'
        }
        if (typeof pair === 'undefined' || pair === '') {
            throw 'GetSpotDepth pair not defined'
        }
    return GetSpotDepth(this.client, exchangeName, pair)
    }

    MarketCenterClient.prototype.SubscribeSpotDepth = function(exchangeName, pair, period) {
        if(typeof(period) === 'undefined') {
            period = 200
        }
        if (typeof exchangeName === 'undefined' || exchangeName === '') {
            throw 'SubscribeSpotDepth exchangeName not defined'
        }
        if (typeof pair === 'undefined' || pair === '') {
            throw 'SubscribeSpotDepth pair not defined'
        }
        var found = false
        _.each(this.list, function(item) {
            if (item === exchangeName) {
                found = true
                return false
            }
        })

        if(!found) {
            throw 'exchange ('+ exchangeName +') not support, please check it again, https://github.com/goex-top/market_center#support-exchanges'
        }
        return SubscribeSpotDepth(this.client, exchangeName, pair, period)
    }

    MarketCenterClient.prototype.SubscribeSpotTicker = function(exchangeName, pair, period) {
        if(typeof(period) === 'undefined') {
            period = 200
        }
        if (typeof exchangeName === 'undefined' || exchangeName === '') {
            throw 'SubscribeSpotTicker exchangeName not defined'
        }
        if (typeof pair === 'undefined' || pair === '') {
            throw 'SubscribeSpotTicker pair not defined'
        }
      var found = false
        _.each(this.list, function(item) {
            if (item === exchangeName) {
                found = true
                return false
            }
        })

        if(!found) {
            throw 'exchange ('+ exchangeName +') not support, please check it again, https://github.com/goex-top/market_center#support-exchanges'
        }
        return SubscribeSpotTicker(this.client, exchangeName, pair, period)
    }


    MarketCenterClient.prototype.GetFutureTicker = function(exchangeName, contractType, pair) {
        if (typeof exchangeName === 'undefined' || exchangeName === '') {
            throw 'GetFutureTicker exchangeName not defined'
        }
        if (typeof pair === 'undefined' || pair === '') {
            throw 'GetFutureTicker pair not defined'
        }
     return GetFutureTicker(this.client, exchangeName, contractType, pair)
    }

    MarketCenterClient.prototype.GetFutureDepth = function(exchangeName, contractType, pair) {
        if (typeof exchangeName === 'undefined' || exchangeName === '') {
            throw 'GetFutureDepth exchangeName not defined'
        }
        if (typeof pair === 'undefined' || pair === '') {
            throw 'GetFutureDepth pair not defined'
        }
     return GetFutureDepth(this.client, exchangeName, contractType, pair)
    }

    MarketCenterClient.prototype.SubscribeFutureDepth = function(exchangeName, contractType, pair, period) {
        if(typeof(period) === 'undefined') {
            period = 200
        }
        if (typeof exchangeName === 'undefined' || exchangeName === '') {
            throw 'SubscribeFutureDepth exchangeName not defined'
        }
        if (typeof pair === 'undefined' || pair === '') {
            throw 'SubscribeFutureDepth pair not defined'
        }
     var found = false
        _.each(this.list, function(item) {
            if (item === exchangeName) {
                found = true
                return false
            }
        })

        if(!found) {
            throw 'exchange ('+ exchangeName +') not support, please check it again, https://github.com/goex-top/market_center#support-exchanges'
        }
        return SubscribeFutureDepth(this.client, exchangeName, contractType, pair, period)
    }

    MarketCenterClient.prototype.SubscribeFutureTicker = function(exchangeName, contractType, pair, period) {
        if(typeof(period) === 'undefined') {
            period = 200
        }
        if (typeof exchangeName === 'undefined' || exchangeName === '') {
            throw 'SubscribeFutureTicker exchangeName not defined'
        }
        if (typeof pair === 'undefined' || pair === '') {
            throw 'SubscribeFutureTicker pair not defined'
        }
     var found = false
        _.each(this.list, function(item) {
            if (item === exchangeName) {
                found = true
                return false
            }
        })

        if(!found) {
            throw 'exchange ('+ exchangeName +') not support, please check it again, https://github.com/goex-top/market_center#support-exchanges'
        }
        return SubscribeFutureTicker(this.client, exchangeName, contractType, pair, period)
    }

    MarketCenterClient.prototype.GetSupportList = function() {
        return GetSupportList(this.client)
    }
    return MarketCenterClient
})()

$.NewMarketCenterClient = function() {
    return new MarketCenterClient()
}

function main() {
    mcc = $.NewMarketCenterClient()
    Log('support list'+mcc.GetSupportList())
    mcc.SubscribeSpotDepth('binance.com', 'BTC_USDT', 200)
    Sleep(1000)
    Log(mcc.GetSpotDepth('binance.com', 'BTC_USDT'))
    mcc.SubscribeSpotTicker('binance.com', 'BTC_USDT', 200)
    Sleep(1000)
    Log(mcc.GetSpotTicker('binance.com', 'BTC_USDT'))
}
  

مزید

17880207677کیسے؟

17880207677یہ کیسے کام کرتا ہے؟

آئسکریم ڈولکیا آپ کو لگتا ہے کہ آپ کو یہ کام کرنا چاہئے؟

fmzeroبراہ کرم چیک کریں https://www.fmz.com/strategy/183009 ٹیسٹ کے نتائج یا اپنے آپ کو اندازہ لگائیں

fmzero https://www.fmz.com/strategy/183009

fmzeroکلائنٹ سے سینٹر تک تاخیر کو بنیادی طور پر نظر انداز کیا جا سکتا ہے۔ اگر آپ ڈیٹا چاہتے ہیں تو میں آپ کو ایک سیٹ ٹیسٹ کر سکتا ہوں۔