forked from opentradeengine/opentradeengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.php
49 lines (34 loc) · 1.51 KB
/
examples.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Open Trade Engine usage examples.
*
* Open Trade Engine
*/
include('engine/engine.php');
include('register.php');
//add traders to database, usually after receiving a post request from a registration form
/*
$register = new Register();
$register->insertMember("buyer", "John", "Smith","2010-11-11", "999-999-9999",
"Question", "Answer", "555", "[email protected]", "password", 3);
$register->insertMember("seller", "Joe", "Smithie", "12-12-1992", "999-888-9999",
"Question", "Answer", "444", "[email protected]", "password", 3);
*/
//TO DO: create new currencies and symbol using them
//TO DO: add balances to traders, usually after a deposit is made manually or through an API
//create an order, usually done after receiving a post request from user's browser
//types are a work in progress
$buyOrder = new Order($price = 0.05, $quantity = 1000, $type = 1, $side = 'Buy', $traderID = 4, $symbolID = 1);
$sellOrder = new Order(0.05, 1000, 1, 'Sell', 5, $symbolID = 1);
$engine = new Engine($symbolID = 1);
$engine->addOrder($buyOrder); //executes or adds order depending on orders already in it
$order = $engine->getOrderByID($ID);
$engine->cancelOrder($order);
$engine->addOrder($sellOrder);
//use trader object to retrieve trader information
$buyer = new Trader();
$buyer->setupTrader(4);
$seller = new Trader();
$seller->setupTrader(5);
echo "Buyer ID: ".$buyer->getID()." Buyer Balance: ".$buyer->getBalance("USD");
echo "Seller ID: ".$seller->getID()." Seller Balance: ".$seller->getBalance("USD");