#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0

    Developing a real-time automated trading system


    Hi,

    I want to make a real time automated trading system that makes trading decisions based on the real-time data-feed that I get from a 3rd party Websocket. Basically I'd like to make calculations on the order book data and possibly the time and sales data coming through and when the calculations turn out in a certain way I want to place, update or cancel an order.In what environment is it best to do this? The problem with PHP is that it is a one time request where the connections don't stay open to process real-time data; but the other problem is that when I want to make a trading decision (update, insert, cancel) I need to send a static HTTP request.

    Any ideas?

    Thanks, Dirk
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,401
    Rep Power
    594
    Use Ajax.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by gw1500se
    Use Ajax.
    Thanks, I will look into that.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,871
    Rep Power
    6351
    Not PHP or AJAX at all. If you want a real time trading platform it needs to be real time, and not rely on a round trip to some other server. Write it in C# or Java and keep it fully on your desktop.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    I need to fetch the data through the web from a 3rd party server (the exchange). If I run a server myself on the same machine as where the client runs it doesn't matter if I use PHP/AJAX or C#/Java, right? I don't see how C# or Java would make it more real-time?
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,871
    Rep Power
    6351
    It depends on how real-time you're talking about. A C# program with an open socket connection to this remote trading floor would be able to respond in one step: Get the information and put it on the screen.

    Using ajax/php, you'd have to have ajax ask apache to ask PHP to open a new socket, negotiate the connection, fetch the data, and return it to ajax for processing and display on the screen. You're involving 4 programs written in 4 languages when you could only be using 1.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by ManiacDan
    It depends on how real-time you're talking about. A C# program with an open socket connection to this remote trading floor would be able to respond in one step: Get the information and put it on the screen.

    Using ajax/php, you'd have to have ajax ask apache to ask PHP to open a new socket, negotiate the connection, fetch the data, and return it to ajax for processing and display on the screen. You're involving 4 programs written in 4 languages when you could only be using 1.
    Ok, I see what you mean.

    However, my own server is located in Europe, where the exchange is located in the US. Isn't the Ajax->Apache->PHP->Ajax operation negligible to the US->Europe transition time?
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,871
    Rep Power
    6351
    Probably, yeah.

    If you're doing international stock trading using an automated system of your own design...you may want to talk to a lawyer. Or a dozen lawyers.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    19
    Rep Power
    0
    Originally Posted by ManiacDan
    Probably, yeah.

    If you're doing international stock trading using an automated system of your own design...you may want to talk to a lawyer. Or a dozen lawyers.
    Why? It's for Bitcoin trading btw.
  18. #10
  19. Autodidact
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2008
    Location
    Canada
    Posts
    741
    Rep Power
    833
    If you want to code this to work inside a Web browser, then read about the Comet web application model. It'll explain the different techniques for achieving real-time data access in your application. For example, you can use a dedicated push engine (push server) like APE, or just write a basic long-polling script. There's a lot of solutions out there.
    Soldiers, from the height of these pyramids forty centuries look down upon you.
    ▪ Napoleon, on the eve of the Battle of the Pyramids
  20. #11
  21. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,871
    Rep Power
    6351
    Originally Posted by Dirk83
    Why? It's for Bitcoin trading btw.
    I was assuming you were trading something "real" which is therefore covered under various domestic and international laws. There are laws which govern how systems like yours would work for the stock market, bond market, monetary funds, currency trading, and futures markets. However, since you're doing bitcoins, which are too new to be considered relevant, you should be ok legally speaking (though again, I'm not a lawyer and you may want to talk to one).
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo