Jump to content

Vincent

Members
  • Content count

    41
  • Joined

  • Last visited

  • Days Won

    6

Posts posted by Vincent


  1. Hi Physicsman,

     

    Thanks. I am also aware of SimulateTrade api. I don't like it is because every time user changes the stack size, the client device need to make a request to the City SimulateTrade API in order to get the margin, which I think is unnecessary if we have all the values we needed to calculate it on client device. This is also much faster comparing to using SimulateTrade API.

     

    Now, I know there is no way for me to calculate the margin correctly on client device. Using SimulateTrade API is what I am going to fall back to.

     

    Thanks.

     

    Vincent


  2. Hi Physicsman,

     

    I am aware that ClientAccountMargin stream can provide the current margin requirements for the account.

     

    Yes, I am trying to compute the margin on the client side. I want to implement this because when an user is opening a position/trade, I want to show him the margin which require for this trade before he open it.

     

    If there is not way to know if an account is set to use Step Margin MF or Basic MF through API, I guess there is no way for me to calculate margin correctly on client side.

     

    Thanks.

     

    Vincent


  3. Hi,

     

    When clicked on market information icon, a market information data set is return to the browser.

     

    I am interested in "MarginFactor" and "Step Margin's MarginFactors" properties.

     

    I like to know when I should use "MarginFactor" ("MarginFactor": 160 as shown in the data at bottom) to calculate the margin.

     

    And when I should use "Step Margin's MarginFactors" which is depending on the trade quantity size? 

            ...

            "Bands": [

              {

                "LowerBound": 0,

                "MarginFactor": 70

              },

              {

                "LowerBound": 750,

                "MarginFactor": 150

              },

              ...

     

    Thanks.

     

     

     

    =============================================

    Data Set:

     

    {

      "MarketInformation": [

        {

          "MarketId": 400616150,

          "Name": "GBP/USD DFT",

          "ExchangeId": 56,

          "ExchangeName": "FX Dummy Exchange",

          "MarginFactor": 160,

          "MinMarginFactor": null,

          "MaxMarginFactor": null,

          "MarginFactorUnits": 27,

          "MinDistance": 1,

          "MinDistanceUnits": 27,

          "WebMinSize": 0.06560819,

          "MaxSize": 3280.4095,

          "MarketSizesCurrencyCode": "GBP",

          "MaxLongSize": 328.04095,

          "MaxShortSize": 328.04095,

          "Market24H": true,

          "PriceDecimalPlaces": 5,

          "DefaultQuoteLength": 30,

          "TradeOnWeb": true,

          "LimitUp": false,

          "LimitDown": false,

          "LongPositionOnly": false,

          "CloseOnly": false,

          "MarketEod": [],

          "PriceTolerance": 2,

          "ConvertPriceToPipsMultiplier": 10000,

          "MarketSettingsTypeId": 1,

          "MarketSettingsType": "Spread",

          "MobileShortName": "GBP/USD",

          "CentralClearingType": "No",

          "CentralClearingTypeDescription": "None",

          "MarketCurrencyId": 11,

          "PhoneMinSize": 0.5,

          "DailyFinancingAppliedAtUtc": "/Date(1430427600000)/",

          "NextMarketEodTimeUtc": "/Date(1430427600000)/",

          "TradingStartTimeUtc": null,

          "TradingEndTimeUtc": null,

          "MarketPricingTimes": [

            {

              "DayOfWeek": 1,

              "StartTimeUtc": {

                "UtcDateTime": "/Date(1430427600000)/",

                "OffsetMinutes": 600

              },

              "EndTimeUtc": null

            },

            {

              "DayOfWeek": 5,

              "StartTimeUtc": null,

              "EndTimeUtc": {

                "UtcDateTime": "/Date(1430511300000)/",

                "OffsetMinutes": -240

              }

            }

          ],

          "MarketBreakTimes": [],

          "MarketSpreads": [

            {

              "SpreadTimeUtc": "/Date(1430463600000)/",

              "Spread": 0.00015,

              "SpreadUnits": 27

            },

            {

              "SpreadTimeUtc": "/Date(1430501400000)/",

              "Spread": 0.0001,

              "SpreadUnits": 27

            }

          ],

          "GuaranteedOrderPremium": 4,

          "GuaranteedOrderPremiumUnits": 1,

          "GuaranteedOrderMinDistance": 50,

          "GuaranteedOrderMinDistanceUnits": 27,

          "PriceToleranceUnits": 0.0001,

          "MarketTimeZoneOffsetMinutes": -240,

          "QuantityConversionFactor": 1,

          "PointFactorDivisor": 100,

          "BetPer": 0.0001,

          "MarketUnderlyingTypeId": 4,

          "MarketUnderlyingType": "FX",

          "AllowGuaranteedOrders": true,

          "OrdersAwareMargining": false,

          "OrdersAwareMarginingMinimum": 50,

          "CommissionChargeMinimum": null,

          "CommissionRate": null,

          "CommissionRateUnits": null,

          "ExpiryUtc": "/Date(1640995200000)/",

          "FutureRolloverUTC": null,

          "AllowRollover": false,

          "ExpiryBasisId": 2,

          "ExpiryBasisText": "Closing price on last day of dealing",

          "StepMargin": {

            "EligibleForStepMargin": true,

            "StepMarginConfigured": true,

            "InheritedFromParentAccountOperator": true,

            "Bands": [

              {

                "LowerBound": 0,

                "MarginFactor": 70

              },

              {

                "LowerBound": 750,

                "MarginFactor": 150

              },

              {

                "LowerBound": 1400,

                "MarginFactor": 220

              },

              {

                "LowerBound": 2300,

                "MarginFactor": 300

              },

              {

                "LowerBound": 3000,

                "MarginFactor": 450

              }

            ]

          },

          "OptionTypeId": null,

          "OptionType": null,

          "StrikePrice": null,

          "MarketTypeId": 2,

          "MarketType": "Ordinary Market",

          "Weighting": 300,

          "FxFinancing": {

            "CaptureDateTime": "/Date(1430514000000)/",

            "LongPoints": 0.3,

            "ShortPoints": -0.52,

            "LongCharge": -0.2,

            "ShortCharge": -0.34,

            "Quantity": 1,

            "ChargeCurrencyId": 6,

            "DaysToRoll": 1

          },

          "UnderlyingRicCode": "43",

          "NewsUnderlyingOverrideType": "NamedItem",

          "NewsUnderlyingOverrideCode": "GBP/"

        }

      ]

    }

    post-3673-0-07378900-1430484478_thumb.png


  4. Hi,

     

    Please refer to the screenshots in the attachment.

     

    The result I got from my calculation (89.4715) is different from the result I got from the Margin Calculator (58.50).

     

    Here is my cacluation

    17894.3 (Buy price) * 0.005 (Margin Factor) * 1 (Quantity) = 89.4715

     

    Am I missing something here?

     

    Thanks.

     

    post-3673-0-53193700-1430473075_thumb.png

    post-3673-0-92847200-1430473081_thumb.png


  5. Hi Physicsman,

     

    Thanks.

     

    Please let me explain why I need this change.

     

    Let's start with a trade which has a stop order and a limit order.

    Here is example of what data sets will be push to the client by order stream when stop order's trigger price of the trade order is edited:

    ==============================================

    Data Set 1

    ==============================================

    521520651 (limit order ID)

    400616113

    400340375

    400482641

    6

     

    2

    false

    \/Date(1423483864000)\/

    0

    \/Date(1423483454000)\/

    2

    1

    2

    Limit

    Accepted

    1

    ==============================================

     

    ==============================================

    Data Set 2

    ==============================================

    521520580 (stop order ID)

    400616113

    400340375

    400482641

    6

     

    2

    false

    \/Date(1423483864000)\/

    0

    \/Date(1423483454000)\/

    2

    1

    2

    Stop

    Accepted

    1

    ==============================================

     

    As you can see, the order stream only push limit order ID and stop order ID to the client. There is no way to know that the limit order and stop order are with the same trade order.

     

    So when client received "Data Set 1", it need to get/query the limit order to  get its parent trade order. Update UI.

    When client received "Data Set 2", it need to do the similar thing again.

    One change, but two updates required. It just not very efficient.

     

    If order stream can return another dataset which contain trade order ID, I can just ignore "data set 1" and "data set 2". And get the trade order info (which contain the limit order and stop order info) and use the info to update the UI.

    One chagne and one update.

     

    Thanks.


  6. Hi Physyicsman,

     

    Order stream push data to client when there is change in order. The data will be push to the client when there change in a "trade order", an "order order", a "stop order" or a "limit order".

    Both "trade order" and "order order" can have a stop order and a limit order.

     

    "But when you edit a stop order or a limit order's trigger price of  an order. The order ID will be push back as well as stop order ID and limit order ID."

     

    What I mean here is that when you edit a stop order's trigger price of an "order order". Order stream will push back not just stop order ID (child order ID), but also "order order"s ID (parent order ID).

    It is the same when you edit a limit order's trigger price of an "order order". Order stream will push back not just limit order ID (child order ID), but also "order order"s ID (parent order ID).

     

    It is desirable since I don't need to query the child order ID to get the parent order ID. I wish this is happening to trade order as well.

     

    Please let me know if it is still not making sense.

     

    Thanks.


  7. Hi,

     

    This question is relate to order stream:

    http://docs.labs.cityindex.com/#Streaming%20Data/Orders.htm%3FTocPath%3DCIAPI%2520Reference|Streaming%2520Data|_____4

     

    When editing a stop order's trigger level/price of a trade order, the order stream will only push back the stop order ID. And it will not push back the trade order ID (the parent order of stop order).

     

    When editing a limit order's trigger level/price of a trade order, the same thing happen as well. Limit order ID is pushed back.

     

    But when you edit a stop order or a limit order's trigger price of  an order. The order ID will be push back as well as stop order ID and limit order ID.

     

    My 1st question is to find out if my observation (above statement) is correct.

     

    My 2nd question is possible to make the order stream to return trade order ID when only its stop order or limit order's trigger price have been changed.

     

    Thanks.


  8. Hi Physicsman,

     

    Sorry, I still don't understand it. I understand the calculation, but I don't know where some of key information is coming from.

     

    How do I know this : "bet per for shares is 1 cent (penny for GB stocks) movement"?

    I am looking at "Microsoft Corp CFD" market info page on City Index Advantage Web platform.

    It has minimum size, max long size, max short size...etc.

     

    And could we use "UK 100 CFD" as an example because it got a long open hour. I can try  do the calculation by hand and compare the result with the web platform.

     

    Thanks.


  9. Hi,

     

    In relate to this topic: http://faq.labs.cityindex.com/index.php?/topic/975-streaming-data-orders/

     

    In the attachment is my code (C#, VS2013) and screenshots.

     

    As shown in the screenshot, my code only recevie one order update after placing a trade with limit and stop on CI web platform.

     

    Thanks.

    post-3673-0-82090700-1422345105_thumb.png

    post-3673-0-87058000-1422345112_thumb.png


  10. Hi Physicsman,


     


    Thank you for your answer. But I am still stuck on this problem.


     


    Could you provide some information/method on how your developement team test this? I like to replicate it.


     


    I have also been monitoring the trafic of CI platform using my demo account:


    https://trade.loginandtrade.com/advantageweb/home.html?ts=1422256044884


    But I didn't get the similar result as shown in your screenshots when I am openning a new trade.


    There were no "bind_session.txt" was push back at all on CI Platform.


     


    Another thing I don't understand is why I am able to received two sets of data, but not all the data.


     


    ================================================================


    Here is my .NET code:


     


    ConnectionInfo


     


            private ConnectionInfo buildNewConnectionInfo(string username, string sessionToken)


            {


                var connInfo = new ConnectionInfo


                {


                    PushServerUrl = "https://push.cityindex.com",


                    Adapter = "STREAMINGALL",


                    User = username,


                    Password = sessionToken,


                    Constraints = { MaxBandwidth = 999999 },


                    Polling = false //,PollingIdleMillis = 250,PollingMillis = 250


                };


     


                return connInfo;


            }


     


    -------------------------------------------------------------------------------------------------


     


    Use ConnectionInfo to build the LsClient


     


            private LSClient createNewLsClient(ConnectionInfo connInfo, LsConnectionListener lsConnectionListener)


            {


                _lsClient = new LSClient();


     


                try


                {


                    _lsClient.OpenConnection(connInfo, lsConnectionListener);


                }


                //username or sessionToken in ConnectionInfo is incorrect.


                catch (PushUserException)


                {


                    var ciEx = new CiStreamConnLoginFailException(


                        string.Format("Unable to establish stream connection because username '{0}'or sessionToken '{1}' is incorrect",


                        connInfo.User,


                        connInfo.Password));


     


                    throw ciEx;


                }


     


                return _lsClient;


            }


     


     


    -------------------------------------------------------------------------------------------------


     


    Use LsClient to subscribe to order stream


     


    public class OrdersApi : BaseApi<OrderDTO>


        {


            private const string _schema = "OrderId MarketId ClientAccountId TradingAccountId CurrencyId CurrencyISO Direction AutoRollover LastChangedTime OpenPrice OriginalLastChangedDateTime OriginalQuantity PositionMethodId Quantity Type Status ReasonId";


     


            public OrdersApi(LSClient client) : base(client) { }


            


            public void Subscribe()


            {


                if (_isSubscribed)


                    Unsubscribe();


     


                var tableInfo = buildTableInfo();


     


                var tbListener = new LsTableListener();


                tbListener.UpdateReceivedHandler += onUpdateReceived;


     


                _tbKey = _lsClient.SubscribeTable(


                    tableInfo,


                    tbListener,


                    false


                    );


     


                _isSubscribed = true;


            }


     


            private static SimpleTableInfo buildTableInfo()


            {


                string group = "ORDERS";


     


                SimpleTableInfo tableInfo = new SimpleTableInfo(


                    group,


                    "MERGE",


                    _schema,


                    true


                    ) { DataAdapter = "ORDERS" };


     


                return tableInfo;


            }


        }


     


     


     


     


     


     


    -------------------------------------------------------------------------------------------------


    BaseApi


     


     


        public abstract class BaseApi<T>


        {


            public EventHandler<CiUpdateReceivedEventArgs<T>> UpdateReceivedHandler;


     


            protected LSClient _lsClient;


            protected SubscribedTableKey _tbKey;


     


            public SubscribedTableKey SubscribedTableKey


            {


                get { return _tbKey; }


            }


            protected SimpleTableInfo _tableInfo;


            protected bool _isSubscribed = false;


     


            protected BaseApi(LSClient client)


            {


                _lsClient = client;


            }


     


            public void Unsubscribe()


            {


                if (_tbKey != null)


                    _lsClient.UnsubscribeTable(_tbKey);


     


                _isSubscribed = false;


            }


     


            protected void onUpdateReceived(object sender, CiUpdateReceivedEventArgs<LsUpdate> e)


            {


                if (isUpdateNull(e.Update.UpdateInfo))


                    return;


     


                var update = e.Update.UpdateInfo;


                Debug.WriteLine("==============================================");


                for (int i = 1; i < update.NumFields + 1; i++)


                {


                    Debug.WriteLine(update.IsValueChanged(i) ? update.GetNewValue(i) : update.GetOldValue(i));


                }


                Debug.WriteLine("==============================================");


     


                var dto = Deserializer<T>.Deserialize(e.Update.UpdateInfo);


                var eventArgs = new CiUpdateReceivedEventArgs<T>(dto);


     


                UpdateReceivedHandler.SafeInvoke(this, eventArgs);


            }


     


     


            /// <summary>


            /// It seems some streams have a 'spin-up' process that can return an all null update


            /// until the data starts streaming. We were not catching this and null updates were


            /// sometimes throwing exceptions that were logged and then swallowed by LS. I think


            /// a better way is to determine if the update is emtpy (null) and simply not fire if so.


            ///


            /// Follows is a very simple check


            /// </summary>


            /// <param name="update"></param>


            /// <returns></returns>


            private static bool isUpdateNull(IUpdateInfo update)


            {


                for (int i = 1; i < update.NumFields + 1; i++)


                {


                    object value = update.IsValueChanged(i) ? update.GetNewValue(i) : update.GetOldValue(i);


                    if (value != null)


                    {


                        return false;


                    }


                }


                return true;


            }


        }


  11. Hi,

     

    Please refer to this DTO: ApiMarketInformationDTO

    http://docs.labs.cityindex.com/#Data%20Types/ApiMarketInformationDTO.htm

     

    What is BetPer? Is it pip movement?

     

    For example:

     

    UK 100
    The Price Stream shows that the price over a period has moved from 5678.5 to 5678.7 showing an increase of +0.2
    If a user is long (betting up) @ £1/point - what does the point movement here represent? Tenths (£1 every 0.1 price movement) or units (£1 every 1.0 price movement?

     

    If not, could you tell me where can I locate such information.

     

    Thanks.


  12. Hi,

     

    Regarding ClientAccountMargin stream:

    http://docs.labs.cityindex.com/#Streaming%20Data/ClientAccountMargin.htm%3FTocPath%3DCIAPI%2520Reference|Streaming%2520Data|_____1

     

    It will push back "ClientAccountMarginDTO" when there is an update.

    http://docs.labs.cityindex.com/#Data%20Types/ClientAccountMarginDTO.htm

     

    And "ClientAccountMarginDTO" have some properties I am not sure if they are duplicates or different data.

     

    1. "Margin" and "TotalMarginRequirement"

    -The data return by these two properties seem to be the same. If I want the information of the amount of cash held as deposit for all open positions, which one do I use?

     

    2. "TradeableFunds" and "TradingResource"

    -These two also seem to be the same.

     

    Thanks.


  13. Hi,

     

    For some reason, the data returned by this order stream is very inconsistent:

    http://docs.labs.cityindex.com/#Streaming%20Data/Orders.htm%3FTocPath%3DCIAPI%2520Reference|Streaming%2520Data|_____4

     

    Please let me explain what I mean:

    If I place a trade order with a stop order and a limit order like shown in picture in the attachment file, the orders stream will always push two sets of data to me. The two sets of data could be "new trade order" and "new stop order" info, OR "new stop order" and "new limit order" info.

     

    I like to know if this is normal and why didn't it push back three set of data : "new trade order", "new stop order" and "new limit order". Since it seem to me that three orders has been created.

     

     

    Raw data return by order stream:

    Case 1:

    "new trade order" and "new stop order"

    ==============================================

    519674241

    400616114

    400332911

    400473108

    6

     

    1

    false

    \/Date(1421412694000)\/

    17255.0

    \/Date(1421412694000)\/

    1

    1

    1

    Trade

    Open

    1

    ==============================================

    ==============================================

    519674242

    400616114

    400332911

    400473108

    6

     

    2

    false

    \/Date(1421412694000)\/

    0

    \/Date(1421412694000)\/

    1

    1

    1

    Limit

    Accepted

    1

    ==============================================

     

     

     

     

    Case 2:

    "new stop order" and "new limit order"

    ==============================================

    519674494

    400616114

    400332911

    400473108

    6

     

    2

    false

    \/Date(1421412871000)\/

    0

    \/Date(1421412871000)\/

    1

    1

    1

    Limit

    Accepted

    1

    ==============================================

     

    ==============================================

    519674495

    400616114

    400332911

    400473108

    6

     

    2

    false

    \/Date(1421412871000)\/

    0

    \/Date(1421412871000)\/

    1

    1

    1

    Stop

    Accepted

    1

    ==============================================

    post-3673-0-14738000-1421413161_thumb.png


  14. Hi,

     

    In this page:

    http://docs.labs.cityindex.com/#API%20Intro.htm%3FTocPath%3DGetting%2520Started|_____1

     

    It mentions that "...This session token is guaranteed to be valid for at least 20 minutes." in "Authentication" topic.

     

    I know how to detect session expiry during web service call (HTTP Services).

     

    But I am not sure what happen and how do to handle it when session expired during price streaming (Streaming Data).

     

    Thanks.


  15. Hi,

     

    I got a response with "OrderActionTypeId" = 4 which is not described in "(Order) Type Codes" section: http://docs.labs.cityindex.com/#APICodesList.htm

     

    How do you interpret it?

     

    Thanks.

     

    This is a response I received when I partially close an open position:

    {
      "Status": 1,
      "StatusReason": 1,
      "OrderId": 516622020,
      "Orders": [
        {
          "OrderId": 516622020,
          "StatusReason": 1,
          "Status": 9,
          "OrderTypeId": 1,
          "Price": 17922.5,
          "Quantity": 0,
          "TriggerPrice": 0,
          "CommissionCharge": 0,
          "IfDone": [],
          "GuaranteedPremium": 0,
          "OCO": null
        }
      ],
      "Quote": null,
      "Actions": [
        {
          "ActionedOrderId": 516621958,
          "ActioningOrderId": 516622020,
          "Quantity": 1,
          "ProfitAndLoss": -3,
          "ProfitAndLossCurrency": "GBP",
          "OrderActionTypeId": 3
        },
        {
          "ActionedOrderId": 516621960,
          "ActioningOrderId": 516622020,
          "Quantity": 1,
          "ProfitAndLoss": 0,
          "ProfitAndLossCurrency": null,
          "OrderActionTypeId": 4
        },
        {
          "ActionedOrderId": 516621959,
          "ActioningOrderId": 516622020,
          "Quantity": 1,
          "ProfitAndLoss": 0,
          "ProfitAndLossCurrency": null,
          "OrderActionTypeId": 4
        }
      ],
      "ErrorMessage": null
    }

×