Beispiel #1
0
void Position::ClosePosition( OrderType::enumOrderType eOrderType ) {
  // should outstanding orders be auto cancelled?
  // position is closed with a market order, can try to do limit in the future, but need active market data
  if ( 0 != m_row.nPositionActive ) {
    switch ( m_row.eOrderSideActive ) {
      case OrderSide::Buy:
        PlaceOrder( eOrderType, OrderSide::Sell, m_row.nPositionActive );
        break;
      case OrderSide::Sell:
        PlaceOrder( eOrderType, OrderSide::Buy, m_row.nPositionActive );
        break;
      case OrderSide::Unknown:
        break;
    }
  }
}
Beispiel #2
0
Order::pOrder_t Position::PlaceOrder( // market
  OrderType::enumOrderType eOrderType,
  OrderSide::enumOrderSide eOrderSide,
  boost::uint32_t nOrderQuantity
) {
  pOrder_t pOrder = ConstructOrder( eOrderType, eOrderSide, nOrderQuantity );
  PlaceOrder( pOrder );
  return pOrder;
}
Beispiel #3
0
Order::pOrder_t Position::PlaceOrder( // limit or stop
  OrderType::enumOrderType eOrderType,
  OrderSide::enumOrderSide eOrderSide,
  boost::uint32_t nOrderQuantity,
  double dblPrice1
) {
  pOrder_t pOrder = ConstructOrder( eOrderType, eOrderSide, nOrderQuantity, dblPrice1 );
  PlaceOrder( pOrder );
  return pOrder;
}
Beispiel #4
0
static
void
MakeOrderResultPage(OpenSOAPStringHashPtr str) {
	static char FuncName[] = "MakeOrderResultPage";
    int error = OPENSOAP_NO_ERROR;
	
	char *endpoint;
	char *pubKey;
	char *privKey;
	char *spec = NULL;
	const char *manufacture = NULL;
	const char *name = NULL;
	const char *code = NULL;
	const char *price = NULL;
	
	error = OpenSOAPStringHashGetValueMB(str, "endpoint", (void**)&endpoint);
 	DecodeURLEncodedString(&endpoint);
	LOG_STRING(FuncName, "endpoint", endpoint ? endpoint : "(null)");
	
	error = OpenSOAPStringHashGetValueMB(str, "pubKey", (void**)&pubKey);
 	DecodeURLEncodedString(&pubKey);
	LOG_STRING(FuncName, "pubKey", pubKey ? pubKey : "(null)");
	
	error = OpenSOAPStringHashGetValueMB(str, "privKey", (void**)&privKey);
 	DecodeURLEncodedString(&privKey);
	LOG_STRING(FuncName, "privKey", privKey ? privKey : "(null)");
	
	error = OpenSOAPStringHashGetValueMB(str, "spec", (void**)&spec);
	if (OPENSOAP_SUCCEEDED(error)) {
		char *confirmation = NULL;
		char *qty;
		manufacture = strtok(spec, "_");
		name = strtok(NULL, "_");
		code = strtok(NULL, "_");
		price = strtok(NULL, "_");
		
		error = OpenSOAPStringHashGetValueMB(str, "qty", (void**)&qty);
		
		fprintf(stderr,
				"PlaceOrder: %s, %s\n",
				code ? code : "(null)",
				qty);
		
		error = PlaceOrder(endpoint,
						   NULL,
						   DEFAULT_CHARENC,
						   SERVICE_NS_URI,
						   pubKey,
						   privKey,
						   code,
						   atol(qty),
						   &confirmation);
		
		fprintf(stderr,
				"OrderResult: %s\n",
				confirmation ? confirmation : "(null)");
		
		if (confirmation) {
			SendHtmlText("./ShoppingHtml/CommonHdr.html");
			SendHtmlText("./ShoppingHtml/OrderResultHdr.html");
			
			printf("<tr>"
				   "<td>%s</td>"
				   "<td>%s</td>"
				   "<td>%s</td>"
				   "<td align=right>%s</td>"
				   "<td align=right>%s</td>"
				   "<td>%s</td>"
				   "</tr>\n",
				   manufacture,
				   name,
				   code,
				   price,
				   qty,
				   confirmation);
			
			SendHtmlText("./ShoppingHtml/OrderResultFtr.html");
			SendHtmlText("./ShoppingHtml/CommonFtr.html");
			
			free(confirmation);
		}
		else {
			/* error */
			SendHtmlText("./ShoppingHtml/CommonHdr.html");
			SendHtmlText("./ShoppingHtml/OrderResultErr.html");
			SendHtmlText("./ShoppingHtml/CommonFtr.html");
		}
	}
	else {
		/* error */
		SendHtmlText("./ShoppingHtml/CommonHdr.html");
		SendHtmlText("./ShoppingHtml/OrderResultErr.html");
		SendHtmlText("./ShoppingHtml/CommonFtr.html");
	}
}