Topics
30 Aug 2017, 11:07
 0
 3234
 3
28 Apr 2017, 14:00
 2161
 2
31 Mar 2017, 09:27
 2696
 3
30 Mar 2017, 11:50
 3433
 7
29 Mar 2017, 16:02
 2674
 7
29 Mar 2017, 10:48
 2115
 3
12 Mar 2017, 13:53
 2243
 2
01 Mar 2017, 22:40
 1789
 4
22 Feb 2017, 21:02
 2125
 1
22 Feb 2017, 19:48
 2525
 5
08 Feb 2017, 13:58
 6020
 14
03 Feb 2017, 10:03
 0
 2092
 1
Replies

mindbreaker
14 Feb 2017, 17:57

RE:

Spotware said:

myfxbook.com and any other application that uses Connect API can see your account info only after you explicitely give it authorization to access your personal details. In the same way your application will be able to see a user's details only after that user has authorized your apprication to do so. 

Ok, I know how i can get  :)

But what to do with this redirected code=7268724368462384628fhr3r87d2dtr28drt32rt ?

When user allow me get his positions?


@mindbreaker

mindbreaker
14 Feb 2017, 17:41

I can't see positions from other cTID ? in my application?

Then how get acces to other account (as myfxbook.com gets my account info and shows charts) ?


@mindbreaker

mindbreaker
14 Feb 2017, 17:20

And now how add new client accounts cTID to my aplication (playground)?


@mindbreaker

mindbreaker
14 Feb 2017, 16:33

And this link shows

https://api.spotware.com/apps/auth?client_id=203_2hosJUozrOVxXNWyvAh8ftmp6Ug3vjmTP1SPBg3ytinkoiF4Te&redirect_uri=http://fxstar.eu/forex/&scope=accounts

Shows me:

403 Forbidden


nginx/1.6.3


@mindbreaker

mindbreaker
14 Feb 2017, 16:32 ( Updated at: 21 Dec 2023, 09:20 )

RE:

Spotware said:

It seems you were using an outdated version of URLs. Please find the URLs you need to use here

https://connect.spotware.com/docs/api-reference/accounts-api

Let us know if you have found those links somewhere in the documentation so we can update.

Regarding the authentication, yes as soon as the client authenticates, you will get his token on your redirection link using the get method.

When i try acces to:

https://sandbox-connect.spotware.com/apps/auth?client_id=203_2hosJUozrOVxXNWyvAh8ftmp6Ug3vjmTP1SPBg3ytinkoiF4Te&redirect_uri=http://fxstar.eu/forex/&scope=accounts

I cant auth from my cTID Error: incorrect password

but if i trying from another (after login i got this):

 


@mindbreaker

mindbreaker
14 Feb 2017, 16:13

RE:

Spotware said:

Can you please try the following link and let us know if it works?

https://api.spotware.com/connect/profile?oauth_token=EpnUPzeilFN_jvS-5-7uY9O6bpymsMnaiLJKqYBMgNo

If you want to use at active account then you should change the link to something like the following (note that you need to change the account_id and token parameters.

https://api.spotware.com/connect/tradingaccounts/account_id/positions?oauth_token=token

oauth_token is the parameter where you will set the token that will be returned to you after the client authenticates. Please the documentation here.

You don't need to allow your client to add accounts to your application. You can access his accounts after he authentices with his cTID and a valid token is returned to you.

Yes, this link works.

If client authenticate with cTID,  I will get on my redirection link his oauth_token (POST or GET method) or? 

 


@mindbreaker

mindbreaker
14 Feb 2017, 15:40 ( Updated at: 21 Dec 2023, 09:20 )

And from VPS browser with new token with full access:

 

 

And how allow Client to add account  to my Application

( I want get data from my clients cTrader accounts ?)

 


@mindbreaker

mindbreaker
14 Feb 2017, 15:23 ( Updated at: 21 Dec 2023, 09:20 )

RE:

mindbreaker said:

Hi, its my browser:

 

3) Below an example of how to get positions

https://sandbox-api.spotware.com/connect/tradingaccounts/89214/positions?oauth_token=test002_access_token

 

But i dont want use sandbox but active account ?

What is oauth_token and how can i get my oauth_token?

 


@mindbreaker

mindbreaker
14 Feb 2017, 15:23 ( Updated at: 21 Dec 2023, 09:20 )

