Server for Pragyan's Dalal Street

CircleCI build status Go Report Card

Server for Dalal Street

Prerequisites

Check prerequisites

  • Check the go version installed.
go version
  • Check protobuf installation.
protoc --help
  • Setup SECRET_KEY environment variable to some string

Build instructions

  • Download the repository and cd into it.
go get github.com/delta/dalal-street-server
cd $GOPATH/src/github.com/delta/dalal-street-server
  • Install dependencies
cd ../
go get -v github.com/gemnasium/migrate
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
cd $GOPATH/src/github.com/golang/protobuf/protoc-gen-go/
git reset --hard ed6926b37a637426117ccab59282c3839528a700
go install github.com/golang/protobuf/protoc-gen-go
cd $GOPATH/src/github.com/delta/dalal-street-server/
go get
  • Setup submodules
git submodule init
git submodule update --recursive
  • Create databases and run migrations
mysql -u root -p -e "CREATE DATABASE dalalstreet_dev; CREATE DATABASE dalalstreet_test;"
migrate -url "mysql://root:YOUR_MYSQL_ROOT_PASSWORD@/dalalstreet_dev" -path ./migrations up
  • Generate proto files
./build_proto.sh
  • Run cp config.json.example config.json
  • Fill in the database credentials in the Dev section of config.json.
  • Run go run main.go

Create Migrations

migrate -url "mysql://root:YOUR_MYSQL_ROOT_PASSWORD@/dalalstreet_dev" -path ./migrations create migration_file_xyz

Tests

  • Run the test script locally before pushing commits.
./test.sh

Docker usage instructions

  • Install docker and docker-compose.
  • Run cp .env.example .env. Fill in the DB_NAME and DB_PASS in .env. These are the credentials for the database container.
  • Use the same credentials in Docker section config.json (DbName and DbPassword) and docker-entry.sh (in the migrate command).
  • Run docker-compose up.
  • Once the containers are up, you can get shell access by using
docker exec -it <CONTAINER_ID> bash

GoMock usage instructions

  • To generate mock for a file using mockgen, place this comment after import statement
 //go:generate mockgen -source {YOUR_FILE_NAME}.go -destination ../mocks/{YOUR_FILE_NAME}.go -package mocks
  • To generate mocks for all packages that has above comment
go generate ./...

  • To manually generate a mock package
mockgen -destination=mocks/{YOUR_FILE_NAME}.go -package=mocks {PATH_TO_YOUR_FILE}

