Creating a tranding script for 2 virtual currencies

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
dannyboyonline
Forum Newbie
Posts: 6
Joined: Mon Jun 15, 2009 10:03 am

Creating a tranding script for 2 virtual currencies

Post by dannyboyonline »

Hello everyone,

Can someone please help me out with a problem I'm having when designing this live trading script.

Firstly I'll try to explain what I need to accomplish.

Each user can have 2 different virtual currencies in his/her account, I would like to create an script where users could post a buy/sell order into the system at their desired rate, after the system accepts the order it will clear any orders that match. For e.g. if there is an order to BUY 100*(Currency A) at 1*(Currency B) and another order of SELL 500*(Currency B) at 1*(Currency A). The BUY order would "Clear" and the SELL order will not have a 400 volume remaining instead of the 500.

Design problems

I would like to have 2 interfaces:-

1. where the user would enter the volume and exchange rate manually and wait for the trade to clear. This should not be too much of an issue as I could easily post the order to a database and then call a function to check for any matching trades and clears them. This shouldn't be too much of an issue.

2. An interface where the user just enters the volume he wishes to buy, this will prompt the user with the total cost of the buy order (Just by checking the lowest sell order orders), and then confirm the order, this will post the order and clear the funds.

The only problem I can see here is that if the price changes between the prompt (with the total cost) there is a possibility that the order would not clear, and this will destroy the whole concept of this second interface where the user just wants to get a "quick" trade.


I would appreciate any suggestions for this problem and/or remarks about the overall design of the system.

I hope I was clear on what I intend to do, but if I wasn't feel free to ask any questions.

Thanks again.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Creating a tranding script for 2 virtual currencies

Post by josh »

http://www.amazon.com/Test-Driven-Devel ... 0321146530
Shows how to build a currency conversion "framework" using test first development (which should be used on any project in my opinion).

There is also Zend_Currency

I can tell you have never used a real world trading system. My financial institution (and almost every one in existence) has the concept of "rules" the trader can set. For instance the trader can put in an order to buy 5 shares of xyz with a "stop" or "limit". More advanced systems get into really sophisticated trading rules. I have heard that most trades these days are executed by algorithms, not by people directly.

http://answers.yahoo.com/question/index ... 007AAeUDEO
http://en.wikipedia.org/wiki/Algorithmic_trading
Last edited by josh on Sun Dec 27, 2009 4:15 pm, edited 1 time in total.
dannyboyonline
Forum Newbie
Posts: 6
Joined: Mon Jun 15, 2009 10:03 am

Re: Creating a tranding script for 2 virtual currencies

Post by dannyboyonline »

Hi josh thanks :)

Could you please post the full amazon URL?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Creating a tranding script for 2 virtual currencies

Post by josh »

Thought I did. Edited post. The forums seem messed up.

# Publisher: Addison-Wesley Professional (November 18, 2002)
# Language: English
# ISBN-10: 0321146530
# ISBN-13: 978-0321146533
dannyboyonline
Forum Newbie
Posts: 6
Joined: Mon Jun 15, 2009 10:03 am

Re: Creating a tranding script for 2 virtual currencies

Post by dannyboyonline »

Thanks mate.

Anyone else have any "simpler" solutions, as it's merely a simple exchange from one ecurrency "Credit" to another. I do not wish to spend that much time in design and development, I just need something that does the job and that's it.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Creating a tranding script for 2 virtual currencies

Post by josh »

Doing testing is simpler than not, because it eliminates the need to debug. Numerous studies have shown it has no, or little impact on effort spent. (but large savings on time)

I don't get what you are asking though, you taking a currency and multiplying it by it's exchange rate. Are you looking for someone to write it for you? When you do TDD the code practically writes itself because you write an "example" of how you are going to use the code, then it becomes obvious how it should be implemented to meet your exact needs, but I digress.

You dont have to do real TDD either, think of it as "EDD" (Example driven development)

1) write an example of how you would use this component or function. Think of what you will name it, what arguments you would like it to take, etc..
2) create the empty function definition
3) write code until your example makes sense

TDD or test driven development just means you "run" your examples to see that they do or do not work. Writing the example of how it is to be used first is key. It helps your brain focus on something "that just does its job and works" like you wanted.

Another spin-off is "documentation first". First pretend you already wrote this component (in reality you havent started). Pretend you are writing a tutorial on how to use this component for others to use. When you are finished you will have an exact specification of what needs to be coded. I always prefer an "example" written in code though.
dannyboyonline
Forum Newbie
Posts: 6
Joined: Mon Jun 15, 2009 10:03 am

Re: Creating a tranding script for 2 virtual currencies

Post by dannyboyonline »

I don't think you guys are getting my problem, I do not need someone to do it for me I've been working as a professional developer for a couple of years now, but the real issue is this.


In interface 2. The user will just input the VOLUME like he wants to buy $10,000 no matter how much €s it costs!, the system will then calculate based on the other selling offers on the market and their volumes and give him a price for e.g.

User says he wants to buy 10,000$

The system will popup saying that will cost €20,000

But by the time the user clicks ok, someone else could have bought these, and the price might have changed... that's the real issue here.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Creating a tranding script for 2 virtual currencies

Post by josh »

Just answered another thread about this then. Trading systems need the concept of a purchase order or a stop limit. The customer should choose the rules for which the purchase order should be satisfied (if price is above X then stop- stop limit, or if price drops below X than buy)
Post Reply