Hi, its my browser:

3) Below an example of how to get positions

https://sandbox-api.spotware.com/connect/tradingaccounts/89214/positions?oauth_token=test002_access_token

 

But i dont want use sandbox but active account ?

What is oauth_token and how can i get my oauth_token?

 


@mindbreaker

mindbreaker
14 Feb 2017, 12:47 ( Updated at: 21 Dec 2023, 09:20 )

and next Wooops !!!!

What is wrong with us?


@mindbreaker

mindbreaker
14 Feb 2017, 12:41 ( Updated at: 21 Dec 2023, 09:20 )

Hi Spotware,

When i create connect aplication

and want redirect to urls:

https://api.spotware.com/webserv/connect/api/profile?access_token=EpnUPzeilFN_jvS-5-7uY9O6bpymsMnaiLJKqYBMgNo

https://api.spotware.com/webserv/connect/api/tradingaccounts?access_token=EpnUPzeilFN_jvS-5-7uY9O6bpymsMnaiLJKqYBMgNo

And how add new user (cTID) when i trying with playground ... next error something went worng ...

AND HOW GET OPEN AND CLOSED POSITIONS FROM ACCOUNTS WITH ACCESS_TOKEN FROM URL ????

 

 


@mindbreaker

mindbreaker
13 Feb 2017, 11:58

Hi,

It's too high thresholds for me (MVC and ASP Net) :).

Computers were invented in order to facilitate human life and not hindering :).

I needs a simpler solution.

I do not want to wander in a clumsy documentation of c connect again.

But thanks for the help.

 


@mindbreaker

mindbreaker
13 Feb 2017, 11:44

RE:

Spotware said:

Hi mindbreaker,

1) In order to close a position, you need to send a NewOrderSingle request with the reverse direction and the PostionID as a paramater. See below

var message = _messageConstructor.NewOrderSingleMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber, "1408471", 1,2, DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss"), 1000,1, "1",0,0,"", "438169");
          

2) This is not supported by FIX API. You will need to develop this logic yourself.

3) It is not possible now and we don't think that this is going to be added as it defeats the purpose of FIX, which is to reduce the necessary information transmitted to minimum for performance reasons.

If points 2 and 3 are important for you you might consider using Trading API instead of FIX

Hi Spotware,

Thank you for your answer.

Hmm. I will login and logout after send one message if 3) is not possible.

Thanks again and bye.


@mindbreaker

mindbreaker
11 Feb 2017, 18:06

FIX cTrader

Hi and thanks works fine.

1) How close positions?

2) How add Stop loss and Take profit to opened positions ( or modify stop loss and take profit )

3) Is it possible create FIX without login, logout and heartbeat messages ( Login and Password send with single message, then send and receive data is much easier and users don't need to worry about session, heartbeats and connections [something like rest api in ajax] ) ?

 

private string SendMessage(string message, NetworkStream stream)
{
    var byteArray = Encoding.ASCII.GetBytes(message);
    stream.Write(byteArray, 0, byteArray.Length);
    //set buffer
    var buffer = new byte[4096];
    int i = 0;
    while (!stream.DataAvailable && i < 10)
    {
        Thread.Sleep(100);
        i++;
    }
    if (stream.DataAvailable)
        // set buffer
        stream.Read(buffer, 0, 4096);
    _messageSequenceNumber++;
    var returnMessage = Encoding.ASCII.GetString(buffer);
    return returnMessage;
}


// Add multiline to message input field !!!!

Bye


@mindbreaker

mindbreaker
11 Feb 2017, 10:56

        public cAlgo.API.Robot robot { get; set; }

@mindbreaker

mindbreaker
10 Feb 2017, 23:21

And here your first example with cAlgo Api dll (you need include calgo api dll to your ddl as reference)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// cAlgo.Api References
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.API.Requests;

namespace Boo
{
    public static class Class1
    {       
        public static double Price(Symbol my)
        {
            return my.Ask - my.Bid;
        }

        public static  double PipSize(Symbol my)
        {
            return  my.PipSize;
        }
    }

}

And in cbot:

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using Boo;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DLL : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Add Symbol
            Print(Boo.Class1.Price(Symbol));
        }
    }
}

And works fine. :)


@mindbreaker

mindbreaker
10 Feb 2017, 23:04

cAlgo create dll file

It's simple   :D

DLL class in visual studio (Boo.dll):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// cAlgo.Api References
// using cAlgo.API.Collections;
// using cAlgo.API.Indicators;
// using cAlgo.API.Internals;
// using cAlgo.API.Requests;

namespace Boo
{
    public static class Class1
    {      
        public static double Price(double p1 = 100, double p2  = 200)
        {
            return p1 - p2;
        }

        public static  double Pips(double Price = 0)
        {
            return  Price;
        }
    }

}

And code in cBot (cAlgo):

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

// My dll name
using Boo;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DLL : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
            Print(Boo.Class1.Price(666, 333));
        }
    }
}

It work in my cAlgo :)

Bye.


@mindbreaker

mindbreaker
10 Feb 2017, 22:11

Hi,

look at this /api/guides/trading_api

use functions

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
 
namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
 

        protected override void OnTick()
        {
            SayHello("JIMBO");
            if(SayHello("JIN") == "Baraki"){
               Print("Booooooo");
            }
        }
        

        /// !!!!!!!!!!!!!!!!!!!!!!!!!!!! YOUR CODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
        public string SayHello(string Name = "AlojzyBombel")
        {
            // Print to log
            Print("HELLO " + Name);

            // return value, string ...
            return "Baraki";
         }

    }
}

 

Or try decompile DLL for example with https://www.jetbrains.com/decompiler/

and see how they do it ;)

It C# search in google how to create dll library in visual studio on youtube and ....

Bye.

 


@mindbreaker

mindbreaker
08 Feb 2017, 17:13

Fix api socket
using FIX_API_Library;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FIX_API_Sample
{
    public partial class frmFIXAPISample : Form
    {
    
        private int _pricePort = 5201;
        private int _tradePort = 5202;

        private string _host = "h20.p.ctrader.com";
        private string _username = "1234567";
        private string _password = "0000000";
        private string _senderCompID = "fxpro.1234567";
        private string _senderSubID = "TRADE";

        private string _targetCompID = "cSERVER";

        private int _messageSequenceNumber = 1;
        private int _testRequestID = 1;
        TcpClient _priceClient;
        NetworkStream _priceStream;
        TcpClient _tradeClient;
        NetworkStream _tradeStream;
        MessageConstructor _messageConstructor;

        public frmFIXAPISample()
        {
            InitializeComponent();
            _priceClient = new TcpClient(_host, _pricePort);           
            _priceStream = _priceClient.GetStream();            
            _tradeClient = new TcpClient(_host, _tradePort);
            _tradeStream = _priceClient.GetStream();
            _messageConstructor = new MessageConstructor(_host, _username,
                _password, _senderCompID, _senderSubID, _targetCompID);
        }

        private void ClearText()
        {
            txtMessageSend.Text = "";
            txtMessageReceived.Text = "";
        }

        private string SendPriceMessage(string message)
        {            
            return SendMessage(message, _priceStream);
        }

        private string SendTradeMessage(string message)
        {           
            return SendMessage(message, _tradeStream);
        }

        private string SendMessage(string message, NetworkStream stream)
        {
            var byteArray = Encoding.ASCII.GetBytes(message);
            stream.Write(byteArray, 0, byteArray.Length);
            var buffer = new byte[1024];
            int i = 0;
            while (!stream.DataAvailable && i < 10)
            {
                Thread.Sleep(100);
                i++;
            }
            if(stream.DataAvailable)
                stream.Read(buffer, 0, 1024);
            _messageSequenceNumber++;
            var returnMessage = Encoding.ASCII.GetString(buffer);
            return returnMessage;
        }
      
        private void btnLogon_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.LogonMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber, 30, false);
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendPriceMessage(message);
        }       

        private void btnTestRequest_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.TestRequestMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber,_testRequestID);
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendPriceMessage(message);
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.LogoutMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber);
            txtMessageSend.Text = message;         
            txtMessageReceived.Text = SendPriceMessage(message);
            _messageSequenceNumber = 1;
        }

        private void btnMarketDataRequest_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.MarketDataRequestMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber, "EURUSD:WDqsoT", 1,0,0,1,1);
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendPriceMessage(message);
        }

        private void btnHeartbeat_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.HeartbeatMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber);
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendPriceMessage(message);
        }

        private void btnResendRequest_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.ResendMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber,_messageSequenceNumber - 1);
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendPriceMessage(message);
        }

        private void btnReject_Click(object sender, EventArgs e)
        {
            ClearText();
             var message = _messageConstructor.RejectMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber,0);
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendPriceMessage(message);
        }

        private void btnSequenceReset_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.SequenceResetMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber,0);
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendPriceMessage(message);
        }

        private void btnNewOrderSingle_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.NewOrderSingleMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber,"1408471",1,1, DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss"), 1000,1, "3");
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }

        private void btnOrderStatusRequest_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.OrderStatusRequest(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber, "1408471");
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }

        private string Timestamp()
        {
            return (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString();
        }

        private void btnRequestForPositions_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.RequestForPositions(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber, "876316401");
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }

        private void btnLogonT_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.LogonMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber, 30, false);
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }

        private void btnHeartbeatT_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.HeartbeatMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber);
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }

        private void btnTestRequestT_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.TestRequestMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber, _testRequestID);
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }

        private void btnLogoutT_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.LogoutMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber);
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
            _messageSequenceNumber = 1;
        }

        private void btnResendRequestT_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.ResendMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber, _messageSequenceNumber - 1);
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }

        private void btnSpotMarketData_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.MarketDataRequestMessage(MessageConstructor.SessionQualifier.QUOTE, _messageSequenceNumber, "EURUSD:WDqsoT", 1, 1, 0, 1, 1);
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendPriceMessage(message);
        }

        private void btnStopOrder_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.NewOrderSingleMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber, "10", 1, 1, DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss"), 1000, 3, "3",0, (decimal)1.08);
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }

        private void btnLimitOrder_Click(object sender, EventArgs e)
        {
            ClearText();
            var message = _messageConstructor.NewOrderSingleMessage(MessageConstructor.SessionQualifier.TRADE, _messageSequenceNumber, "10", 1, 1, DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss"), 1000,2, "3", (decimal)1.08);
            _testRequestID++;
            txtMessageSend.Text = message;
            txtMessageReceived.Text = SendTradeMessage(message);
        }
    }
}

 