Owner
Delta Force
The Official Programming Club of NIT Trichy
Delta Force
Comments
  • [orders]: Add 3 percent ordering fee on all orders placed

    [orders]: Add 3 percent ordering fee on all orders placed

    Currently people are placing orders mindlessly. To prevent random orders from being placed, a fee of 3 % is charged on whatever the order is worth (price x quantity).

    I'm not a 100% sure on the kind of effect this will have on the game but atleast for the demo, we can see how this works out. Can be removed if it doesn't add any positive effect.

  • [Orders] Add tax to earnings

    [Orders] Add tax to earnings

    For the game to adjust in terms of difficulty for relatively wealthy players, we could have tax instead of mortage interest over time. I feel this solves the issue better. We could have tax brackets based on net worth.

  • Add proto files for socketapi

    Add proto files for socketapi

    These are modified version of the files on DalalStreetv3 repo. I'm updating those too with this commit.

    Actions for getting data aren't available yet. But the structure is laid out in this commit.

  • [tax]: Add taxes to player's earnings

    [tax]: Add taxes to player's earnings

    This PR addresses #236 - check this issue for an explanation on the implementation.

    Issues that still exist :-

    • After a tax is charged, there is no indication on the frontend that a tax was charged.
    • The cash and stock value changes in the Nav Bar immediately after a trade happens but this doesn't reflect the tax that was charged. Only after refreshing the page does it update correctly.
  • Plot volume in stock history graphs

    Plot volume in stock history graphs

    Also change the styling of the line graph. It's honestly terrible.

    Volume already arrives with the stock history data, but doesn't get plotted. It'll be cool to show the volume on the charts as well to show which periods are most active, etc.

  • [Reserved-Assets]: Sending reserved-assets updates to frontend

    [Reserved-Assets]: Sending reserved-assets updates to frontend

    This is bad. The first thing to do for next year is to undo whatever this issue asks you to. Since we now reserve assets prior to execution of requests, all subsequent OrderFillTransactions received to the frontend will only contain partial information. OrderFillTransactions will no longer have details like how much stocks were sold for an AskOrder, how much cash was taken from reserved cash for a BidOrder.

    Solution

    1. Create a new type of Transaction. Call it ReserveUpdateTransaction
    2. These transactions WILL NOT be saved in the database. This is to maintain the sum(...) integrity.
    3. For an AskOrder being matched, the transaction will have how much stocks were matched.
    4. For an BidOrder being matched, the transaction will have how much cash was taken out of reserve.
    5. Send this transaction to the frontend.
  • [Remove]: frontend & bots submodule, improbable-eng/grpc-web

    [Remove]: frontend & bots submodule, improbable-eng/grpc-web

    • removed frontend & bots submodule
    • removed wrapped improbable-eng/grpc-web server (we'll use envoy here after for grpc-web client)
    • add serve mux for rest api
    • go fmt
    • removed docker files
    • news(market events) assets files will be downloaded in public directory and served statically (rest fashion)
    • add air conf for live reload (not hot reload)

    TODO

    • dockerize the server with envoy proxy

    IMP

    • dalal-street-web will not work without improbable-eng/grpc-web (can we use it in dev mode ?)
  • [hotfix]: Fixes integer wraparound in Market Depth datastream

    [hotfix]: Fixes integer wraparound in Market Depth datastream

    Alright so here's the deal.

    I guess we still don't know why we faced an integer wraparound error last year, and I haven't investigated it yet, so until we have the time and patience to read through the entire codebase to figure out the root cause, I'd prefer it if we just merged this hack that we used last year.

    k thnx.

    This PR closes #248
  • Market Orders Logic

    Market Orders Logic

    Right now Market Orders can be heavily exploited. Either clear pending Market or add a Market Order fee for getting (if margin of profit is large enough, then this doesn't help). Or something else?

  • Stock history recording and retrieval needs to be fixed

    Stock history recording and retrieval needs to be fixed

    Problem

    We do not have a proper mechanism to handle stock history. We returned entire history of the stock last year, but that's a terrible thing to do.

    How other sites solve it

    Most stock sites provide you to specify the ranges of the stock history (1day, 5day, 1month, 3month, 6month, 1yr, 2yr, 5yr, Max - these are standard ranges, some offer lesser, some more). We'll follow the same. However, our game will be of only 10-14 days (mostly 10) and will run for 5-6 hours a day, so people won't be using most of the ranges except for looking at how the company did in the past. So maybe we should change our ranges to something more relevant (like have more short term ranges starting from 1 hour). We'll still need long-term ranges for completeness and for giving the gameplay some story factor.

    Also, for each range the granularity/interval (we'll call it interval from now on) will be pre-decided. For example, in 1day range, stock prices of every minute will be shown. In 5day range, stock prices of every 5min interval will be shown, etc.

    To get a feel of these, checkout any site - yahoo finance is pretty good, or http://gdax.com/trade/ETH-USD

    Candlesticks business

    Also, we'll be showing price candlesticks on the frontend. These require 4 things - Open, High, Low, Close prices for each interval. Open is the price at the start of the interval, High is the highest price during the interval, Low is the Lowest price during the interval. Close is the price at the close of the interval (this will coincide with the Open price of the next interval). Look up stock candlesticks if you're still confused.

    And, I'd like the trade volume to be stored as well. But that'll be part of another PR.


    Parts of the problem

    1. First part of this feature would be to figure out what ranges & corresponding intervals we want to support.

    2. Second part would be to figure out how we'd be querying the data.

    3. Third part will be the actual coding. It'll affect models and proto and gRPC API.

  • [stockprice]: New stock price is now determined by weighted average

    [stockprice]: New stock price is now determined by weighted average

    THIS IS A MAJOR PR. Read it carefully and TEST IT TEST IT before merging.

    Like seriously, clone it to your local and do whatever you can to try and break it. Only then should we merge it.

    Old stock price logic :-

    1. stock.CurrentPrice = price at which last transaction was executed The problem - This could cause the stock to fluctuate wildly as we saw last year in Dalal

    2. stock.avgLastPrice = average price at which last 20 transactions were executed. The problem - This doesn't take into account the number of stocks that were traded in each transaction i.e A transaction with 1000 stocks would carry the same weight as a transaction with 1 stock.

    What this PR changes the stock price logic to :-

    1. stock.CurrentPrice is now the weighted average of the price at which the last x stocks were traded where

    x = min(1% of total number of stocks in circulation, 20)

    The reason for the upper limit of 20 is that as x increases, the amount of stock price fluctuation reduces, and if we allow x to increase unchecked, then the stock price will never change.

    This solves both of the above problems

    1. stock.avgLastPrice has been renamed to stock.lastTradePrice since the currentPrice now stores the average price anyways. The table column names and proto files have been updated accordingly.

    Commit notes

    • This PR resyncs with proto
    • This PR closes #214
  • [Matching engine]: refactor server matching engine

    [Matching engine]: refactor server matching engine

    We faced some weird issues like market sell orders not getting matched for some time even though there was a matching buy order for that. On looking upon the matching engine code, we found out that there is some issues regarding the implementation of that. Try to refactor that

  • [Admin Panel]: Add feature for adding/modifying/deleting stocks and also clearing a particular stock's exchange stocks

    [Admin Panel]: Add feature for adding/modifying/deleting stocks and also clearing a particular stock's exchange stocks

    This might be useful during testing and in prod also if you find that people are manipulating the market then we can clear it from the admin panel itself

  • [Cheat]: New method for finding users who cheat

    [Cheat]: New method for finding users who cheat

    We tried to find people who played in groups using Strongly Connected Components by taking transactions between users as the edge but during event , we saw that it wasnt effective in finding groups as even a small number of random transactions were making them come into the SCC. Try to come up with new idea for that

  • [Transactions]: Add constraint for preventing short selling after some extent

    [Transactions]: Add constraint for preventing short selling after some extent

    This year , we tried to add a constraint where we check in each transaction if the user has enough cash to retrieve the stocks after short selling, but in the main event as the no of transactions were high, we faced some sql lock timed out issues during first day. Have to think about better way of doing this and also we need to write stress tests to check with lot of concurrent transactions.

A Language Server Protocol (LSP) server for Jsonnet

Jsonnet Language Server Warning: This project is in active development and is likely very buggy. A Language Server Protocol (LSP) server for Jsonnet.

Nov 22, 2022
The server-pubsub is the main backend of DATAVOC project that manages all the other web-server modules of the same project such as the processor

server-pubsub The server-pubsub is the main backend of DATAVOC project that manages all the other web-server modules of the same project such as the p

Dec 3, 2021
server-to-server sync application, written in go/golang.

svcpy: server to server copy a basic server-to-server copy application. on a single binary, it can be a server or a client. example usage: on the serv

Nov 4, 2021
Server and client implementation of the grpc go libraries to perform unary, client streaming, server streaming and full duplex RPCs from gRPC go introduction

Description This is an implementation of a gRPC client and server that provides route guidance from gRPC Basics: Go tutorial. It demonstrates how to u

Nov 24, 2021
Pape-server - A small server written in golang to serve a random wallpaper.

pape-server I like to inject custom CSS themes into a lot of websites and electron apps, however browsers don't let websites access local disk through

Dec 31, 2021
Cert bound sts server - Certificate Bound Tokens using Security Token Exchange Server (STS)
Cert bound sts server - Certificate Bound Tokens using Security Token Exchange Server (STS)

Certificate Bound Tokens using Security Token Exchange Server (STS) Sample demonstration of Certificate Bound Tokens acquired from a Security Token Ex

Jan 2, 2022
Echo-server - An HTTP echo server designed for testing applications and proxies

echo-server An HTTP echo server designed for testing applications and proxies. R

Dec 20, 2022
Broadcast-server - A simple Go server that broadcasts any data/stream

broadcast A simple Go server that broadcasts any data/stream usage data You can

Oct 21, 2022
Videos2gether-server - Server for the Realtime video streaming app Videos2Gether

Videos Together server Server source code for the https://videos2gether.com Arch

Jan 9, 2022
JPRQ Customizer is a customizer that helps to use the JPRQ server code and make it compatible with your own server with custom subdomain and domain
JPRQ Customizer is a customizer that helps to use the JPRQ server code and make it compatible with your own server with custom subdomain and domain

JPRQ Customizer is a customizer that helps to use the JPRQ server code and make it compatible with your own server with custom subdomain and domain.You can upload the generated directory to your web server and expose user localhost to public internet. You can use this to make your local machine a command center for your ethical hacking purpose ;)

Jan 19, 2022
Envoy-eds-server - Envoy EDS server is a working Envoy Discovery Service implementation

envoy-eds-server Intro Envoy EDS server is a working Envoy Discovery Service imp

Apr 2, 2022
Http-server - A HTTP server and can be accessed via TLS and non-TLS mode

Application server.go runs a HTTP/HTTPS server on the port 9090. It gives you 4

Feb 3, 2022
Server - Dupman server written in Go

server dupman server written in Go Requirements Go (>=1.17) Installation Usage C

Feb 22, 2022
“Dear Port80” is a zero-config TCP proxy server that hides SSH connection behind a HTTP server!

Dear Port80 About The Project: “Dear Port80” is a zero-config TCP proxy server that hides SSH connection behind a HTTP server! +---------------------

Jun 29, 2022
CoAP Client/Server implementing RFC 7252 for the Go Language

Canopus Canopus is a client/server implementation of the Constrained Application Protocol (CoAP) Updates 25.11.2016 I've added basic dTLS Support base

Nov 18, 2022
Package dhcp6 implements a DHCPv6 server, as described in RFC 3315. MIT Licensed.

dhcp6 Package dhcp6 implements a DHCPv6 server, as described in IETF RFC 3315. MIT Licensed. At this time, the API is not stable, and may change over

Sep 27, 2022
An experimental go FTP server framework

graval Go FTP server framework. By providing a simple driver class that responds to a handful of methods you can have a complete FTP server. Some samp

Sep 27, 2022
The interactive web server
The interactive web server

The interactive web server. HTTPLabs let you inspect HTTP requests and forge responses. Install Golang go get github.com/gchaincl/httplab go install g

Dec 24, 2022
go websocket, a better way to buid your IM server
go websocket, a better way to buid your IM server

Your star is my power!! ?? ⭐ ⭐ ⭐ ⭐ ⭐ Discribe lhttp is a http like protocol using websocket to provide long live, build your IM service quickly scalab

Dec 30, 2022