mtgoxapi-0.5.0.2: Library to communicate with Mt.Gox

Safe HaskellNone

Network.MtGoxAPI

Description

This library offers a wrapper around the Mt.Gox API. It focuses, above all, on reliability, in that many actions - if they are idempotent - are automatically retried for some time in case of errors (using Control.Watchdog).

The library is able to maintain a copy of the current Mt.Gox order book by subscribing to real-time updates via the Mt.Gox websocket API. Based on this data the cost of hypothetical orders can then be calculated (e.g. simulateBTCBuy). For this feature to work, it is necessary to run an instance of the MtGoxCachingProxy ( https://github.com/javgh/MtGoxCachingProxy ) to which the library will connect (using port 10508 on localhost).

NOTE: The library is currently hardcoded to work on the BTC/EUR pair for Mt.Gox only. This was done in a very hackish way, which is why many of the function names still contain USD, because BTC/USD was the previously used pair. I apologize for this terrible source of confusion. I had planned to clean this up, but you know how priorities change around sometimes. Patches to fix this properly, at the cost of breaking changes, and to ideally make the currency pair configurable are welcome.

Example usage:

 import Network.MtGoxAPI

 import qualified Data.ByteString.Char8 as B8

 main :: IO ()
 main = do
     putStrLn "Please provide your API key: "
     authKey <- getLine
     putStrLn "Please provide your API secret: "
     authSecret <- getLine
     let credentials = initMtGoxCredentials (B8.pack authKey)
                                            (B8.pack authSecret)
         streamSettings = MtGoxStreamSettings DisableWalletNotifications
                                              SkipFullDepth
     apiHandles <- initMtGoxAPI Nothing credentials streamSettings
     getPrivateInfoR apiHandles >>= print

Example output:

 Please provide your API key:
 ...
 Please provide your API secret:
 ...
 Right (PrivateInfo {piBtcBalance = 1000000, piUsdBalance = 846450,
 piBtcOperations = 441, piUsdOperations = 6, piFee = 0.45})

Synopsis

Documentation

initMtGoxAPI :: Maybe WatchdogLogger -> MtGoxCredentials -> MtGoxStreamSettings -> IO MtGoxAPIHandlesSource

Rolls all the individual init functions into one. Namely initTickerMonitor, initDepthStore, initCurlWrapper, initWalletNotifier and finally initMtGoxStream. All handles are returned in one package and can then be used in combination with the various functions from the submodules which are re-exported here for convenience.

getTickerStatus :: TickerMonitorHandle -> IO TickerStatusSource

Access latest ticker status in a safe way. It will be checked, whether fresh data is available (never older than 300 seconds) and if not, re-try a few times before giving up. The function will not block for longer than about 20 seconds.

simulateBTCSell :: DepthStoreHandle -> Integer -> IO DepthStoreAnswerSource

Simulate how much USD can be earned by selling the specified amount of BTC. The function will return NotEnoughDepth in case there is not enough depth to cover the full amount. If no recent data is available, it will return DepthStoreUnavailable. In the latter case it will have retried a few times before giving up. The function will not block for longer than about 20 seconds.

simulateBTCBuy :: DepthStoreHandle -> Integer -> IO DepthStoreAnswerSource

Simulate how much USD will be needed to buy the specified amount of BTC. See simulateBTCSell for more details.

simulateUSDSell :: DepthStoreHandle -> Integer -> IO DepthStoreAnswerSource

Simulate how much BTC can be earned by selling the specified amount of USD. See simulateBTCSell for more details.

simulateUSDBuy :: DepthStoreHandle -> Integer -> IO DepthStoreAnswerSource

Simulate how much BTC will be needed to buy the specified amount of USD. See simulateBTCSell for more details.

waitForBTCDeposit :: WalletNotifierHandle -> IO ()Source

Will block until a BTC deposit happens. Note: This might sometimes be a little unreliable, when the streaming connection is under load from a lot of depth channel updates.

data OrderStats Source

Constructors

OrderStats 

Instances