@mindbreaker

mindbreaker
08 Feb 2017, 17:11

FIX DLL
// Decompiled with JetBrains decompiler
// Type: FIX_API_Library.MessageConstructor
// Assembly: FIX API Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 34DF1E64-4374-4F03-8043-79A2A1904730
// Assembly location: C:\Users\ByczyPalowrson\Desktop\FIX-API-Sample-master\FIX API Library.dll

using System;
using System.Text;

namespace FIX_API_Library
{
  public class MessageConstructor
  {
    private string _host;
    private string _username;
    private string _password;
    private string _senderCompID;
    private string _senderSubID;
    private string _targetCompID;

    public MessageConstructor(string host, string username, string password, string senderCompID, string senderSubID, string targetCompID)
    {
      this._host = host;
      this._username = username;
      this._password = password;
      this._senderCompID = senderCompID;
      this._senderSubID = senderSubID;
      this._targetCompID = targetCompID;
    }

    public string LogonMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, int heartBeatSeconds, bool resetSeqNum)
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("98=0|");
      stringBuilder.Append("108=" + (object) heartBeatSeconds + "|");
      if (resetSeqNum)
        stringBuilder.Append("141=Y|");
      stringBuilder.Append("553=" + this._username + "|");
      stringBuilder.Append("554=" + this._password + "|");
      string str1 = this.ConstructHeader(qualifier, this.SessionMessageCode(MessageConstructor.SessionMessageType.Logon), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string HeartbeatMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber)
    {
      string message = this.ConstructHeader(qualifier, this.SessionMessageCode(MessageConstructor.SessionMessageType.Heartbeat), messageSequenceNumber, string.Empty);
      string str = this.ConstructTrailer(message);
      return (message + str).Replace("|", "\x0001");
    }

