Beispiel #1
0
        public OkexPositionBriefInfo getHoldPosition(OkexFutureInstrumentType instrument, OkexFutureContractType contract,
                                                     OkexFutureTradeDirectionType direction, uint leverRate)
        {
            OkexPositionBriefInfo   briefInfo = null;
            List <OkexPositionInfo> info;
            bool hold = getFuturePosition(instrument, contract, out info);

            if (hold)
            {
                foreach (var pi in info)
                {
                    OkexFutureContractType ct = OkexDefValueConvert.parseContractType(pi.contract_type);
                    if (ct == contract && leverRate == pi.lever_rate)
                    {
                        OkexPositionBriefInfo bi = new OkexPositionBriefInfo(pi, instrument, contract, direction);
                        if (bi.amount > 0)
                        {
                            briefInfo = bi;
                            break;
                        }
                    }
                }
            }

            return(briefInfo);
        }
Beispiel #2
0
        // extension for position holding query
        public long getHoldPositionAmount(OkexFutureInstrumentType instrument, OkexFutureContractType contract,
                                          OkexFutureTradeDirectionType direction)
        {
            long positionAmount = 0;
            List <OkexPositionInfo> info;
            bool hold = getFuturePosition(instrument, contract, out info);

            if (hold)
            {
                foreach (var pi in info)
                {
                    OkexFutureContractType ct = OkexDefValueConvert.parseContractType(pi.contract_type);
                    if (ct == contract)
                    {
                        OkexPositionBriefInfo bi = new OkexPositionBriefInfo(pi, instrument, contract, direction);
                        if (bi.amount > 0)
                        {
                            positionAmount += bi.amount;
                            break;
                        }
                    }
                }
            }

            return(positionAmount);
        }
Beispiel #3
0
        public OkexPositionBriefInfo(OkexPositionInfo info, OkexFutureInstrumentType inst,
                                     OkexFutureContractType ct, OkexFutureTradeDirectionType dir)
        {
            contractID   = info.contract_id;
            instrument   = inst;
            contractType = ct;
            direction    = dir;

            leverRate = info.lever_rate;

            if (dir == OkexFutureTradeDirectionType.FTD_Buy)
            {
                amount    = info.buy_amount;
                available = info.buy_available;
                avgPrice  = info.buy_price_avg;
                costPrice = info.buy_price_cost;
                bond      = info.buy_bond;
                flatPrice = info.buy_flatprice;
            }
            else
            {
                amount    = info.sell_amount;
                available = info.sell_available;
                avgPrice  = info.sell_price_avg;
                costPrice = info.sell_price_cost;
                bond      = info.sell_bond;
                flatPrice = info.sell_flatprice;
            }
        }
Beispiel #4
0
 public OkexTransferPositionByBasis(OkexFutureInstrumentType inst, OkexFutureContractType sc, OkexFutureContractType fc,
                                    OkexBasisCalcType type, OkexFutureTradeDirectionType tradeDir)
 {
     m_instrument      = inst;
     m_basisCalcType   = type;
     m_spotContract    = sc;
     m_forwardContract = fc;
     m_tradeDirection  = tradeDir;
 }
Beispiel #5
0
 protected bool isTradeTypeMatchDirection(OkexContractTradeType tradeType, OkexFutureTradeDirectionType direction)
 {
     if (direction == OkexFutureTradeDirectionType.FTD_Buy)
     {
         return(tradeType == OkexContractTradeType.TT_CloseBuy || tradeType == OkexContractTradeType.TT_OpenBuy);
     }
     else
     {
         return(tradeType == OkexContractTradeType.TT_CloseSell || tradeType == OkexContractTradeType.TT_OpenSell);
     }
 }
Beispiel #6
0
        public OkexStrategy generateStrategy(string type, string info)
        {
            OkexStrategy s = null;

            if (type == "TPByBasis")
            {
                JObject jo                       = (JObject)JsonConvert.DeserializeObject(info);
                string  strInst                  = (string)jo["Instrument"];
                OkexFutureInstrumentType fi      = strInstrumentMap[strInst];
                string strSC                     = (string)jo["SpotContract"];
                OkexFutureContractType sc        = strContractMap[strSC];
                string strFC                     = (string)jo["ForwardContract"];
                OkexFutureContractType fc        = strContractMap[strFC];
                string strDir                    = (string)jo["Direction"];
                OkexFutureTradeDirectionType dir = OkexFutureTradeDirectionType.FTD_Sell;
                if (strDir.Equals("buy", StringComparison.OrdinalIgnoreCase))
                {
                    dir = OkexFutureTradeDirectionType.FTD_Buy;
                }
                else if (strDir.Equals("sell", StringComparison.OrdinalIgnoreCase))
                {
                    dir = OkexFutureTradeDirectionType.FTD_Sell;
                }
                OkexBasisCalcType bc      = OkexBasisCalcType.BC_Ratio;
                string            strType = (string)jo["Type"];
                if (strType.Equals("ratio", StringComparison.OrdinalIgnoreCase))
                {
                    bc = OkexBasisCalcType.BC_Ratio;
                }
                else if (strType.Equals("diff", StringComparison.OrdinalIgnoreCase))
                {
                    bc = OkexBasisCalcType.BC_Diff;
                }

                s = new OkexTransferPositionByBasis(fi, sc, fc, bc, dir);

                //double boardLot = (double)jo["BoardLot"];
                double basis = (double)jo["Basis"];
                double safe  = (double)jo["Safe"];
                double limit = (double)jo["Limit"];
                uint   count = (uint)jo["Count"];
                double param = (double)jo["Param"];
                ((OkexTransferPositionByBasis)s).init(basis, safe, limit, count, param);
            }

            return(s);
        }
Beispiel #7
0
        protected long getOrderedPositionByContract(OkexFutureInstrumentType instrument, OkexFutureContractType contract, OkexFutureTradeDirectionType direction, bool inOpenOrder)
        {
            List <OkexFutureOrderBriefInfo> info;
            long orderedPosition = 0;

            //

            return(orderedPosition);
        }
Beispiel #8
0
        protected long getAvailablePositionByContract(OkexFutureInstrumentType instrument, OkexFutureContractType contract, OkexFutureTradeDirectionType direction)
        {
            OkexPositionBriefInfo bi10 = OkexFutureTrader.Instance.getHoldPosition(instrument, contract, direction, 10);
            OkexPositionBriefInfo bi20 = OkexFutureTrader.Instance.getHoldPosition(instrument, contract, direction, 20);

            long availablePosition = 0;

            if (bi10 != null)
            {
                availablePosition += bi10.available;
            }
            if (bi20 != null)
            {
                availablePosition += bi20.available;
            }

            return(availablePosition);
        }
Beispiel #9
0
 protected long getPositionByContract(OkexFutureInstrumentType instrument, OkexFutureContractType contract, OkexFutureTradeDirectionType direction)
 {
     return(OkexFutureTrader.Instance.getHoldPositionAmount(instrument, contract, direction));
 }