    public string TestRequestMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, int testRequestID)
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("112=" + (object) testRequestID + "|");
      string str1 = this.ConstructHeader(qualifier, this.SessionMessageCode(MessageConstructor.SessionMessageType.TestRequest), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string LogoutMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber)
    {
      string message = this.ConstructHeader(qualifier, this.SessionMessageCode(MessageConstructor.SessionMessageType.Logout), messageSequenceNumber, string.Empty);
      string str = this.ConstructTrailer(message);
      return (message + str).Replace("|", "\x0001");
    }

    public string ResendMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, int endSequenceNo)
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("16=" + (object) endSequenceNo + "|");
      string str1 = this.ConstructHeader(qualifier, this.SessionMessageCode(MessageConstructor.SessionMessageType.Resend), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string RejectMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, int rejectSequenceNumber)
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("45=" + (object) rejectSequenceNumber + "|");
      string str1 = this.ConstructHeader(qualifier, this.SessionMessageCode(MessageConstructor.SessionMessageType.Reject), messageSequenceNumber, string.Empty);
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string SequenceResetMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, int rejectSequenceNumber)
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("36=" + (object) rejectSequenceNumber + "|");
      string str1 = this.ConstructHeader(qualifier, this.SessionMessageCode(MessageConstructor.SessionMessageType.SequenceReset), messageSequenceNumber, string.Empty);
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string MarketDataRequestMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, string marketDataRequestID, int subscriptionRequestType, int marketDepth, int marketDataEntryType, int noRelatedSymbol, long symbol = 0)
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("262=" + marketDataRequestID + "|");
      stringBuilder.Append("263=" + (object) subscriptionRequestType + "|");
      stringBuilder.Append("264=" + (object) marketDepth + "|");
      stringBuilder.Append("265=1|");
      stringBuilder.Append("267=2|");
      stringBuilder.Append("269=0|269=1|");
      stringBuilder.Append("146=" + (object) noRelatedSymbol + "|");
      stringBuilder.Append("55=" + (object) symbol + "|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.MarketDataRequest), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string MarketDataSnapshotMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, long symbol, string noMarketDataEntries, int entryType, Decimal entryPrice, string marketDataRequestID = "")
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("262=" + marketDataRequestID + "|");
      stringBuilder.Append("55=" + (object) symbol + "|");
      stringBuilder.Append("268=" + noMarketDataEntries + "|");
      stringBuilder.Append("269=" + (object) entryType + "|");
      stringBuilder.Append("270=" + (object) entryPrice + "|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.MarketDataRequest), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string MarketDataIncrementalRefreshMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, string marketDataRequestID, int noMarketDataEntries, int marketDataUpdateAction, int marketDataEntryType, string marketDataEntryID, int noRelatedSymbol, Decimal marketDataEntryPrice = 0M, double marketDataEntrySize = 0.0, long symbol = 0)
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("262=" + marketDataRequestID + "|");
      stringBuilder.Append("268=" + (object) noMarketDataEntries + "|");
      stringBuilder.Append("279=" + (object) marketDataUpdateAction + "|");
      stringBuilder.Append("269=" + (object) marketDataEntryType + "|");
      stringBuilder.Append("278=" + marketDataEntryID + "|");
      stringBuilder.Append("55=" + (object) symbol + "|");
      if (marketDataEntryPrice > Decimal.Zero)
        stringBuilder.Append("270=" + (object) marketDataEntryPrice + "|");
      if (marketDataEntrySize > 0.0)
        stringBuilder.Append("271=" + (object) marketDataEntrySize + "|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.MarketDataIncrementalRefresh), messageSequenceNumber, string.Empty);
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string NewOrderSingleMessage(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, string orderID, long symbol, int side, string transactTime, int orderQuantity, int orderType, string timeInForce, Decimal price = 0M, Decimal stopPrice = 0M, string expireTime = "", string positionID = "")
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("11=" + orderID + "|");
      stringBuilder.Append("55=" + (object) symbol + "|");
      stringBuilder.Append("54=" + (object) side + "|");
      stringBuilder.Append("60=" + transactTime + "|");
      stringBuilder.Append("38=" + (object) orderQuantity + "|");
      stringBuilder.Append("40=" + (object) orderType + "|");
      if (price != Decimal.Zero)
        stringBuilder.Append("44=" + (object) price + "|");
      if (stopPrice != Decimal.Zero)
        stringBuilder.Append("99=" + (object) stopPrice + "|");
      stringBuilder.Append("59=" + timeInForce + "|");
      if (expireTime != string.Empty)
        stringBuilder.Append("126=" + expireTime + "|");
      if (positionID != string.Empty)
        stringBuilder.Append("721=" + positionID + "|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.NewOrderSingle), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string OrderStatusRequest(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, string orderID)
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("11=" + orderID + "|");
      stringBuilder.Append("54=1|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.OrderStatusRequest), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string ExecutionReport(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, string cTraderOrderID, string orderStatus, string transactTime, long symbol = 0, int side = 1, int averagePrice = 0, int orderQuantity = 0, int leavesQuantity = 0, int cumQuantity = 0, string orderID = "", string orderType = "", int price = 0, int stopPrice = 0, string timeInForce = "", string expireTime = "", string text = "", int orderRejectionReason = -1, string positionID = "")
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("37=" + cTraderOrderID + "|");
      stringBuilder.Append("11=" + orderID + "|");
      stringBuilder.Append("150=F|");
      stringBuilder.Append("39=" + orderStatus + "|");
      stringBuilder.Append("55=" + (object) symbol + "|");
      stringBuilder.Append("54=" + (object) side + "|");
      stringBuilder.Append("60=" + transactTime + "|");
      if (averagePrice > 0)
        stringBuilder.Append("6=" + (object) averagePrice + "|");
      if (orderQuantity > 0)
        stringBuilder.Append("38=" + (object) orderQuantity + "|");
      if (leavesQuantity > 0)
        stringBuilder.Append("151=" + (object) leavesQuantity + "|");
      if (cumQuantity > 0)
        stringBuilder.Append("14=" + (object) cumQuantity + "|");
      if (orderType != string.Empty)
        stringBuilder.Append("40=" + orderType + "|");
      if (price > 0)
        stringBuilder.Append("44=" + (object) price + "|");
      if (stopPrice > 0)
        stringBuilder.Append("99=" + (object) stopPrice + "|");
      if (timeInForce != string.Empty)
        stringBuilder.Append("59=" + timeInForce + "|");
      if (expireTime != string.Empty)
        stringBuilder.Append("126=" + expireTime + "|");
      if (text != string.Empty)
        stringBuilder.Append("58=" + text + "|");
      if (orderRejectionReason != -1)
        stringBuilder.Append("103=" + (object) orderRejectionReason + "|");
      if (positionID != string.Empty)
        stringBuilder.Append("721=" + positionID + "|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.OrderStatusRequest), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string BusinessMessageReject(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, int referenceSequenceNum = 0, string referenceMessageType = "", string businessRejectRefID = "", int businessRejectReason = -1, string text = "")
    {
      StringBuilder stringBuilder = new StringBuilder();
      if ((uint) referenceSequenceNum > 0U)
        stringBuilder.Append("45=" + (object) referenceSequenceNum + "|");
      if (referenceMessageType != string.Empty)
        stringBuilder.Append("372=" + referenceMessageType + "|");
      if (businessRejectRefID != string.Empty)
        stringBuilder.Append("379=" + businessRejectRefID + "|");
      if (businessRejectReason != -1)
        stringBuilder.Append("380=" + (object) businessRejectReason + "|");
      if (text != string.Empty)
        stringBuilder.Append("58=" + text + "|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.BusinessMessageReject), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string RequestForPositions(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, string requestID, string positionRequestID = "")
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("710=" + requestID + "|");
      if (positionRequestID != string.Empty)
        stringBuilder.Append("721=" + positionRequestID + "|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.RequestForPosition), messageSequenceNumber, stringBuilder.ToString());
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    public string PositionReport(MessageConstructor.SessionQualifier qualifier, int messageSequenceNumber, string requestID, string totalNumberOfPositionReports, string positionRequestResult, string positionID = "", string symbol = "", string noOfPositions = "", string longQuantity = "", string shortQuantity = "", string settlementPrice = "")
    {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.Append("710=" + requestID + "|");
      if (positionID != string.Empty)
        stringBuilder.Append("721=" + positionID + "|");
      stringBuilder.Append("727=" + totalNumberOfPositionReports + "|");
      stringBuilder.Append("728=" + positionRequestResult + "|");
      if (symbol != string.Empty)
        stringBuilder.Append("55=" + symbol + "|");
      if (noOfPositions != string.Empty)
        stringBuilder.Append("702=" + noOfPositions + "|");
      if (longQuantity != string.Empty)
        stringBuilder.Append("704=" + requestID + "|");
      if (shortQuantity != string.Empty)
        stringBuilder.Append("705=" + shortQuantity + "|");
      if (settlementPrice != string.Empty)
        stringBuilder.Append("730=" + settlementPrice + "|");
      string str1 = this.ConstructHeader(qualifier, this.ApplicationMessageCode(MessageConstructor.ApplicationMessageType.PositionReport), messageSequenceNumber, string.Empty);
      string str2 = this.ConstructTrailer(str1 + (object) stringBuilder);
      return (str1 + (object) stringBuilder + str2).Replace("|", "\x0001");
    }

    private string ConstructHeader(MessageConstructor.SessionQualifier qualifier, string type, int messageSequenceNumber, string bodyMessage)
    {
      StringBuilder stringBuilder1 = new StringBuilder();
      stringBuilder1.Append("8=FIX.4.4|");
      StringBuilder stringBuilder2 = new StringBuilder();
      stringBuilder2.Append("35=" + type + "|");
      stringBuilder2.Append("49=" + this._senderCompID + "|");
      stringBuilder2.Append("56=" + this._targetCompID + "|");
      stringBuilder2.Append("57=" + qualifier.ToString() + "|");
      stringBuilder2.Append("50=" + this._senderSubID + "|");
      stringBuilder2.Append("34=" + (object) messageSequenceNumber + "|");
      stringBuilder2.Append("52=" + DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss") + "|");
      int num = stringBuilder2.Length + bodyMessage.Length;
      stringBuilder1.Append("9=" + (object) num + "|");
      stringBuilder1.Append((object) stringBuilder2);
      return stringBuilder1.Replace("|", "\x0001").ToString();
    }

    private string ConstructTrailer(string message)
    {
      return ("10=" + (object) this.CalculateChecksum(message.Replace("|", "\x0001").ToString()) + "|").Replace("|", "\x0001");
    }

    private int CalculateChecksum(string dataToCalculate)
    {
      byte[] bytes = Encoding.ASCII.GetBytes(dataToCalculate);
      int num1 = 0;
      foreach (byte num2 in bytes)
        num1 += (int) num2;
      return num1 % 256;
    }

    private string SessionMessageCode(MessageConstructor.SessionMessageType type)
    {
      switch (type)
      {
        case MessageConstructor.SessionMessageType.Logon:
          return "A";
        case MessageConstructor.SessionMessageType.Logout:
          return "5";
        case MessageConstructor.SessionMessageType.Heartbeat:
          return "0";
        case MessageConstructor.SessionMessageType.TestRequest:
          return "1";
        case MessageConstructor.SessionMessageType.Resend:
          return "2";
        case MessageConstructor.SessionMessageType.Reject:
          return "3";
        case MessageConstructor.SessionMessageType.SequenceReset:
          return "4";
        default:
          return "0";
      }
    }

    private string ApplicationMessageCode(MessageConstructor.ApplicationMessageType type)
    {
      switch (type)
      {
        case MessageConstructor.ApplicationMessageType.MarketDataRequest:
          return "V";
        case MessageConstructor.ApplicationMessageType.MarketDataIncrementalRefresh:
          return "X";
        case MessageConstructor.ApplicationMessageType.NewOrderSingle:
          return "D";
        case MessageConstructor.ApplicationMessageType.OrderStatusRequest:
          return "H";
        case MessageConstructor.ApplicationMessageType.ExecutionReport:
          return "8";
        case MessageConstructor.ApplicationMessageType.BusinessMessageReject:
          return "j";
        case MessageConstructor.ApplicationMessageType.RequestForPosition:
          return "AN";
        case MessageConstructor.ApplicationMessageType.PositionReport:
          return "AP";
        default:
          return "0";
      }
    }

    public enum SessionMessageType
    {
      Logon,
      Logout,
      Heartbeat,
      TestRequest,
      Resend,
      Reject,
      SequenceReset,
    }

    public enum ApplicationMessageType
    {
      MarketDataRequest,
      MarketDataIncrementalRefresh,
      NewOrderSingle,
      OrderStatusRequest,
      ExecutionReport,
      BusinessMessageReject,
      RequestForPosition,
      PositionReport,
    }

    public enum SessionQualifier
    {
      QUOTE,
      TRADE,
    }
  }
}

 


@mindbreaker